Index: lib/CrossTU/CrossTranslationUnit.cpp =================================================================== --- lib/CrossTU/CrossTranslationUnit.cpp +++ lib/CrossTU/CrossTranslationUnit.cpp @@ -21,6 +21,7 @@ #include "clang/Frontend/TextDiagnosticPrinter.h" #include "clang/Index/USRGeneration.h" #include "llvm/ADT/Triple.h" +#include "llvm/ADT/Statistic.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Path.h" @@ -32,6 +33,15 @@ namespace cross_tu { namespace { +#define DEBUG_TYPE "CrossTranslationUnit" +STATISTIC(NumGetCTUCalled, "The # of getCTUDefinition function called"); +STATISTIC( + NumNotInOtherTU, + "The # of getCTUDefinition called but the function is not in any other TU"); +STATISTIC(NumGetCTUSuccess, + "The # of getCTUDefinition successfully returned the " + "requested function's body"); + // FIXME: This class is will be removed after the transition to llvm::Error. class IndexErrorCategory : public std::error_category { public: @@ -151,14 +161,16 @@ StringRef CrossTUDir, StringRef IndexName) { assert(!FD->hasBody() && "FD has a definition in current translation unit!"); + ++NumGetCTUCalled; const std::string LookupFnName = getLookupName(FD); if (LookupFnName.empty()) return llvm::make_error( index_error_code::failed_to_generate_usr); llvm::Expected ASTUnitOrError = loadExternalAST(LookupFnName, CrossTUDir, IndexName); - if (!ASTUnitOrError) + if (!ASTUnitOrError) { return ASTUnitOrError.takeError(); + } ASTUnit *Unit = *ASTUnitOrError; if (!Unit) return llvm::make_error( @@ -216,8 +228,10 @@ } auto It = FunctionFileMap.find(LookupName); - if (It == FunctionFileMap.end()) + if (It == FunctionFileMap.end()) { + ++NumNotInOtherTU; return llvm::make_error(index_error_code::missing_definition); + } StringRef ASTFileName = It->second; auto ASTCacheEntry = FileASTUnitMap.find(ASTFileName); if (ASTCacheEntry == FileASTUnitMap.end()) { @@ -250,6 +264,7 @@ cast(Importer.Import(const_cast(FD))); assert(ToDecl->hasBody()); assert(FD->hasBody() && "Functions already imported should have body."); + ++NumGetCTUSuccess; return ToDecl; }