-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[XRay] Draft: Runtime symbol resolution #132416
Draft
sebastiankreutzer
wants to merge
5
commits into
llvm:main
Choose a base branch
from
sebastiankreutzer:xray_func_res
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You can test this locally with the following command:git-clang-format --diff 733be4ed7dcf976719f424c0cb81b77a14f91f5a 82bb16ee5094cd7759bcf579eaf56f3b32a19f88 --extensions h,cpp -- compiler-rt/test/xray/TestCases/Posix/symbolize-dso.cpp compiler-rt/include/xray/xray_interface.h compiler-rt/include/xray/xray_records.h compiler-rt/lib/xray/xray_basic_logging.cpp compiler-rt/lib/xray/xray_interface.cpp compiler-rt/lib/xray/xray_interface_internal.h compiler-rt/lib/xray/xray_utils.cpp compiler-rt/lib/xray/xray_utils.h compiler-rt/test/xray/TestCases/Posix/basic-mode-dso.cpp llvm/include/llvm/XRay/Trace.h llvm/include/llvm/XRay/XRayRecord.h llvm/lib/XRay/Trace.cpp llvm/tools/llvm-xray/func-id-helper.cpp llvm/tools/llvm-xray/func-id-helper.h llvm/tools/llvm-xray/xray-account.cpp llvm/tools/llvm-xray/xray-account.h View the diff from clang-format here.diff --git a/compiler-rt/include/xray/xray_interface.h b/compiler-rt/include/xray/xray_interface.h
index e3ac316102..39bcd7dc8d 100644
--- a/compiler-rt/include/xray/xray_interface.h
+++ b/compiler-rt/include/xray/xray_interface.h
@@ -23,18 +23,18 @@ extern "C" {
struct FunctionMapEntry {
int32_t FunctionId;
uint64_t Addr;
- FunctionMapEntry* Next;
+ FunctionMapEntry *Next;
};
struct XRaySymbolInfo {
int32_t FuncId;
- const char* Name;
- const char* Module;
- const char* File;
+ const char *Name;
+ const char *Module;
+ const char *File;
int64_t Line;
};
-extern int __xray_symbolize(int32_t, XRaySymbolInfo*);
+extern int __xray_symbolize(int32_t, XRaySymbolInfo *);
/// Synchronize this with AsmPrinter::SledKind in LLVM.
enum XRayEntryType {
diff --git a/compiler-rt/include/xray/xray_records.h b/compiler-rt/include/xray/xray_records.h
index 5c87f21296..293a794094 100644
--- a/compiler-rt/include/xray/xray_records.h
+++ b/compiler-rt/include/xray/xray_records.h
@@ -88,9 +88,9 @@ struct alignas(32) XRayFunctionMD {
struct alignas(32) XRayFileMD {
uint16_t RecordType = RecordTypes::FILE_MD;
int16_t FilenameLen = 0;
- // The padding bytes may not be enough to store the full name. In this case, 32 byte blocks
- // containing the rest of the name are expected to follow this record
- // as needed.
+ // The padding bytes may not be enough to store the full name. In this case,
+ // 32 byte blocks containing the rest of the name are expected to follow this
+ // record as needed.
char FilenameBuffer[28] = {};
} __attribute__((packed));
diff --git a/compiler-rt/lib/xray/xray_basic_logging.cpp b/compiler-rt/lib/xray/xray_basic_logging.cpp
index 1847372fbf..4500505525 100644
--- a/compiler-rt/lib/xray/xray_basic_logging.cpp
+++ b/compiler-rt/lib/xray/xray_basic_logging.cpp
@@ -26,18 +26,18 @@
#include <unistd.h>
#include "sanitizer_common/sanitizer_allocator_internal.h"
-#include "sanitizer_common/sanitizer_libc.h"
#include "sanitizer_common/sanitizer_dense_map.h"
-#include "sanitizer_common/sanitizer_symbolizer.h"
#include "sanitizer_common/sanitizer_hash.h"
-#include "xray/xray_records.h"
+#include "sanitizer_common/sanitizer_libc.h"
+#include "sanitizer_common/sanitizer_symbolizer.h"
#include "xray/xray_allocator.h"
-#include "xray_recursion_guard.h"
+#include "xray/xray_records.h"
#include "xray_basic_flags.h"
#include "xray_basic_logging.h"
#include "xray_defs.h"
#include "xray_flags.h"
#include "xray_interface_internal.h"
+#include "xray_recursion_guard.h"
#include "xray_tsc.h"
#include "xray_utils.h"
@@ -62,7 +62,6 @@ struct StringKey {
const char *Key{nullptr};
mutable char EmptyOrTombstone{__sanitizer::DenseMapInfo<char>::getEmptyKey()};
-
};
} // namespace
@@ -70,7 +69,9 @@ namespace __sanitizer {
// Provide DenseMapInfo for chars.
template <> struct DenseMapInfo<StringKey> {
static constexpr StringKey getEmptyKey() { return StringKey::Empty(); }
- static constexpr StringKey getTombstoneKey() { return StringKey::Tombstone(); }
+ static constexpr StringKey getTombstoneKey() {
+ return StringKey::Tombstone();
+ }
static unsigned getHashValue(const StringKey &Val) {
if (!Val.Key) {
return 0;
@@ -87,7 +88,7 @@ template <> struct DenseMapInfo<StringKey> {
if (!LHS.Key || !RHS.Key) {
return !LHS.Key && !RHS.Key;
}
- return __sanitizer::internal_strcmp(LHS.Key, RHS.Key) == 0;
+ return __sanitizer::internal_strcmp(LHS.Key, RHS.Key) == 0;
}
};
} // namespace __sanitizer
@@ -140,11 +141,10 @@ static atomic_uint64_t ThresholdTicks{0};
static atomic_uint64_t TicksPerSec{0};
static atomic_uint64_t CycleFrequency{NanosecondsPerSecond};
-
struct FunctionRecordBuffer {
// First entry is buffer idx, second states if this entry has been flushed.
- using FuncMapEntry = bool;//detail::DenseMapPair<int32_t, bool>;
+ using FuncMapEntry = bool; // detail::DenseMapPair<int32_t, bool>;
// DenseMap<int32_t, DataInfo> SymInfo;
@@ -153,7 +153,7 @@ struct FunctionRecordBuffer {
using MappedAddressInfo = std::pair<int, AddressInfo>;
- MappedAddressInfo * AddrInfoBuf{nullptr};
+ MappedAddressInfo *AddrInfoBuf{nullptr};
unsigned Size{0};
DenseMap<StringKey, int32_t> FileMDMap;
@@ -163,36 +163,36 @@ struct FunctionRecordBuffer {
static constexpr unsigned BufferSize = 1024;
- LogWriter* Writer;
+ LogWriter *Writer;
- FunctionRecordBuffer(LogWriter* LW) XRAY_NEVER_INSTRUMENT : Writer(LW) {
+ FunctionRecordBuffer(LogWriter *LW) XRAY_NEVER_INSTRUMENT : Writer(LW) {
AddrInfoBuf = allocateBuffer<MappedAddressInfo>(BufferSize);
}
- ~FunctionRecordBuffer() XRAY_NEVER_INSTRUMENT {
+ ~FunctionRecordBuffer() XRAY_NEVER_INSTRUMENT {
Flush();
deallocateBuffer<MappedAddressInfo>(AddrInfoBuf, BufferSize);
}
- static FunctionRecordBuffer& Create(LogWriter* LW) XRAY_NEVER_INSTRUMENT {
+ static FunctionRecordBuffer &Create(LogWriter *LW) XRAY_NEVER_INSTRUMENT {
auto *FRB = allocate<FunctionRecordBuffer>();
new (FRB) FunctionRecordBuffer(LW);
return *FRB;
}
- void Destroy() XRAY_NEVER_INSTRUMENT {
+ void Destroy() XRAY_NEVER_INSTRUMENT {
this->~FunctionRecordBuffer();
deallocate(this);
}
void StoreFunctionRecord(int32_t FuncId) XRAY_NEVER_INSTRUMENT {
- auto& Symbolized = FuncMapping[FuncId];
+ auto &Symbolized = FuncMapping[FuncId];
if (!Symbolized) {
if (Size >= BufferSize) {
Flush();
}
- auto&MAI = AddrInfoBuf[Size];
+ auto &MAI = AddrInfoBuf[Size];
if (!Symbolize(FuncId, &MAI.second)) {
Report("Unable to symbolize function %d\n", FuncId);
return;
@@ -201,17 +201,15 @@ struct FunctionRecordBuffer {
Symbolized = true;
Size++;
}
-
-
}
- void Flush() XRAY_NEVER_INSTRUMENT {
+ void Flush() XRAY_NEVER_INSTRUMENT {
if (Verbosity())
Report("Flushing function record buffer\n");
for (unsigned I = 0; I < Size; I++) {
- auto& MDI = AddrInfoBuf[I];
+ auto &MDI = AddrInfoBuf[I];
auto Id = MDI.first;
- AddressInfo& AI = MDI.second;
+ AddressInfo &AI = MDI.second;
int FileMDIdx = 0;
if (AI.file) {
@@ -245,33 +243,36 @@ struct FunctionRecordBuffer {
reinterpret_cast<char *>(&FIR.NameBuffer));
Writer->WriteAll(AI.function, AI.function + FIR.NameLen);
constexpr int NameBufferSize = sizeof(FIR.NameBuffer);
- auto NumPaddingBytes = FIR.NameLen < NameBufferSize ? NameBufferSize - FIR.NameLen : 32 - (FIR.NameLen - NameBufferSize) % 32;
+ auto NumPaddingBytes = FIR.NameLen < NameBufferSize
+ ? NameBufferSize - FIR.NameLen
+ : 32 - (FIR.NameLen - NameBufferSize) % 32;
Writer->WritePadding(NumPaddingBytes);
-// auto ObjId = UnpackId(Id).first;
-// auto& ObjWritten = ObjWrittenMap[ObjId];
-// if (!ObjWritten) {
-// XRayObjectInfoRecord OIR;
-// OIR.ObjId = ObjId;
-// const char* Filename = AI.module;
-// OIR.FilenameLen = static_cast<int16_t>(internal_strlen(Filename));
-// Writer->WriteAll(reinterpret_cast<char *>(&OIR),
-// reinterpret_cast<char *>(&OIR.FilenameBuffer));
-// Writer->WriteAll(Filename, Filename + OIR.FilenameLen);
-// NumPaddingBytes = OIR.FilenameLen < 24 ? 24 - OIR.FilenameLen : 32 - (OIR.FilenameLen - 24) % 32;
-// Writer->WritePadding(NumPaddingBytes);
-// ObjWritten = true;
-// }
+ // auto ObjId = UnpackId(Id).first;
+ // auto& ObjWritten = ObjWrittenMap[ObjId];
+ // if (!ObjWritten) {
+ // XRayObjectInfoRecord OIR;
+ // OIR.ObjId = ObjId;
+ // const char* Filename = AI.module;
+ // OIR.FilenameLen =
+ // static_cast<int16_t>(internal_strlen(Filename));
+ // Writer->WriteAll(reinterpret_cast<char *>(&OIR),
+ // reinterpret_cast<char *>(&OIR.FilenameBuffer));
+ // Writer->WriteAll(Filename, Filename + OIR.FilenameLen);
+ // NumPaddingBytes = OIR.FilenameLen < 24 ? 24 - OIR.FilenameLen :
+ // 32 - (OIR.FilenameLen - 24) % 32;
+ // Writer->WritePadding(NumPaddingBytes);
+ // ObjWritten = true;
+ // }
}
Size = 0;
}
};
-
struct GlobalLoggingData {
- LogWriter* Writer;
- FunctionRecordBuffer* RecordBuffer;
+ LogWriter *Writer;
+ FunctionRecordBuffer *RecordBuffer;
};
static LogWriter *getLog() XRAY_NEVER_INSTRUMENT {
@@ -305,8 +306,8 @@ static LogWriter *getLog() XRAY_NEVER_INSTRUMENT {
}
static GlobalLoggingData createLoggingData() XRAY_NEVER_INSTRUMENT {
- auto* LW = getLog();
- auto* FRB = &FunctionRecordBuffer::Create(LW);
+ auto *LW = getLog();
+ auto *FRB = &FunctionRecordBuffer::Create(LW);
return {LW, FRB};
}
@@ -350,7 +351,6 @@ static ThreadLocalData &getThreadLocalData() XRAY_NEVER_INSTRUMENT {
return TLD;
}
-
template <class RDTSC>
void InMemoryRawLog(int32_t FuncId, XRayEntryType Type,
RDTSC ReadTSC) XRAY_NEVER_INSTRUMENT {
diff --git a/compiler-rt/lib/xray/xray_interface.cpp b/compiler-rt/lib/xray/xray_interface.cpp
index 554fccd2b7..6469a3ddc3 100644
--- a/compiler-rt/lib/xray/xray_interface.cpp
+++ b/compiler-rt/lib/xray/xray_interface.cpp
@@ -34,7 +34,6 @@
// TODO: For function map
#include "sanitizer_common/sanitizer_symbolizer.h"
-
#include "xray_defs.h"
#include "xray_flags.h"
@@ -508,7 +507,7 @@ XRayPatchingStatus mprotectAndPatchFunction(int32_t FuncId, int32_t ObjId,
} // namespace
-bool Symbolize(int32_t PackedId, AddressInfo* AI) {
+bool Symbolize(int32_t PackedId, AddressInfo *AI) {
auto Ids = UnpackId(PackedId);
auto ObjId = Ids.first;
auto FuncId = Ids.second;
@@ -526,17 +525,19 @@ bool Symbolize(int32_t PackedId, AddressInfo* AI) {
const XRaySledEntry *Sled =
InstrMap.SledsIndex ? InstrMap.SledsIndex[FuncId - 1].fromPCRelative()
- : findFunctionSleds(FuncId, InstrMap).Begin;
+ : findFunctionSleds(FuncId, InstrMap).Begin;
auto Addr = Sled->function();
- Symbolizer* Sym = Symbolizer::GetOrInit();
-// Sym->RefreshModules(); // FIXME: Is this needed?
- auto* SymStack = Sym->SymbolizePC(Addr);
+ Symbolizer *Sym = Symbolizer::GetOrInit();
+ // Sym->RefreshModules(); // FIXME: Is this needed?
+ auto *SymStack = Sym->SymbolizePC(Addr);
if (!SymStack) {
return false;
}
-// printf("Symbol Info: function %s from module %s in %s:%d\n", SymStack->info.function, SymStack->info.module, SymStack->info.file, SymStack->info.line);
+ // printf("Symbol Info: function %s from module %s in %s:%d\n",
+ // SymStack->info.function, SymStack->info.module, SymStack->info.file,
+ // SymStack->info.line);
// XRay does not support inlined function instrumentation.
// Therefore, we only look at the first function stack entry.
@@ -545,7 +546,6 @@ bool Symbolize(int32_t PackedId, AddressInfo* AI) {
return true;
}
-
} // namespace __xray
using namespace __xray;
@@ -607,7 +607,7 @@ uint16_t __xray_register_event_type(
return h->type_id;
}
-int __xray_symbolize(int32_t PackedId, XRaySymbolInfo* SymInfo) {
+int __xray_symbolize(int32_t PackedId, XRaySymbolInfo *SymInfo) {
if (!SymInfo) {
return 0; // TODO Error msg?
}
@@ -624,7 +624,8 @@ int __xray_symbolize(int32_t PackedId, XRaySymbolInfo* SymInfo) {
SymInfo->File = ai.file;
SymInfo->Line = ai.line;
- // TODO: AddressInfo owns its memory, so passing char pointers is okay for now.
+ // TODO: AddressInfo owns its memory, so passing char pointers is okay for
+ // now.
// Need to free at some point.
return true;
diff --git a/compiler-rt/lib/xray/xray_interface_internal.h b/compiler-rt/lib/xray/xray_interface_internal.h
index ca1618a8fc..0df3b3ef42 100644
--- a/compiler-rt/lib/xray/xray_interface_internal.h
+++ b/compiler-rt/lib/xray/xray_interface_internal.h
@@ -21,7 +21,6 @@
#include <cstdint>
#include <utility>
-
extern "C" {
// The following functions have to be defined in assembler, on a per-platform
// basis. See xray_trampoline_*.S files for implementations.
@@ -137,7 +136,7 @@ struct XRaySledMap {
bool Loaded;
};
-bool Symbolize(int32_t FuncId, AddressInfo* DI);
+bool Symbolize(int32_t FuncId, AddressInfo *DI);
bool patchFunctionEntry(bool Enable, uint32_t FuncId, const XRaySledEntry &Sled,
const XRayTrampolines &Trampolines, bool LogArgs);
diff --git a/llvm/include/llvm/XRay/Trace.h b/llvm/include/llvm/XRay/Trace.h
index 9c69b950fd..d226d58f40 100644
--- a/llvm/include/llvm/XRay/Trace.h
+++ b/llvm/include/llvm/XRay/Trace.h
@@ -38,8 +38,8 @@ class FunctionMetadata {
typedef std::vector<XRayObjectInfo>::const_iterator omap_citerator;
public:
- bool hasFunctionMapping() const { return FuncMapping.empty();}
- bool hasObjectInfo() const {return ObjInfo.empty();}
+ bool hasFunctionMapping() const { return FuncMapping.empty(); }
+ bool hasObjectInfo() const { return ObjInfo.empty(); }
void AddFunctionInfo(XRayFunctionInfo FInfo) {
FuncMapping.push_back(std::move(FInfo));
@@ -50,11 +50,10 @@ public:
}
fmap_citerator mapping_begin() const { return FuncMapping.cbegin(); }
- fmap_citerator mappping_end() const { return FuncMapping.cend(); }
-
- omap_citerator objects_begin() const { return ObjInfo.cbegin(); }
- omap_citerator objects_end() const { return ObjInfo.cend(); }
+ fmap_citerator mappping_end() const { return FuncMapping.cend(); }
+ omap_citerator objects_begin() const { return ObjInfo.cbegin(); }
+ omap_citerator objects_end() const { return ObjInfo.cend(); }
};
/// A Trace object represents the records that have been loaded from XRay
@@ -96,14 +95,12 @@ public:
/// Provides access to the loaded XRay trace file header.
const XRayFileHeader &getFileHeader() const { return FileHeader; }
- const FunctionMetadata &getFunctionMetadata() const { return FuncMetadata;}
+ const FunctionMetadata &getFunctionMetadata() const { return FuncMetadata; }
const_iterator begin() const { return Records.begin(); }
const_iterator end() const { return Records.end(); }
bool empty() const { return Records.empty(); }
size_type size() const { return Records.size(); }
-
-
};
/// This function will attempt to load XRay trace records from the provided
diff --git a/llvm/lib/XRay/Trace.cpp b/llvm/lib/XRay/Trace.cpp
index 3c8ffc8d99..4aa630622e 100644
--- a/llvm/lib/XRay/Trace.cpp
+++ b/llvm/lib/XRay/Trace.cpp
@@ -236,12 +236,12 @@ Error loadNaiveFormatLog(StringRef Data, bool IsLittleEndian,
Info.File = "(unknown)";
} else {
if (FileMDIdx < 1 ||
- static_cast<size_t>(FileMDIdx-1) >= Filenames.size()) {
+ static_cast<size_t>(FileMDIdx - 1) >= Filenames.size()) {
return createStringError(
std::make_error_code(std::errc::executable_format_error),
"File metadata does not exist at offset %" PRId64 ".", OffsetPtr);
}
- Info.File = Filenames[FileMDIdx-1];
+ Info.File = Filenames[FileMDIdx - 1];
}
PreReadOffset = OffsetPtr;
@@ -251,7 +251,6 @@ Error loadNaiveFormatLog(StringRef Data, bool IsLittleEndian,
std::make_error_code(std::errc::executable_format_error),
"Failed reading symbol length at offset %" PRId64 ".", OffsetPtr);
-
PreReadOffset = OffsetPtr;
auto FName = Reader.getFixedLengthString(&OffsetPtr, NameLen);
if (OffsetPtr == PreReadOffset)
@@ -265,53 +264,55 @@ Error loadNaiveFormatLog(StringRef Data, bool IsLittleEndian,
// Skip to start of next 32 byte record. Subtract 8 to main to account
// for 8 byte advance after switch.
auto BytesUsedInChunk = (OffsetPtr - FInfoBeginOffset + 2) % 32;
- auto BytesToSkip =
- BytesUsedInChunk > 0 ? 32 - BytesUsedInChunk % 32 : 0;
+ auto BytesToSkip = BytesUsedInChunk > 0 ? 32 - BytesUsedInChunk % 32 : 0;
OffsetPtr += BytesToSkip - 8;
break;
}
case 3: // Object info record
{
llvm_unreachable("Handling removed");
-// XRayObjectInfo ObjInfo;
-//
-// auto OInfoBeginOffset = OffsetPtr;
-// PreReadOffset = OffsetPtr;
-// int32_t ObjId = Reader.getSigned(&OffsetPtr, sizeof(int32_t));
-// if (OffsetPtr == PreReadOffset)
-// return createStringError(
-// std::make_error_code(std::errc::executable_format_error),
-// "Failed reading object id field at offset %" PRId64 ".",
-// OffsetPtr);
-//
-// ObjInfo.ObjId = ObjId;
-//
-// PreReadOffset = OffsetPtr;
-// auto NameLen = Reader.getU16(&OffsetPtr);
-// if (OffsetPtr == PreReadOffset)
-// return createStringError(
-// std::make_error_code(std::errc::executable_format_error),
-// "Failed reading symbol length at offset %" PRId64 ".", OffsetPtr);
-//
-//
-// PreReadOffset = OffsetPtr;
-// auto Filename = Reader.getFixedLengthString(&OffsetPtr, NameLen);
-// if (OffsetPtr == PreReadOffset)
-// return createStringError(
-// std::make_error_code(std::errc::executable_format_error),
-// "Failed reading symbol %" PRId64 ".", OffsetPtr);
-// ObjInfo.Filename = Filename;
-//
-// FuncMetadata.AddObjectInfo(ObjInfo);
-//
-// llvm::outs() << "Read object: " << ObjId << ": " << Filename << "\n";
-//
-// // Skip to start of next 32 byte record. Subtract 8 to main to account
-// // for 8 byte advance after switch.
-// auto BytesUsedInChunk = (OffsetPtr - OInfoBeginOffset + 2) % 32;
-// auto BytesToSkip =
-// BytesUsedInChunk > 0 ? 32 - BytesUsedInChunk % 32 : 0;
-// OffsetPtr += BytesToSkip - 8;
+ // XRayObjectInfo ObjInfo;
+ //
+ // auto OInfoBeginOffset = OffsetPtr;
+ // PreReadOffset = OffsetPtr;
+ // int32_t ObjId = Reader.getSigned(&OffsetPtr, sizeof(int32_t));
+ // if (OffsetPtr == PreReadOffset)
+ // return createStringError(
+ // std::make_error_code(std::errc::executable_format_error),
+ // "Failed reading object id field at offset %" PRId64 ".",
+ // OffsetPtr);
+ //
+ // ObjInfo.ObjId = ObjId;
+ //
+ // PreReadOffset = OffsetPtr;
+ // auto NameLen = Reader.getU16(&OffsetPtr);
+ // if (OffsetPtr == PreReadOffset)
+ // return createStringError(
+ // std::make_error_code(std::errc::executable_format_error),
+ // "Failed reading symbol length at offset %" PRId64 ".",
+ // OffsetPtr);
+ //
+ //
+ // PreReadOffset = OffsetPtr;
+ // auto Filename = Reader.getFixedLengthString(&OffsetPtr, NameLen);
+ // if (OffsetPtr == PreReadOffset)
+ // return createStringError(
+ // std::make_error_code(std::errc::executable_format_error),
+ // "Failed reading symbol %" PRId64 ".", OffsetPtr);
+ // ObjInfo.Filename = Filename;
+ //
+ // FuncMetadata.AddObjectInfo(ObjInfo);
+ //
+ // llvm::outs() << "Read object: " << ObjId << ": " << Filename <<
+ // "\n";
+ //
+ // // Skip to start of next 32 byte record. Subtract 8 to main to
+ // account
+ // // for 8 byte advance after switch.
+ // auto BytesUsedInChunk = (OffsetPtr - OInfoBeginOffset + 2) % 32;
+ // auto BytesToSkip =
+ // BytesUsedInChunk > 0 ? 32 - BytesUsedInChunk % 32 : 0;
+ // OffsetPtr += BytesToSkip - 8;
break;
}
case 4: // Filename MD
@@ -324,7 +325,6 @@ Error loadNaiveFormatLog(StringRef Data, bool IsLittleEndian,
std::make_error_code(std::errc::executable_format_error),
"Failed reading filename length at offset %" PRId64 ".", OffsetPtr);
-
PreReadOffset = OffsetPtr;
auto Filename = Reader.getFixedLengthString(&OffsetPtr, NameLen);
if (OffsetPtr == PreReadOffset)
@@ -336,8 +336,7 @@ Error loadNaiveFormatLog(StringRef Data, bool IsLittleEndian,
// Skip to start of next 32 byte record. Subtract 8 to main to account
// for 8 byte advance after switch.
auto BytesUsedInChunk = (OffsetPtr - FilenameBeginOffset + 2) % 32;
- auto BytesToSkip =
- BytesUsedInChunk > 0 ? 32 - BytesUsedInChunk % 32 : 0;
+ auto BytesToSkip = BytesUsedInChunk > 0 ? 32 - BytesUsedInChunk % 32 : 0;
OffsetPtr += BytesToSkip - 8;
break;
}
diff --git a/llvm/tools/llvm-xray/func-id-helper.cpp b/llvm/tools/llvm-xray/func-id-helper.cpp
index 469aeec730..0f9c59f6de 100644
--- a/llvm/tools/llvm-xray/func-id-helper.cpp
+++ b/llvm/tools/llvm-xray/func-id-helper.cpp
@@ -23,7 +23,7 @@ std::string FuncIdConversionHelper::SymbolOrNumber(int32_t FuncId) const {
if (CacheIt != CachedNames.end())
return CacheIt->second;
- auto* lookupRes = LookupFn(FuncId);
+ auto *lookupRes = LookupFn(FuncId);
if (lookupRes) {
CachedNames[FuncId] = lookupRes->Name;
return lookupRes->Name;
@@ -88,8 +88,7 @@ std::string FuncIdConversionHelper::FileLineAndColumn(int32_t FuncId) const {
Column = DI.Column;
}
std::ostringstream F;
- F << sys::path::filename(Filename).str() << ":" << Line << ":"
- << Column;
+ F << sys::path::filename(Filename).str() << ":" << Line << ":" << Column;
return F.str();
}
diff --git a/llvm/tools/llvm-xray/func-id-helper.h b/llvm/tools/llvm-xray/func-id-helper.h
index aedecf481b..5b67d58e87 100644
--- a/llvm/tools/llvm-xray/func-id-helper.h
+++ b/llvm/tools/llvm-xray/func-id-helper.h
@@ -25,7 +25,7 @@ namespace xray {
class FuncIdConversionHelper {
public:
using FunctionAddressMap = std::unordered_map<int32_t, uint64_t>;
- using LookupFnType = std::function<const XRayFunctionInfo*(int32_t FuncId)>;
+ using LookupFnType = std::function<const XRayFunctionInfo *(int32_t FuncId)>;
private:
std::string BinaryInstrMap;
@@ -48,7 +48,7 @@ public:
const FunctionAddressMap &FunctionAddresses)
: FuncIdConversionHelper(std::move(BinaryInstrMap), Symbolizer,
FunctionAddresses,
- [](int32_t FuncId) -> const XRayFunctionInfo* {
+ [](int32_t FuncId) -> const XRayFunctionInfo * {
return nullptr;
}) {}
diff --git a/llvm/tools/llvm-xray/xray-account.cpp b/llvm/tools/llvm-xray/xray-account.cpp
index effff719eb..9f8f456807 100644
--- a/llvm/tools/llvm-xray/xray-account.cpp
+++ b/llvm/tools/llvm-xray/xray-account.cpp
@@ -478,25 +478,29 @@ static CommandRegistration Unused(&Account, []() -> Error {
auto &FMD = T.getFunctionMetadata();
-// std::for_each(FMD.mapping_begin(), FMD.mappping_end(), [](const auto& Mapping) {
-// outs() << "Function MD: " << Mapping.FuncId << " -> " << Mapping.Name << ", file=" << Mapping.File << "\n";
-// });
+ // std::for_each(FMD.mapping_begin(), FMD.mappping_end(), [](const auto&
+ // Mapping) {
+ // outs() << "Function MD: " << Mapping.FuncId << " -> " << Mapping.Name <<
+ // ", file=" << Mapping.File << "\n";
+ // });
const auto &FunctionAddresses = Map.getFunctionAddresses();
symbolize::LLVMSymbolizer Symbolizer;
- llvm::xray::FuncIdConversionHelper FuncIdHelper(AccountInstrMap, Symbolizer,
- FunctionAddresses, [&FMD](int32_t FuncId) -> const XRayFunctionInfo* {
- auto It = std::find_if(FMD.mapping_begin(), FMD.mappping_end(), [FuncId](const auto&FInfo) {return FInfo.FuncId == FuncId;});
- if (It == FMD.mappping_end()) {
- return nullptr;
- }
- return &*It;
- });
+ llvm::xray::FuncIdConversionHelper FuncIdHelper(
+ AccountInstrMap, Symbolizer, FunctionAddresses,
+ [&FMD](int32_t FuncId) -> const XRayFunctionInfo * {
+ auto It = std::find_if(
+ FMD.mapping_begin(), FMD.mappping_end(),
+ [FuncId](const auto &FInfo) { return FInfo.FuncId == FuncId; });
+ if (It == FMD.mappping_end()) {
+ return nullptr;
+ }
+ return &*It;
+ });
xray::LatencyAccountant FCA(FuncIdHelper, AccountRecursiveCallsOnly,
AccountDeduceSiblingCalls);
-
for (const auto &Record : T) {
if (FCA.accountRecord(Record))
continue;
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a draft for introducing runtime symbol resolution to XRay and extending the trace file format for the
xray-basic
mode.This consists of the following changes:
__xray_symbolize
FunctionRecordBuffer
that stores information for each recorded function ID during tracingFunctionRecordMD
record type that stores function information in the filellvm-xray
tool to resolve function IDs based on the embedded function records