1 //===- xray-fc-account.cpp: XRay Function Call Accounting Tool ------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Implementation of the helper tools dealing with XRay-generated function ids.
11 //===----------------------------------------------------------------------===//
13 #include "func-id-helper.h"
14 #include "llvm/Support/Path.h"
20 std::string
FuncIdConversionHelper::SymbolOrNumber(int32_t FuncId
) const {
21 auto CacheIt
= CachedNames
.find(FuncId
);
22 if (CacheIt
!= CachedNames
.end())
23 return CacheIt
->second
;
26 auto It
= FunctionAddresses
.find(FuncId
);
27 if (It
== FunctionAddresses
.end()) {
32 if (auto ResOrErr
= Symbolizer
.symbolizeCode(BinaryInstrMap
, It
->second
)) {
34 if (DI
.FunctionName
== "<invalid>")
35 F
<< "@(" << std::hex
<< It
->second
<< ")";
39 handleAllErrors(ResOrErr
.takeError(), [&](const ErrorInfoBase
&) {
40 F
<< "@(" << std::hex
<< It
->second
<< ")";
44 CachedNames
[FuncId
] = S
;
48 std::string
FuncIdConversionHelper::FileLineAndColumn(int32_t FuncId
) const {
49 auto It
= FunctionAddresses
.find(FuncId
);
50 if (It
== FunctionAddresses
.end())
54 auto ResOrErr
= Symbolizer
.symbolizeCode(BinaryInstrMap
, It
->second
);
56 consumeError(ResOrErr
.takeError());
61 F
<< sys::path::filename(DI
.FileName
).str() << ":" << DI
.Line
<< ":"