[sourcekitd] Add a request to get statistics from the service

... and add a few basic statistics about the number of requests, ASTs
built, etc.  The Statistic type is loosely based on the one from LLVM,
but suitable for using without DEBUG macros and using SourceKit UIdents
to identify the statistic.  The easiest way to add a new statistic is to
add it to SwiftStatistics.def in the SwiftLangSupport.
This commit is contained in:
Ben Langmuir
2017-10-04 14:28:42 -07:00
parent d558168a42
commit 9c7d9235de
14 changed files with 250 additions and 10 deletions

View File

@@ -2073,6 +2073,8 @@ void SwiftLangSupport::editorOpen(StringRef Name, llvm::MemoryBuffer *Buf,
LOG_WARN_FUNC("Document already exists in editorOpen(..): " << Name);
Snapshot = nullptr;
}
auto numOpen = ++Stats.numOpenDocs;
Stats.maxOpenDocs.updateMax(numOpen);
}
if (!Snapshot) {
@@ -2095,8 +2097,12 @@ void SwiftLangSupport::editorOpen(StringRef Name, llvm::MemoryBuffer *Buf,
void SwiftLangSupport::editorClose(StringRef Name, bool RemoveCache) {
auto Removed = EditorDocuments.remove(Name);
if (!Removed)
if (Removed) {
--Stats.numOpenDocs;
} else {
IFaceGenContexts.remove(Name);
}
if (Removed && RemoveCache)
Removed->removeCachedAST();
// FIXME: Report error if Name did not apply to anything ?