aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang-c/Index.h3
-rw-r--r--tools/c-index-test/c-index-test.c15
-rw-r--r--tools/libclang/CIndex.cpp12
3 files changed, 21 insertions, 9 deletions
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h
index 11e060b27a..728db90600 100644
--- a/include/clang-c/Index.h
+++ b/include/clang-c/Index.h
@@ -1020,8 +1020,9 @@ enum CXTUMemoryUsageKind {
CXTUMemoryUsage_AST = 1,
CXTUMemoryUsage_Identifiers = 2,
CXTUMemoryUsage_Selectors = 3,
+ CXTUMemoryUsage_GlobalCompletionResults = 4,
CXTUMemoryUsage_First = CXTUMemoryUsage_AST,
- CXTUMemoryUsage_Last = CXTUMemoryUsage_Selectors
+ CXTUMemoryUsage_Last = CXTUMemoryUsage_GlobalCompletionResults
};
/**
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c
index b7025fc396..a1065a832f 100644
--- a/tools/c-index-test/c-index-test.c
+++ b/tools/c-index-test/c-index-test.c
@@ -371,19 +371,18 @@ void PrintDiagnostics(CXTranslationUnit TU) {
}
void PrintMemoryUsage(CXTranslationUnit TU) {
- CXTUMemoryUsage usage = clang_getCXTUMemoryUsage(TU);
unsigned long total = 0.0;
- unsigned i, n;
-
+ unsigned i = 0;
+ CXTUMemoryUsage usage = clang_getCXTUMemoryUsage(TU);
fprintf(stderr, "Memory usage:\n");
- for (i = 0, n = usage.numEntries; i != n; ++i) {
+ for (i = 0 ; i != usage.numEntries; ++i) {
const char *name = clang_getTUMemoryUsageName(usage.entries[i].kind);
unsigned long amount = usage.entries[i].amount;
total += amount;
- fprintf(stderr, " %s : %ld bytes (%lf MBytes)\n", name, amount,
+ fprintf(stderr, " %s : %ld bytes (%f MBytes)\n", name, amount,
((double) amount)/(1024*1024));
}
- fprintf(stderr, " TOTAL = %ld bytes (%lf MBytes)\n", total,
+ fprintf(stderr, " TOTAL = %ld bytes (%f MBytes)\n", total,
((double) total)/(1024*1024));
clang_disposeCXTUMemoryUsage(usage);
}
@@ -1548,9 +1547,9 @@ static void print_usage(void) {
"<symbol filter> {<args>}*\n"
" c-index-test -test-annotate-tokens=<range> {<args>}*\n"
" c-index-test -test-inclusion-stack-source {<args>}*\n"
- " c-index-test -test-inclusion-stack-tu <AST file>\n"
- " c-index-test -test-print-linkage-source {<args>}*\n");
+ " c-index-test -test-inclusion-stack-tu <AST file>\n");
fprintf(stderr,
+ " c-index-test -test-print-linkage-source {<args>}*\n"
" c-index-test -test-print-typekind {<args>}*\n"
" c-index-test -print-usr [<CursorKind> {<args>}]*\n"
" c-index-test -print-usr-file <file>\n"
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index 2ac57bf208..0d0f08f4e1 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -5202,6 +5202,8 @@ const char *clang_getTUMemoryUsageName(CXTUMemoryUsageKind kind) {
break;
case CXTUMemoryUsage_Selectors:
str = "ASTContext: selectors";
+ case CXTUMemoryUsage_GlobalCompletionResults:
+ str = "Code completion: cached global results";
}
return str;
}
@@ -5228,6 +5230,16 @@ CXTUMemoryUsage clang_getCXTUMemoryUsage(CXTranslationUnit TU) {
createCXTUMemoryUsageEntry(*entries, CXTUMemoryUsage_Selectors,
(unsigned long) astContext.Selectors.getTotalMemory());
+ // How much memory is used for caching global code completion results?
+ unsigned long completionBytes = 0;
+ if (GlobalCodeCompletionAllocator *completionAllocator =
+ astUnit->getCachedCompletionAllocator().getPtr()) {
+ completionBytes = completionAllocator-> getTotalMemory();
+ }
+ createCXTUMemoryUsageEntry(*entries, CXTUMemoryUsage_GlobalCompletionResults,
+ completionBytes);
+
+
CXTUMemoryUsage usage = { (void*) entries.get(),
(unsigned) entries->size(),
entries->size() ? &(*entries)[0] : 0 };