Skip to content

Commit 729e0e2

Browse files
committed
[libSyntax] Add logging for how long syntax tree serialization took
1 parent 85f1c5e commit 729e0e2

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "llvm/ADT/StringRef.h"
3838
#include "llvm/ADT/STLExtras.h"
3939
#include "llvm/Support/MemoryBuffer.h"
40+
#include "llvm/Support/NativeFormatting.h"
4041
#include "llvm/Support/Path.h"
4142
#include "llvm/Support/PrettyStackTrace.h"
4243
#include "llvm/Support/raw_ostream.h"
@@ -2423,6 +2424,7 @@ void serializeSyntaxTreeAsJson(
24232424
const swift::syntax::SourceFileSyntax &SyntaxTree,
24242425
std::unordered_set<unsigned> ReusedNodeIds,
24252426
ResponseBuilder::Dictionary &Dict) {
2427+
auto StartClock = clock();
24262428
// 4096 is a heuristic buffer size that appears to usually be able to fit an
24272429
// incremental syntax tree
24282430
size_t ReserveBufferSize = 4096;
@@ -2438,6 +2440,15 @@ void serializeSyntaxTreeAsJson(
24382440
SyntaxTreeOutput << *SyntaxTree.getRaw();
24392441
}
24402442
Dict.set(KeySerializedSyntaxTree, SyntaxTreeString);
2443+
2444+
auto EndClock = clock();
2445+
LOG_SECTION("incrParse Performance", InfoLowPrio) {
2446+
Log->getOS() << "Serialized " << SyntaxTreeString.size() << " bytes in ";
2447+
llvm::write_double(Log->getOS(),
2448+
(double)(EndClock - StartClock) * 1000 / CLOCKS_PER_SEC,
2449+
llvm::FloatStyle::Fixed, 2);
2450+
Log->getOS() << "ms";
2451+
}
24412452
}
24422453

24432454
void SKEditorConsumer::handleSyntaxTree(

0 commit comments

Comments
 (0)