When the environment variable LIBCLANG_RESOURCE_USAGE is set, teach

libclang to emit information about resource usage after parsing, code
completion, etc.

llvm-svn: 130946
This commit is contained in:
Douglas Gregor 2011-05-05 20:27:22 +00:00
parent cb59baaa20
commit af44c781a7
3 changed files with 24 additions and 5 deletions

View File

@ -2560,8 +2560,10 @@ CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx,
fprintf(stderr, "}\n"); fprintf(stderr, "}\n");
return 0; return 0;
} else if (getenv("LIBCLANG_RESOURCE_USAGE")) {
PrintLibclangResourceUsage(PTUI.result);
} }
return PTUI.result; return PTUI.result;
} }
@ -2574,7 +2576,10 @@ int clang_saveTranslationUnit(CXTranslationUnit TU, const char *FileName,
if (!TU) if (!TU)
return 1; 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) { void clang_disposeTranslationUnit(CXTranslationUnit CTUnit) {
@ -2650,8 +2655,8 @@ int clang_reparseTranslationUnit(CXTranslationUnit TU,
fprintf(stderr, "libclang: crash detected during reparsing\n"); fprintf(stderr, "libclang: crash detected during reparsing\n");
static_cast<ASTUnit *>(TU->TUData)->setUnsafeToFree(true); static_cast<ASTUnit *>(TU->TUData)->setUnsafeToFree(true);
return 1; return 1;
} } else if (getenv("LIBCLANG_RESOURCE_USAGE"))
PrintLibclangResourceUsage(TU);
return RTUI.result; return RTUI.result;
} }
@ -5349,6 +5354,16 @@ void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage) {
} // end extern "C" } // 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. // Misc. utility functions.
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -498,7 +498,8 @@ CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
fprintf(stderr, "libclang: crash detected in code completion\n"); fprintf(stderr, "libclang: crash detected in code completion\n");
static_cast<ASTUnit *>(TU->TUData)->setUnsafeToFree(true); static_cast<ASTUnit *>(TU->TUData)->setUnsafeToFree(true);
return 0; return 0;
} } else if (getenv("LIBCLANG_RESOURCE_USAGE"))
PrintLibclangResourceUsage(TU);
return CCAI.result; return CCAI.result;
} }

View File

@ -77,6 +77,9 @@ namespace clang {
/// \return False if a crash was detected. /// \return False if a crash was detected.
bool RunSafely(llvm::CrashRecoveryContext &CRC, bool RunSafely(llvm::CrashRecoveryContext &CRC,
void (*Fn)(void*), void *UserData, unsigned Size = 0); void (*Fn)(void*), void *UserData, unsigned Size = 0);
/// \brief Print libclang's resource usage to standard error.
void PrintLibclangResourceUsage(CXTranslationUnit TU);
} }
#endif #endif