Dean Michael Berris | f4f861b | 2018-05-02 00:43:17 +0000 | [diff] [blame] | 1 | //===- xray-fc-account.cpp: XRay Function Call Accounting Tool ------------===// |
Dean Michael Berris | 6e1f066 | 2017-01-10 02:38:11 +0000 | [diff] [blame] | 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 | |
| 21 | std::string FuncIdConversionHelper::SymbolOrNumber(int32_t FuncId) const { |
Martin Pelikan | 26e6f68 | 2018-03-01 01:59:24 +0000 | [diff] [blame] | 22 | auto CacheIt = CachedNames.find(FuncId); |
| 23 | if (CacheIt != CachedNames.end()) |
| 24 | return CacheIt->second; |
| 25 | |
Dean Michael Berris | 6e1f066 | 2017-01-10 02:38:11 +0000 | [diff] [blame] | 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 | |
Martin Pelikan | 26e6f68 | 2018-03-01 01:59:24 +0000 | [diff] [blame] | 44 | auto S = F.str(); |
| 45 | CachedNames[FuncId] = S; |
| 46 | return S; |
Dean Michael Berris | 6e1f066 | 2017-01-10 02:38:11 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | 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 | } |