[cfe-commits] r130946 - in /cfe/trunk/tools/libclang: CIndex.cpp CIndexCodeCompletion.cpp CIndexer.h
Douglas Gregor
dgregor at apple.com
Thu May 5 13:27:22 PDT 2011
Author: dgregor
Date: Thu May 5 15:27:22 2011
New Revision: 130946
URL: http://llvm.org/viewvc/llvm-project?rev=130946&view=rev
Log:
When the environment variable LIBCLANG_RESOURCE_USAGE is set, teach
libclang to emit information about resource usage after parsing, code
completion, etc.
Modified:
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp
cfe/trunk/tools/libclang/CIndexer.h
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=130946&r1=130945&r2=130946&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Thu May 5 15:27:22 2011
@@ -2560,8 +2560,10 @@
fprintf(stderr, "}\n");
return 0;
+ } else if (getenv("LIBCLANG_RESOURCE_USAGE")) {
+ PrintLibclangResourceUsage(PTUI.result);
}
-
+
return PTUI.result;
}
@@ -2574,7 +2576,10 @@
if (!TU)
return 1;
- return static_cast<ASTUnit *>(TU->TUData)->Save(FileName);
+ int result = static_cast<ASTUnit *>(TU->TUData)->Save(FileName);
+ if (getenv("LIBCLANG_RESOURCE_USAGE"))
+ PrintLibclangResourceUsage(TU);
+ return result;
}
void clang_disposeTranslationUnit(CXTranslationUnit CTUnit) {
@@ -2650,8 +2655,8 @@
fprintf(stderr, "libclang: crash detected during reparsing\n");
static_cast<ASTUnit *>(TU->TUData)->setUnsafeToFree(true);
return 1;
- }
-
+ } else if (getenv("LIBCLANG_RESOURCE_USAGE"))
+ PrintLibclangResourceUsage(TU);
return RTUI.result;
}
@@ -5349,6 +5354,16 @@
} // end extern "C"
+void clang::PrintLibclangResourceUsage(CXTranslationUnit TU) {
+ CXTUResourceUsage Usage = clang_getCXTUResourceUsage(TU);
+ for (unsigned I = 0; I != Usage.numEntries; ++I)
+ fprintf(stderr, " %s: %lu\n",
+ clang_getTUResourceUsageName(Usage.entries[I].kind),
+ Usage.entries[I].amount);
+
+ clang_disposeCXTUResourceUsage(Usage);
+}
+
//===----------------------------------------------------------------------===//
// Misc. utility functions.
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp?rev=130946&r1=130945&r2=130946&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp Thu May 5 15:27:22 2011
@@ -498,7 +498,8 @@
fprintf(stderr, "libclang: crash detected in code completion\n");
static_cast<ASTUnit *>(TU->TUData)->setUnsafeToFree(true);
return 0;
- }
+ } else if (getenv("LIBCLANG_RESOURCE_USAGE"))
+ PrintLibclangResourceUsage(TU);
return CCAI.result;
}
Modified: cfe/trunk/tools/libclang/CIndexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexer.h?rev=130946&r1=130945&r2=130946&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexer.h (original)
+++ cfe/trunk/tools/libclang/CIndexer.h Thu May 5 15:27:22 2011
@@ -77,6 +77,9 @@
/// \return False if a crash was detected.
bool RunSafely(llvm::CrashRecoveryContext &CRC,
void (*Fn)(void*), void *UserData, unsigned Size = 0);
+
+ /// \brief Print libclang's resource usage to standard error.
+ void PrintLibclangResourceUsage(CXTranslationUnit TU);
}
#endif
More information about the cfe-commits
mailing list