[cfe-commits] r129733 - in /cfe/trunk: include/clang-c/Index.h tools/c-index-test/c-index-test.c tools/libclang/CIndex.cpp

Ted Kremenek kremenek at apple.com
Mon Apr 18 16:42:53 PDT 2011


Author: kremenek
Date: Mon Apr 18 18:42:53 2011
New Revision: 129733

URL: http://llvm.org/viewvc/llvm-project?rev=129733&view=rev
Log:
Report memory usage for global code completion results in CXTUMemoryUsage.

Modified:
    cfe/trunk/include/clang-c/Index.h
    cfe/trunk/tools/c-index-test/c-index-test.c
    cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=129733&r1=129732&r2=129733&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Mon Apr 18 18:42:53 2011
@@ -1020,8 +1020,9 @@
   CXTUMemoryUsage_AST = 1,
   CXTUMemoryUsage_Identifiers = 2,
   CXTUMemoryUsage_Selectors = 3,
+  CXTUMemoryUsage_GlobalCompletionResults = 4,
   CXTUMemoryUsage_First = CXTUMemoryUsage_AST,
-  CXTUMemoryUsage_Last = CXTUMemoryUsage_Selectors
+  CXTUMemoryUsage_Last = CXTUMemoryUsage_GlobalCompletionResults
 };
 
 /**

Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=129733&r1=129732&r2=129733&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Mon Apr 18 18:42:53 2011
@@ -371,19 +371,18 @@
 }
 
 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 @@
           "<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"

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=129733&r1=129732&r2=129733&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Mon Apr 18 18:42:53 2011
@@ -5202,6 +5202,8 @@
       break;
     case CXTUMemoryUsage_Selectors:
       str = "ASTContext: selectors";
+    case CXTUMemoryUsage_GlobalCompletionResults:
+      str = "Code completion: cached global results";
   }
   return str;
 }
@@ -5228,6 +5230,16 @@
   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 };





More information about the cfe-commits mailing list