forked from OSchip/llvm-project
[llvm-profgen] An option to dump disasm of specified symbols
For large app, dumping disasm of the whole program can be slow and result in gianant output. Adding a switch to dump specific symbols only. Reviewed By: wlei Differential Revision: https://reviews.llvm.org/D110079
This commit is contained in:
parent
1a7b7d7ba2
commit
734f4d832c
|
@ -1,4 +1,5 @@
|
|||
; RUN: llvm-profgen --format=text --perfscript=%s --binary=%S/Inputs/inline-cs-pseudoprobe.perfbin --output=%t --show-pseudo-probe --show-disassembly-only | FileCheck %s
|
||||
; RUN: llvm-profgen --format=text --perfscript=%s --binary=%S/Inputs/inline-cs-pseudoprobe.perfbin --output=%t --show-pseudo-probe --show-disassembly-only --disassemble-functions=main,foo | FileCheck %s -check-prefix=SYM
|
||||
|
||||
PERF_RECORD_MMAP2 2854748/2854748: [0x400000(0x1000) @ 0 00:1d 123291722 526021]: r-xp /home/inline-cs-pseudoprobe.perfbin
|
||||
|
||||
|
@ -79,6 +80,11 @@ PERF_RECORD_MMAP2 2854748/2854748: [0x400000(0x1000) @ 0 00:1d 123291722 526021]
|
|||
; CHECK: [Probe]: FUNC: foo Index: 9 Type: DirectCall Inlined: @ main:2
|
||||
; CHECK-NEXT: 865: callq 0x930
|
||||
|
||||
; SYM-NOT: <bar>:
|
||||
; SYM: <foo>:
|
||||
; SYM: <main>:
|
||||
|
||||
|
||||
|
||||
; clang -O3 -fexperimental-new-pass-manager -fuse-ld=lld -fpseudo-probe-for-profiling
|
||||
; -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -Xclang -mdisable-tail-calls
|
||||
|
|
|
@ -38,6 +38,11 @@ cl::opt<bool> ShowPseudoProbe(
|
|||
"show-pseudo-probe", cl::ReallyHidden, cl::init(false), cl::ZeroOrMore,
|
||||
cl::desc("Print pseudo probe section and disassembled info."));
|
||||
|
||||
static cl::list<std::string> DisassembleFunctions(
|
||||
"disassemble-functions", cl::CommaSeparated,
|
||||
cl::desc("List of functions to print disassembly for. Accept demangled "
|
||||
"names only. Only work with show-disassembly-only"));
|
||||
|
||||
namespace llvm {
|
||||
namespace sampleprof {
|
||||
|
||||
|
@ -298,7 +303,10 @@ bool ProfiledBinary::dissassembleSymbol(std::size_t SI, ArrayRef<uint8_t> Bytes,
|
|||
ShowCanonicalFnName
|
||||
? FunctionSamples::getCanonicalFnName(Symbols[SI].Name)
|
||||
: Symbols[SI].Name;
|
||||
if (ShowDisassemblyOnly)
|
||||
bool ShowDisassembly =
|
||||
ShowDisassemblyOnly && (DisassembleFunctionSet.empty() ||
|
||||
DisassembleFunctionSet.count(SymbolName));
|
||||
if (ShowDisassembly)
|
||||
outs() << '<' << SymbolName << ">:\n";
|
||||
|
||||
auto WarnInvalidInsts = [](uint64_t Start, uint64_t End) {
|
||||
|
@ -321,7 +329,7 @@ bool ProfiledBinary::dissassembleSymbol(std::size_t SI, ArrayRef<uint8_t> Bytes,
|
|||
if (Size == 0)
|
||||
Size = 1;
|
||||
|
||||
if (ShowDisassemblyOnly) {
|
||||
if (ShowDisassembly) {
|
||||
if (ShowPseudoProbe) {
|
||||
ProbeDecoder.printProbeForAddress(outs(),
|
||||
Offset + getPreferredBaseAddress());
|
||||
|
@ -385,7 +393,7 @@ bool ProfiledBinary::dissassembleSymbol(std::size_t SI, ArrayRef<uint8_t> Bytes,
|
|||
if (InvalidInstLength)
|
||||
WarnInvalidInsts(Offset - InvalidInstLength, Offset - 1);
|
||||
|
||||
if (ShowDisassemblyOnly)
|
||||
if (ShowDisassembly)
|
||||
outs() << "\n";
|
||||
|
||||
FuncStartAddrMap[StartOffset] = Symbols[SI].Name.str();
|
||||
|
@ -452,6 +460,12 @@ void ProfiledBinary::disassemble(const ELFObjectFileBase *Obj) {
|
|||
for (std::pair<const SectionRef, SectionSymbolsTy> &SecSyms : AllSymbols)
|
||||
stable_sort(SecSyms.second);
|
||||
|
||||
DisassembleFunctionSet.insert(DisassembleFunctions.begin(),
|
||||
DisassembleFunctions.end());
|
||||
assert((DisassembleFunctionSet.empty() || ShowDisassemblyOnly) &&
|
||||
"Functions to disassemble should be only specified together with "
|
||||
"--show-disassembly-only");
|
||||
|
||||
if (ShowDisassemblyOnly)
|
||||
outs() << "\nDisassembly of " << FileName << ":\n";
|
||||
|
||||
|
|
|
@ -185,6 +185,9 @@ class ProfiledBinary {
|
|||
// String table owning function name strings created from the symbolizer.
|
||||
std::unordered_set<std::string> NameStrings;
|
||||
|
||||
// A collection of functions to print disassembly for.
|
||||
StringSet<> DisassembleFunctionSet;
|
||||
|
||||
// Pseudo probe decoder
|
||||
MCPseudoProbeDecoder ProbeDecoder;
|
||||
|
||||
|
|
Loading…
Reference in New Issue