aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-xray
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/llvm-xray')
-rw-r--r--llvm/tools/llvm-xray/func-id-helper.h6
-rw-r--r--llvm/tools/llvm-xray/trie-node.h2
-rw-r--r--llvm/tools/llvm-xray/xray-account.cpp33
-rw-r--r--llvm/tools/llvm-xray/xray-account.h6
-rw-r--r--llvm/tools/llvm-xray/xray-color-helper.h7
-rw-r--r--llvm/tools/llvm-xray/xray-converter.cpp32
-rw-r--r--llvm/tools/llvm-xray/xray-converter.h6
-rw-r--r--llvm/tools/llvm-xray/xray-extract.cpp12
-rw-r--r--llvm/tools/llvm-xray/xray-graph-diff.cpp4
-rw-r--r--llvm/tools/llvm-xray/xray-graph-diff.h6
-rw-r--r--llvm/tools/llvm-xray/xray-graph.cpp9
-rw-r--r--llvm/tools/llvm-xray/xray-graph.h6
-rw-r--r--llvm/tools/llvm-xray/xray-registry.cpp9
-rw-r--r--llvm/tools/llvm-xray/xray-registry.h6
-rw-r--r--llvm/tools/llvm-xray/xray-stacks.cpp9
15 files changed, 64 insertions, 89 deletions
diff --git a/llvm/tools/llvm-xray/func-id-helper.h b/llvm/tools/llvm-xray/func-id-helper.h
index d99fb7c..d1a6628 100644
--- a/llvm/tools/llvm-xray/func-id-helper.h
+++ b/llvm/tools/llvm-xray/func-id-helper.h
@@ -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 {
@@ -45,7 +44,6 @@ public:
std::string FileLineAndColumn(int32_t FuncId) const;
};
-} // namespace xray
-} // namespace llvm
+} // namespace llvm::xray
#endif // LLVM_TOOLS_LLVM_XRAY_FUNC_ID_HELPER_H
diff --git a/llvm/tools/llvm-xray/trie-node.h b/llvm/tools/llvm-xray/trie-node.h
index 7bff814..b42b029 100644
--- a/llvm/tools/llvm-xray/trie-node.h
+++ b/llvm/tools/llvm-xray/trie-node.h
@@ -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.
@@ -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
diff --git a/llvm/tools/llvm-xray/xray-account.cpp b/llvm/tools/llvm-xray/xray-account.cpp
index 24a3552..5168aa1 100644
--- a/llvm/tools/llvm-xray/xray-account.cpp
+++ b/llvm/tools/llvm-xray/xray-account.cpp
@@ -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++() {
@@ -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);
@@ -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
}
@@ -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);
@@ -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>
@@ -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:
@@ -445,7 +441,6 @@ template <> struct format_provider<llvm::xray::RecordTypes> {
}
}
};
-} // namespace llvm
static CommandRegistration Unused(&Account, []() -> Error {
InstrumentationMap Map;
@@ -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(
diff --git a/llvm/tools/llvm-xray/xray-account.h b/llvm/tools/llvm-xray/xray-account.h
index 0f24f93..c4e20731af 100644
--- a/llvm/tools/llvm-xray/xray-account.h
+++ b/llvm/tools/llvm-xray/xray-account.h
@@ -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:
@@ -107,7 +106,6 @@ private:
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
diff --git a/llvm/tools/llvm-xray/xray-color-helper.h b/llvm/tools/llvm-xray/xray-color-helper.h
index 3141e90..ae95c92 100644
--- a/llvm/tools/llvm-xray/xray-color-helper.h
+++ b/llvm/tools/llvm-xray/xray-color-helper.h
@@ -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.
@@ -82,6 +81,6 @@ public:
// 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
diff --git a/llvm/tools/llvm-xray/xray-converter.cpp b/llvm/tools/llvm-xray/xray-converter.cpp
index 34832eb..0f45fef 100644
--- a/llvm/tools/llvm-xray/xray-converter.cpp
+++ b/llvm/tools/llvm-xray/xray-converter.cpp
@@ -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) {
@@ -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,
@@ -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(
@@ -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();
@@ -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;
@@ -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
@@ -420,6 +417,3 @@ static CommandRegistration Unused(&Convert, []() -> Error {
}
return Error::success();
});
-
-} // namespace xray
-} // namespace llvm
diff --git a/llvm/tools/llvm-xray/xray-converter.h b/llvm/tools/llvm-xray/xray-converter.h
index db6d2b1..0f8efa4 100644
--- a/llvm/tools/llvm-xray/xray-converter.h
+++ b/llvm/tools/llvm-xray/xray-converter.h
@@ -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;
@@ -37,7 +36,6 @@ public:
void exportAsChromeTraceEventFormat(const Trace &Records, raw_ostream &OS);
};
-} // namespace xray
-} // namespace llvm
+} // namespace llvm::xray
#endif // LLVM_TOOLS_LLVM_XRAY_XRAY_CONVERTER_H
diff --git a/llvm/tools/llvm-xray/xray-extract.cpp b/llvm/tools/llvm-xray/xray-extract.cpp
index 52767a0..70fe011 100644
--- a/llvm/tools/llvm-xray/xray-extract.cpp
+++ b/llvm/tools/llvm-xray/xray-extract.cpp
@@ -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();
@@ -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)
@@ -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();
});
diff --git a/llvm/tools/llvm-xray/xray-graph-diff.cpp b/llvm/tools/llvm-xray/xray-graph-diff.cpp
index b5c63ab..66799091 100644
--- a/llvm/tools/llvm-xray/xray-graph-diff.cpp
+++ b/llvm/tools/llvm-xray/xray-graph-diff.cpp
@@ -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,
@@ -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);
diff --git a/llvm/tools/llvm-xray/xray-graph-diff.h b/llvm/tools/llvm-xray/xray-graph-diff.h
index c2b2a93..709f1bf 100644
--- a/llvm/tools/llvm-xray/xray-graph-diff.h
+++ b/llvm/tools/llvm-xray/xray-graph-diff.h
@@ -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
@@ -66,7 +65,6 @@ public:
const GraphT &getGraph() { return G; }
};
-} // namespace xray
-} // namespace llvm
+} // namespace llvm::xray
#endif
diff --git a/llvm/tools/llvm-xray/xray-graph.cpp b/llvm/tools/llvm-xray/xray-graph.cpp
index a97aacf..71d3029 100644
--- a/llvm/tools/llvm-xray/xray-graph.cpp
+++ b/llvm/tools/llvm-xray/xray-graph.cpp
@@ -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) {
@@ -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)
diff --git a/llvm/tools/llvm-xray/xray-graph.h b/llvm/tools/llvm-xray/xray-graph.h
index 23372d4..fd96449 100644
--- a/llvm/tools/llvm-xray/xray-graph.h
+++ b/llvm/tools/llvm-xray/xray-graph.h
@@ -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.
@@ -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
diff --git a/llvm/tools/llvm-xray/xray-registry.cpp b/llvm/tools/llvm-xray/xray-registry.cpp
index 34ac07e..ae18f8d 100644
--- a/llvm/tools/llvm-xray/xray-registry.cpp
+++ b/llvm/tools/llvm-xray/xray-registry.cpp
@@ -13,8 +13,8 @@
#include <unordered_map>
-namespace llvm {
-namespace xray {
+using namespace llvm;
+using namespace xray;
using HandlerType = std::function<Error()>;
@@ -31,12 +31,9 @@ CommandRegistration::CommandRegistration(cl::SubCommand *SC,
getCommands()[SC] = Command;
}
-HandlerType dispatch(cl::SubCommand *SC) {
+HandlerType xray::dispatch(cl::SubCommand *SC) {
auto It = getCommands().find(SC);
assert(It != getCommands().end() &&
"Attempting to dispatch on un-registered SubCommand.");
return It->second;
}
-
-} // namespace xray
-} // namespace llvm
diff --git a/llvm/tools/llvm-xray/xray-registry.h b/llvm/tools/llvm-xray/xray-registry.h
index d6fae78..3921a42 100644
--- a/llvm/tools/llvm-xray/xray-registry.h
+++ b/llvm/tools/llvm-xray/xray-registry.h
@@ -15,8 +15,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Error.h"
-namespace llvm {
-namespace xray {
+namespace llvm::xray {
// Use |CommandRegistration| as a global initialiser that registers a function
// and associates it with |SC|. This requires that a command has not been
@@ -34,7 +33,6 @@ struct CommandRegistration {
// Requires that |SC| is not null and has an associated function to it.
std::function<Error()> dispatch(cl::SubCommand *SC);
-} // namespace xray
-} // namespace llvm
+} // namespace llvm::xray
#endif // TOOLS_LLVM_XRAY_XRAY_REGISTRY_H
diff --git a/llvm/tools/llvm-xray/xray-stacks.cpp b/llvm/tools/llvm-xray/xray-stacks.cpp
index b11d732..8101cad 100644
--- a/llvm/tools/llvm-xray/xray-stacks.cpp
+++ b/llvm/tools/llvm-xray/xray-stacks.cpp
@@ -107,6 +107,8 @@ static cl::opt<AggregationType> RequestedAggregation(
"of all callees.")),
cl::sub(Stack), cl::init(AggregationType::TOTAL_TIME));
+namespace {
+
/// A helper struct to work with formatv and XRayRecords. Makes it easier to
/// use instrumentation map names or addresses in formatted output.
struct format_xray_record : public FormatAdapter<XRayRecord> {
@@ -252,10 +254,9 @@ private:
/// maintain an index of unique functions, and provide a means of iterating
/// through all the instrumented call stacks which we know about.
-namespace {
struct StackDuration {
- llvm::SmallVector<int64_t, 4> TerminalDurations;
- llvm::SmallVector<int64_t, 4> IntermediateDurations;
+ SmallVector<int64_t, 4> TerminalDurations;
+ SmallVector<int64_t, 4> IntermediateDurations;
};
} // namespace
@@ -310,6 +311,7 @@ std::size_t GetValueForStack(const StackTrieNode *Node) {
return 0;
}
+namespace {
class StackTrie {
// Avoid the magic number of 4 propagated through the code with an alias.
// We use this SmallVector to track the root nodes in a call graph.
@@ -649,6 +651,7 @@ public:
OS << "\n";
}
};
+} // namespace
static std::string CreateErrorMessage(StackTrie::AccountRecordStatus Error,
const XRayRecord &Record,