Skip to content

Commit e8b5bca

Browse files
committed
[SourceKit] Report number of instructions executed since SourceKit was started in statistics request
This can be used to measure how many instructions a request executes by retrieving the number of instructions executed since the process’s start before and after executing the request.
1 parent 7ce0e87 commit e8b5bca

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

test/SourceKit/Misc/stats.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ func foo() {}
22

33
// RUN: %sourcekitd-test -req=syntax-map %s == -req=stats | %FileCheck %s -check-prefix=SYNTAX_1
44

5+
// SYNTAX_1: {{.*}} source.statistic.instruction-count
56
// SYNTAX_1: 2 {{.*}} source.statistic.num-requests
67
// SYNTAX_1: 0 {{.*}} source.statistic.num-semantic-requests
78
// SYNTAX_1: 0 {{.*}} source.statistic.num-ast-builds

tools/SourceKit/tools/sourcekitd/lib/API/Requests.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include "swift/Basic/ExponentialGrowthAppendingBinaryByteStream.h"
3131
#include "swift/Basic/Mangler.h"
32+
#include "swift/Basic/Statistic.h"
3233
#include "swift/Basic/Version.h"
3334
#include "swift/Demangling/Demangler.h"
3435
#include "swift/Demangling/ManglingMacros.h"
@@ -918,6 +919,11 @@ void handleRequestImpl(sourcekitd_object_t ReqObj, ResponseReceiver Rec) {
918919
dict.set(KeyValue, stat->value);
919920
};
920921

922+
Statistic instructionCount(
923+
UIdentFromSKDUID(KindStatInstructionCount),
924+
"# of instructions executed since the SourceKit process was started");
925+
instructionCount.value.store(swift::getInstructionsExecuted());
926+
addStat(&instructionCount);
921927
addStat(&numRequests);
922928
addStat(&numSemaRequests);
923929
std::for_each(stats.begin(), stats.end(), addStat);

utils/gyb_sourcekit_support/UIDs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def __init__(self, internal_name, external_name):
176176
KEY('ExpressionLength', 'key.expression_length'),
177177
KEY('ExpressionType', 'key.expression_type'),
178178
KEY('CanonicalizeType', 'key.canonicalize_type'),
179-
KEY('InternalDiagnostic', "key.internal_diagnostic"),
179+
KEY('InternalDiagnostic', 'key.internal_diagnostic'),
180180
KEY('VFSName', 'key.vfs.name'),
181181
KEY('VFSOptions', 'key.vfs.options'),
182182
KEY('Files', 'key.files'),
@@ -453,6 +453,7 @@ def __init__(self, internal_name, external_name):
453453
KIND('Unknown', 'source.syntacticrename.unknown'),
454454
KIND('StatNumRequests', 'source.statistic.num-requests'),
455455
KIND('StatNumSemaRequests', 'source.statistic.num-semantic-requests'),
456+
KIND('StatInstructionCount', 'source.statistic.instruction-count'),
456457
KIND('SyntaxTreeOff', 'source.syntaxtree.transfer.off'),
457458
KIND('SyntaxTreeFull', 'source.syntaxtree.transfer.full'),
458459
KIND('Swift', 'source.lang.swift'),

0 commit comments

Comments
 (0)