• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- xray-fc-account.cpp: XRay Function Call Accounting Tool ------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Implementation of the helper tools dealing with XRay-generated function ids.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "func-id-helper.h"
15 #include "llvm/Support/Path.h"
16 #include <sstream>
17 
18 using namespace llvm;
19 using namespace xray;
20 
SymbolOrNumber(int32_t FuncId) const21 std::string FuncIdConversionHelper::SymbolOrNumber(int32_t FuncId) const {
22   auto CacheIt = CachedNames.find(FuncId);
23   if (CacheIt != CachedNames.end())
24     return CacheIt->second;
25 
26   std::ostringstream F;
27   auto It = FunctionAddresses.find(FuncId);
28   if (It == FunctionAddresses.end()) {
29     F << "#" << FuncId;
30     return F.str();
31   }
32 
33   if (auto ResOrErr = Symbolizer.symbolizeCode(BinaryInstrMap, It->second)) {
34     auto &DI = *ResOrErr;
35     if (DI.FunctionName == "<invalid>")
36       F << "@(" << std::hex << It->second << ")";
37     else
38       F << DI.FunctionName;
39   } else
40     handleAllErrors(ResOrErr.takeError(), [&](const ErrorInfoBase &) {
41       F << "@(" << std::hex << It->second << ")";
42     });
43 
44   auto S = F.str();
45   CachedNames[FuncId] = S;
46   return S;
47 }
48 
FileLineAndColumn(int32_t FuncId) const49 std::string FuncIdConversionHelper::FileLineAndColumn(int32_t FuncId) const {
50   auto It = FunctionAddresses.find(FuncId);
51   if (It == FunctionAddresses.end())
52     return "(unknown)";
53 
54   std::ostringstream F;
55   auto ResOrErr = Symbolizer.symbolizeCode(BinaryInstrMap, It->second);
56   if (!ResOrErr) {
57     consumeError(ResOrErr.takeError());
58     return "(unknown)";
59   }
60 
61   auto &DI = *ResOrErr;
62   F << sys::path::filename(DI.FileName).str() << ":" << DI.Line << ":"
63     << DI.Column;
64 
65   return F.str();
66 }
67