[llvm] r326407 - [XRay] cache symbolized function names for a repeatedly queried function ID

Martin Pelikan via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 28 17:59:25 PST 2018


Author: pelikan
Date: Wed Feb 28 17:59:24 2018
New Revision: 326407

URL: http://llvm.org/viewvc/llvm-project?rev=326407&view=rev
Log:
[XRay] cache symbolized function names for a repeatedly queried function ID

Summary:
Processing 2 GB XRay traces with "llvm-xray convert -symbolize" needs to
go over each trace record and symbolize the function name refered to by
its ID.  Currently this happens by asking the LLVM symbolizer code every
single time.  A simple cache can save around 30 minutes of processing of
that trace.

llvm-xray's resident memory usage increased negligibly with this cache.

Reviewers: dberris

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D43896

Modified:
    llvm/trunk/tools/llvm-xray/func-id-helper.cc
    llvm/trunk/tools/llvm-xray/func-id-helper.h

Modified: llvm/trunk/tools/llvm-xray/func-id-helper.cc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-xray/func-id-helper.cc?rev=326407&r1=326406&r2=326407&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-xray/func-id-helper.cc (original)
+++ llvm/trunk/tools/llvm-xray/func-id-helper.cc Wed Feb 28 17:59:24 2018
@@ -19,6 +19,10 @@ using namespace llvm;
 using namespace xray;
 
 std::string FuncIdConversionHelper::SymbolOrNumber(int32_t FuncId) const {
+  auto CacheIt = CachedNames.find(FuncId);
+  if (CacheIt != CachedNames.end())
+    return CacheIt->second;
+
   std::ostringstream F;
   auto It = FunctionAddresses.find(FuncId);
   if (It == FunctionAddresses.end()) {
@@ -37,7 +41,9 @@ std::string FuncIdConversionHelper::Symb
       F << "@(" << std::hex << It->second << ")";
     });
 
-  return F.str();
+  auto S = F.str();
+  CachedNames[FuncId] = S;
+  return S;
 }
 
 std::string FuncIdConversionHelper::FileLineAndColumn(int32_t FuncId) const {

Modified: llvm/trunk/tools/llvm-xray/func-id-helper.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-xray/func-id-helper.h?rev=326407&r1=326406&r2=326407&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-xray/func-id-helper.h (original)
+++ llvm/trunk/tools/llvm-xray/func-id-helper.h Wed Feb 28 17:59:24 2018
@@ -13,6 +13,7 @@
 #ifndef LLVM_TOOLS_LLVM_XRAY_FUNC_ID_HELPER_H
 #define LLVM_TOOLS_LLVM_XRAY_FUNC_ID_HELPER_H
 
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/DebugInfo/Symbolize/Symbolize.h"
 #include <unordered_map>
 
@@ -28,6 +29,7 @@ private:
   std::string BinaryInstrMap;
   symbolize::LLVMSymbolizer &Symbolizer;
   const FunctionAddressMap &FunctionAddresses;
+  mutable llvm::DenseMap<int32_t, std::string> CachedNames;
 
 public:
   FuncIdConversionHelper(std::string BinaryInstrMap,




More information about the llvm-commits mailing list