llvm/llvm/tools/llvm-profgen/PerfReader.cpp

//===-- PerfReader.cpp - perfscript reader  ---------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "PerfReader.h"
#include "ProfileGenerator.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/ToolOutputFile.h"

#define DEBUG_TYPE

cl::opt<bool> SkipSymbolization("skip-symbolization",
                                cl::desc("Dump the unsymbolized profile to the "
                                         "output file. It will show unwinder "
                                         "output for CS profile generation."));

static cl::opt<bool> ShowMmapEvents("show-mmap-events",
                                    cl::desc("Print binary load events."));

static cl::opt<bool>
    UseOffset("use-offset", cl::init(true),
              cl::desc("Work with `--skip-symbolization` or "
                       "`--unsymbolized-profile` to write/read the "
                       "offset instead of virtual address."));

static cl::opt<bool> UseLoadableSegmentAsBase(
    "use-first-loadable-segment-as-base",
    cl::desc("Use first loadable segment address as base address "
             "for offsets in unsymbolized profile. By default "
             "first executable segment address is used"));

static cl::opt<bool>
    IgnoreStackSamples("ignore-stack-samples",
                       cl::desc("Ignore call stack samples for hybrid samples "
                                "and produce context-insensitive profile."));
cl::opt<bool> ShowDetailedWarning("show-detailed-warning",
                                  cl::desc("Show detailed warning message."));

extern cl::opt<std::string> PerfTraceFilename;
extern cl::opt<bool> ShowDisassemblyOnly;
extern cl::opt<bool> ShowSourceLocations;
extern cl::opt<std::string> OutputFilename;

namespace llvm {
namespace sampleprof {

void VirtualUnwinder::unwindCall(UnwindState &State) {}

void VirtualUnwinder::unwindLinear(UnwindState &State, uint64_t Repeat) {}

void VirtualUnwinder::unwindReturn(UnwindState &State) {}

void VirtualUnwinder::unwindBranch(UnwindState &State) {}

std::shared_ptr<StringBasedCtxKey> FrameStack::getContextKey() {}

std::shared_ptr<AddrBasedCtxKey> AddressStack::getContextKey() {}

template <typename T>
void VirtualUnwinder::collectSamplesFromFrame(UnwindState::ProfiledFrame *Cur,
                                              T &Stack) {}

template <typename T>
void VirtualUnwinder::collectSamplesFromFrameTrie(
    UnwindState::ProfiledFrame *Cur, T &Stack) {}

void VirtualUnwinder::collectSamplesFromFrameTrie(
    UnwindState::ProfiledFrame *Cur) {}

void VirtualUnwinder::recordBranchCount(const LBREntry &Branch,
                                        UnwindState &State, uint64_t Repeat) {}

bool VirtualUnwinder::unwind(const PerfSample *Sample, uint64_t Repeat) {}

std::unique_ptr<PerfReaderBase>
PerfReaderBase::create(ProfiledBinary *Binary, PerfInputFile &PerfInput,
                       std::optional<int32_t> PIDFilter) {}

PerfInputFile
PerfScriptReader::convertPerfDataToTrace(ProfiledBinary *Binary, bool SkipPID,
                                         PerfInputFile &File,
                                         std::optional<int32_t> PIDFilter) {}

static StringRef filename(StringRef Path, bool UseBackSlash) {}

void PerfScriptReader::updateBinaryAddress(const MMapEvent &Event) {}

static std::string getContextKeyStr(ContextKey *K,
                                    const ProfiledBinary *Binary) {}

void HybridPerfReader::unwindSamples() {}

bool PerfScriptReader::extractLBRStack(TraceStream &TraceIt,
                                       SmallVectorImpl<LBREntry> &LBRStack) {}

bool PerfScriptReader::extractCallstack(TraceStream &TraceIt,
                                        SmallVectorImpl<uint64_t> &CallStack) {}

void PerfScriptReader::warnIfMissingMMap() {}

void HybridPerfReader::parseSample(TraceStream &TraceIt, uint64_t Count) {}

void PerfScriptReader::writeUnsymbolizedProfile(StringRef Filename) {}

// Use ordered map to make the output deterministic
OrderedCounterForPrint;

void PerfScriptReader::writeUnsymbolizedProfile(raw_fd_ostream &OS) {}

// Format of input:
// number of entries in RangeCounter
// from_1-to_1:count_1
// from_2-to_2:count_2
// ......
// from_n-to_n:count_n
// number of entries in BranchCounter
// src_1->dst_1:count_1
// src_2->dst_2:count_2
// ......
// src_n->dst_n:count_n
void UnsymbolizedProfileReader::readSampleCounters(TraceStream &TraceIt,
                                                   SampleCounter &SCounters) {}

void UnsymbolizedProfileReader::readUnsymbolizedProfile(StringRef FileName) {}

void UnsymbolizedProfileReader::parsePerfTraces() {}

void PerfScriptReader::computeCounterFromLBR(const PerfSample *Sample,
                                             uint64_t Repeat) {}

void LBRPerfReader::parseSample(TraceStream &TraceIt, uint64_t Count) {}

void PerfScriptReader::generateUnsymbolizedProfile() {}

uint64_t PerfScriptReader::parseAggregatedCount(TraceStream &TraceIt) {}

void PerfScriptReader::parseSample(TraceStream &TraceIt) {}

bool PerfScriptReader::extractMMapEventForBinary(ProfiledBinary *Binary,
                                                 StringRef Line,
                                                 MMapEvent &MMap) {}

void PerfScriptReader::parseMMapEvent(TraceStream &TraceIt) {}

void PerfScriptReader::parseEventOrSample(TraceStream &TraceIt) {}

void PerfScriptReader::parseAndAggregateTrace() {}

// A LBR sample is like:
// 40062f 0x5c6313f/0x5c63170/P/-/-/0  0x5c630e7/0x5c63130/P/-/-/0 ...
// A heuristic for fast detection by checking whether a
// leading "  0x" and the '/' exist.
bool PerfScriptReader::isLBRSample(StringRef Line) {}

bool PerfScriptReader::isMMapEvent(StringRef Line) {}

// The raw hybird sample is like
// e.g.
// 	          4005dc    # call stack leaf
//	          400634
//	          400684    # call stack root
// 0x4005c8/0x4005dc/P/-/-/0   0x40062f/0x4005b0/P/-/-/0 ...
//          ... 0x4005c8/0x4005dc/P/-/-/0    # LBR Entries
// Determine the perfscript contains hybrid samples(call stack + LBRs) by
// checking whether there is a non-empty call stack immediately followed by
// a LBR sample
PerfContent PerfScriptReader::checkPerfScriptType(StringRef FileName) {}

void HybridPerfReader::generateUnsymbolizedProfile() {}

void PerfScriptReader::warnTruncatedStack() {}

void PerfScriptReader::warnInvalidRange() {}

void PerfScriptReader::parsePerfTraces() {}

SmallVector<CleanupInstaller, 2> PerfScriptReader::TempFileCleanups;

} // end namespace sampleprof
} // end namespace llvm