Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions llvm/tools/llvm-xray/func-id-helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
#include "llvm/DebugInfo/Symbolize/Symbolize.h"
#include <unordered_map>

namespace llvm {
namespace xray {
namespace llvm::xray {

// This class consolidates common operations related to Function IDs.
class FuncIdConversionHelper {
Expand All @@ -45,7 +44,6 @@ class FuncIdConversionHelper {
std::string FileLineAndColumn(int32_t FuncId) const;
};

} // namespace xray
} // namespace llvm
} // namespace llvm::xray

#endif // LLVM_TOOLS_LLVM_XRAY_FUNC_ID_HELPER_H
2 changes: 2 additions & 0 deletions llvm/tools/llvm-xray/trie-node.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"

namespace llvm {
/// A type to represent a trie of invocations. It is useful to construct a
/// graph of these nodes from reading an XRay trace, such that each function
/// call can be placed in a larger context.
Expand Down Expand Up @@ -87,5 +88,6 @@ mergeTrieNodes(const TrieNode<T> &Left, const TrieNode<T> &Right,

return Node;
}
} // namespace llvm

#endif // LLVM_TOOLS_LLVM_XRAY_STACK_TRIE_H
33 changes: 14 additions & 19 deletions llvm/tools/llvm-xray/xray-account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,16 @@ static cl::opt<std::string>
static cl::alias AccountInstrMap2("m", cl::aliasopt(AccountInstrMap),
cl::desc("Alias for -instr_map"));

namespace {

template <class T, class U> void setMinMax(std::pair<T, T> &MM, U &&V) {
template <class T, class U> static void setMinMax(std::pair<T, T> &MM, U &&V) {
if (MM.first == 0 || MM.second == 0)
MM = std::make_pair(std::forward<U>(V), std::forward<U>(V));
else
MM = std::make_pair(std::min(MM.first, V), std::max(MM.second, V));
}

template <class T> T diff(T L, T R) { return std::max(L, R) - std::min(L, R); }

} // namespace
template <class T> static T diff(T L, T R) {
return std::max(L, R) - std::min(L, R);
}

using RecursionStatus = LatencyAccountant::FunctionStack::RecursionStatus;
RecursionStatus &RecursionStatus::operator++() {
Expand All @@ -143,6 +141,7 @@ RecursionStatus &RecursionStatus::operator++() {
true); // Storage |= INT_MIN
return *this;
}

RecursionStatus &RecursionStatus::operator--() {
auto Depth = Bitfield::get<RecursionStatus::Depth>(Storage);
assert(Depth > 0);
Expand All @@ -153,6 +152,7 @@ RecursionStatus &RecursionStatus::operator--() {
Bitfield::set<RecursionStatus::IsRecursive>(Storage, false); // Storage = 0
return *this;
}

bool RecursionStatus::isRecursive() const {
return Bitfield::get<RecursionStatus::IsRecursive>(Storage); // Storage s< 0
}
Expand Down Expand Up @@ -270,8 +270,9 @@ struct ResultRow {
std::string DebugInfo;
std::string Function;
};
} // namespace

ResultRow getStats(MutableArrayRef<uint64_t> Timings) {
static ResultRow getStats(MutableArrayRef<uint64_t> Timings) {
assert(!Timings.empty());
ResultRow R;
R.Sum = std::accumulate(Timings.begin(), Timings.end(), 0.0);
Expand All @@ -296,8 +297,6 @@ ResultRow getStats(MutableArrayRef<uint64_t> Timings) {
return R;
}

} // namespace

using TupleType = std::tuple<int32_t, uint64_t, ResultRow>;

template <typename F>
Expand Down Expand Up @@ -417,11 +416,8 @@ void LatencyAccountant::exportStatsAsCSV(raw_ostream &OS,
});
}

using namespace llvm::xray;

namespace llvm {
template <> struct format_provider<llvm::xray::RecordTypes> {
static void format(const llvm::xray::RecordTypes &T, raw_ostream &Stream,
template <> struct llvm::format_provider<RecordTypes> {
static void format(const RecordTypes &T, raw_ostream &Stream,
StringRef Style) {
switch (T) {
case RecordTypes::ENTER:
Expand All @@ -445,7 +441,6 @@ template <> struct format_provider<llvm::xray::RecordTypes> {
}
}
};
} // namespace llvm

static CommandRegistration Unused(&Account, []() -> Error {
InstrumentationMap Map;
Expand All @@ -468,10 +463,10 @@ static CommandRegistration Unused(&Account, []() -> Error {

const auto &FunctionAddresses = Map.getFunctionAddresses();
symbolize::LLVMSymbolizer Symbolizer;
llvm::xray::FuncIdConversionHelper FuncIdHelper(AccountInstrMap, Symbolizer,
FunctionAddresses);
xray::LatencyAccountant FCA(FuncIdHelper, AccountRecursiveCallsOnly,
AccountDeduceSiblingCalls);
FuncIdConversionHelper FuncIdHelper(AccountInstrMap, Symbolizer,
FunctionAddresses);
LatencyAccountant FCA(FuncIdHelper, AccountRecursiveCallsOnly,
AccountDeduceSiblingCalls);
auto TraceOrErr = loadTraceFile(AccountInput);
if (!TraceOrErr)
return joinErrors(
Expand Down
6 changes: 2 additions & 4 deletions llvm/tools/llvm-xray/xray-account.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
#include "llvm/Support/raw_ostream.h"
#include "llvm/XRay/XRayRecord.h"

namespace llvm {
namespace xray {
namespace llvm::xray {

class LatencyAccountant {
public:
Expand Down Expand Up @@ -107,7 +106,6 @@ class LatencyAccountant {
template <class F> void exportStats(const XRayFileHeader &Header, F fn) const;
};

} // namespace xray
} // namespace llvm
} // namespace llvm::xray

#endif // LLVM_TOOLS_LLVM_XRAY_XRAY_ACCOUNT_H
7 changes: 3 additions & 4 deletions llvm/tools/llvm-xray/xray-color-helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
#include "llvm/ADT/ArrayRef.h"
#include <tuple>

namespace llvm {
namespace xray {
namespace llvm::xray {

/// The color helper class it a healper class which allows you to easily get a
/// color in a gradient. This is used to color-code edges in XRay-Graph tools.
Expand Down Expand Up @@ -82,6 +81,6 @@ class ColorHelper {
// Convert a tuple to a string
static std::string getColorString(std::tuple<uint8_t, uint8_t, uint8_t> t);
};
} // namespace xray
} // namespace llvm
} // namespace llvm::xray

#endif
32 changes: 13 additions & 19 deletions llvm/tools/llvm-xray/xray-converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,14 @@ struct StackIdData {
// unique ID.
SmallVector<TrieNode<StackIdData> *, 4> siblings;
};
} // namespace

using StackTrieNode = TrieNode<StackIdData>;

// A helper function to find the sibling nodes for an encountered function in a
// thread of execution. Relies on the invariant that each time a new node is
// traversed in a thread, sibling bidirectional pointers are maintained.
SmallVector<StackTrieNode *, 4>
static SmallVector<StackTrieNode *, 4>
findSiblings(StackTrieNode *parent, int32_t FnId, uint32_t TId,
const DenseMap<uint32_t, SmallVector<StackTrieNode *, 4>>
&StackRootsByThreadId) {
Expand Down Expand Up @@ -213,7 +214,7 @@ findSiblings(StackTrieNode *parent, int32_t FnId, uint32_t TId,
// StackTrie representing the function call stack. If no node exists, creates
// the node. Assigns unique IDs to stacks newly encountered among all threads
// and keeps sibling links up to when creating new nodes.
StackTrieNode *findOrCreateStackNode(
static StackTrieNode *findOrCreateStackNode(
StackTrieNode *Parent, int32_t FuncId, uint32_t TId,
DenseMap<uint32_t, SmallVector<StackTrieNode *, 4>> &StackRootsByThreadId,
DenseMap<unsigned, StackTrieNode *> &StacksByStackId, unsigned *id_counter,
Expand Down Expand Up @@ -244,12 +245,13 @@ StackTrieNode *findOrCreateStackNode(
return CurrentStack;
}

void writeTraceViewerRecord(uint16_t Version, raw_ostream &OS, int32_t FuncId,
uint32_t TId, uint32_t PId, bool Symbolize,
const FuncIdConversionHelper &FuncIdHelper,
double EventTimestampUs,
const StackTrieNode &StackCursor,
StringRef FunctionPhenotype) {
static void writeTraceViewerRecord(uint16_t Version, raw_ostream &OS,
int32_t FuncId, uint32_t TId, uint32_t PId,
bool Symbolize,
const FuncIdConversionHelper &FuncIdHelper,
double EventTimestampUs,
const StackTrieNode &StackCursor,
StringRef FunctionPhenotype) {
OS << " ";
if (Version >= 3) {
OS << llvm::formatv(
Expand All @@ -269,8 +271,6 @@ void writeTraceViewerRecord(uint16_t Version, raw_ostream &OS, int32_t FuncId,
}
}

} // namespace

void TraceConverter::exportAsChromeTraceEventFormat(const Trace &Records,
raw_ostream &OS) {
const auto &FH = Records.getFileHeader();
Expand Down Expand Up @@ -364,9 +364,6 @@ void TraceConverter::exportAsChromeTraceEventFormat(const Trace &Records,
OS << "}\n"; // Close the JSON entry.
}

namespace llvm {
namespace xray {

static CommandRegistration Unused(&Convert, []() -> Error {
// FIXME: Support conversion to BINARY when upgrading XRay trace versions.
InstrumentationMap Map;
Expand All @@ -386,9 +383,9 @@ static CommandRegistration Unused(&Convert, []() -> Error {
if (Demangle.getPosition() < NoDemangle.getPosition())
SymbolizerOpts.Demangle = false;
symbolize::LLVMSymbolizer Symbolizer(SymbolizerOpts);
llvm::xray::FuncIdConversionHelper FuncIdHelper(ConvertInstrMap, Symbolizer,
FunctionAddresses);
llvm::xray::TraceConverter TC(FuncIdHelper, ConvertSymbolize);
FuncIdConversionHelper FuncIdHelper(ConvertInstrMap, Symbolizer,
FunctionAddresses);
TraceConverter TC(FuncIdHelper, ConvertSymbolize);
std::error_code EC;
raw_fd_ostream OS(ConvertOutput, EC,
ConvertOutputFormat == ConvertFormats::BINARY
Expand Down Expand Up @@ -420,6 +417,3 @@ static CommandRegistration Unused(&Convert, []() -> Error {
}
return Error::success();
});

} // namespace xray
} // namespace llvm
6 changes: 2 additions & 4 deletions llvm/tools/llvm-xray/xray-converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
#include "llvm/XRay/Trace.h"
#include "llvm/XRay/XRayRecord.h"

namespace llvm {
namespace xray {
namespace llvm::xray {

class TraceConverter {
FuncIdConversionHelper &FuncIdHelper;
Expand All @@ -37,7 +36,6 @@ class TraceConverter {
void exportAsChromeTraceEventFormat(const Trace &Records, raw_ostream &OS);
};

} // namespace xray
} // namespace llvm
} // namespace llvm::xray

#endif // LLVM_TOOLS_LLVM_XRAY_XRAY_CONVERTER_H
12 changes: 4 additions & 8 deletions llvm/tools/llvm-xray/xray-extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ static cl::opt<bool> NoDemangle("no-demangle",
cl::desc("don't demangle symbols"),
cl::sub(Extract));

namespace {

void exportAsYAML(const InstrumentationMap &Map, raw_ostream &OS,
FuncIdConversionHelper &FH) {
static void exportAsYAML(const InstrumentationMap &Map, raw_ostream &OS,
FuncIdConversionHelper &FH) {
// First we translate the sleds into the YAMLXRaySledEntry objects in a deque.
std::vector<YAMLXRaySledEntry> YAMLSleds;
auto Sleds = Map.sleds();
Expand All @@ -72,8 +70,6 @@ void exportAsYAML(const InstrumentationMap &Map, raw_ostream &OS,
Out << YAMLSleds;
}

} // namespace

static CommandRegistration Unused(&Extract, []() -> Error {
auto InstrumentationMapOrError = loadInstrumentationMap(ExtractInput);
if (!InstrumentationMapOrError)
Expand All @@ -94,8 +90,8 @@ static CommandRegistration Unused(&Extract, []() -> Error {
if (Demangle.getPosition() < NoDemangle.getPosition())
opts.Demangle = false;
symbolize::LLVMSymbolizer Symbolizer(opts);
llvm::xray::FuncIdConversionHelper FuncIdHelper(ExtractInput, Symbolizer,
FunctionAddresses);
FuncIdConversionHelper FuncIdHelper(ExtractInput, Symbolizer,
FunctionAddresses);
exportAsYAML(*InstrumentationMapOrError, OS, FuncIdHelper);
return Error::success();
});
4 changes: 2 additions & 2 deletions llvm/tools/llvm-xray/xray-graph-diff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ Expected<GraphDiffRenderer> GraphDiffRenderer::Factory::getGraphDiffRenderer() {

return R;
}

// Returns the Relative change With respect to LeftStat between LeftStat
// and RightStat.
static double statRelDiff(const GraphDiffRenderer::TimeStat &LeftStat,
Expand Down Expand Up @@ -363,9 +364,8 @@ void GraphDiffRenderer::exportGraphAsDOT(raw_ostream &OS, StatType EdgeLabel,
StringMap<int32_t> VertexNo;

int i = 0;
for (const auto &V : G.vertices()) {
for (const auto &V : G.vertices())
VertexNo[V.first] = i++;
}

ColorHelper H(ColorHelper::DivergingScheme::PiYG);

Expand Down
6 changes: 2 additions & 4 deletions llvm/tools/llvm-xray/xray-graph-diff.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
#include "xray-graph.h"
#include "llvm/XRay/Graph.h"

namespace llvm {
namespace xray {
namespace llvm::xray {

// This class creates a graph representing the difference between two
// xray-graphs And allows you to print it to a dot file, with optional color
Expand Down Expand Up @@ -66,7 +65,6 @@ class GraphDiffRenderer {

const GraphT &getGraph() { return G; }
};
} // namespace xray
} // namespace llvm
} // namespace llvm::xray

#endif
9 changes: 5 additions & 4 deletions llvm/tools/llvm-xray/xray-graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ static cl::opt<GraphRenderer::StatType> GraphVertexColorType(
static cl::alias GraphVertexColorType2("b", cl::aliasopt(GraphVertexColorType),
cl::desc("Alias for -edge-label"));

template <class T> T diff(T L, T R) { return std::max(L, R) - std::min(L, R); }
template <class T> static T diff(T L, T R) {
return std::max(L, R) - std::min(L, R);
}

// Updates the statistics for a GraphRenderer::TimeStat
static void updateStat(GraphRenderer::TimeStat &S, int64_t L) {
Expand Down Expand Up @@ -459,10 +461,9 @@ Expected<GraphRenderer> GraphRenderer::Factory::getGraphRenderer() {
symbolize::LLVMSymbolizer Symbolizer;
const auto &Header = Trace.getFileHeader();

llvm::xray::FuncIdConversionHelper FuncIdHelper(InstrMap, Symbolizer,
FunctionAddresses);
FuncIdConversionHelper FuncIdHelper(InstrMap, Symbolizer, FunctionAddresses);

xray::GraphRenderer GR(FuncIdHelper, DeduceSiblingCalls);
GraphRenderer GR(FuncIdHelper, DeduceSiblingCalls);
for (const auto &Record : Trace) {
auto E = GR.accountRecord(Record);
if (!E)
Expand Down
6 changes: 2 additions & 4 deletions llvm/tools/llvm-xray/xray-graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
#include "llvm/XRay/Trace.h"
#include "llvm/XRay/XRayRecord.h"

namespace llvm {
namespace xray {
namespace llvm::xray {

/// A class encapsulating the logic related to analyzing XRay traces, producting
/// Graphs from them and then exporting those graphs for review.
Expand Down Expand Up @@ -225,7 +224,6 @@ inline GraphRenderer::TimeStat operator/(const GraphRenderer::TimeStat &A,
A.Pct90 / B.Pct90, A.Pct99 / B.Pct99, A.Max / B.Max,
A.Sum / B.Sum};
}
} // namespace xray
} // namespace llvm
} // namespace llvm::xray

#endif // XRAY_GRAPH_H
Loading