diff --git a/llvm/tools/llvm-xray/func-id-helper.h b/llvm/tools/llvm-xray/func-id-helper.h index d99fb7c1cfb0c..d1a66282bab0b 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 -namespace llvm { -namespace xray { +namespace llvm::xray { // This class consolidates common operations related to Function IDs. class FuncIdConversionHelper { @@ -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 diff --git a/llvm/tools/llvm-xray/trie-node.h b/llvm/tools/llvm-xray/trie-node.h index 7bff81473b5df..b42b0293620dd 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 &Left, const TrieNode &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 24a3552cfb91e..5168aa1c88bc6 100644 --- a/llvm/tools/llvm-xray/xray-account.cpp +++ b/llvm/tools/llvm-xray/xray-account.cpp @@ -118,18 +118,16 @@ static cl::opt static cl::alias AccountInstrMap2("m", cl::aliasopt(AccountInstrMap), cl::desc("Alias for -instr_map")); -namespace { - -template void setMinMax(std::pair &MM, U &&V) { +template static void setMinMax(std::pair &MM, U &&V) { if (MM.first == 0 || MM.second == 0) MM = std::make_pair(std::forward(V), std::forward(V)); else MM = std::make_pair(std::min(MM.first, V), std::max(MM.second, V)); } -template T diff(T L, T R) { return std::max(L, R) - std::min(L, R); } - -} // namespace +template 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(Storage); assert(Depth > 0); @@ -153,6 +152,7 @@ RecursionStatus &RecursionStatus::operator--() { Bitfield::set(Storage, false); // Storage = 0 return *this; } + bool RecursionStatus::isRecursive() const { return Bitfield::get(Storage); // Storage s< 0 } @@ -270,8 +270,9 @@ struct ResultRow { std::string DebugInfo; std::string Function; }; +} // namespace -ResultRow getStats(MutableArrayRef Timings) { +static ResultRow getStats(MutableArrayRef Timings) { assert(!Timings.empty()); ResultRow R; R.Sum = std::accumulate(Timings.begin(), Timings.end(), 0.0); @@ -296,8 +297,6 @@ ResultRow getStats(MutableArrayRef Timings) { return R; } -} // namespace - using TupleType = std::tuple; template @@ -417,11 +416,8 @@ void LatencyAccountant::exportStatsAsCSV(raw_ostream &OS, }); } -using namespace llvm::xray; - -namespace llvm { -template <> struct format_provider { - static void format(const llvm::xray::RecordTypes &T, raw_ostream &Stream, +template <> struct llvm::format_provider { + static void format(const RecordTypes &T, raw_ostream &Stream, StringRef Style) { switch (T) { case RecordTypes::ENTER: @@ -445,7 +441,6 @@ template <> struct format_provider { } } }; -} // 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 0f24f93b9fd10..c4e20731af083 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 @@ class LatencyAccountant { template 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 3141e90cc893c..ae95c921769f0 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 -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 @@ class ColorHelper { // Convert a tuple to a string static std::string getColorString(std::tuple 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 34832ebda0224..0f45fef670014 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 *, 4> siblings; }; +} // namespace using StackTrieNode = TrieNode; // 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 +static SmallVector findSiblings(StackTrieNode *parent, int32_t FnId, uint32_t TId, const DenseMap> &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> &StackRootsByThreadId, DenseMap &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 db6d2b1614ee2..0f8efa4626081 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 @@ 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 diff --git a/llvm/tools/llvm-xray/xray-extract.cpp b/llvm/tools/llvm-xray/xray-extract.cpp index 52767a00f6152..70fe0111b0c40 100644 --- a/llvm/tools/llvm-xray/xray-extract.cpp +++ b/llvm/tools/llvm-xray/xray-extract.cpp @@ -52,10 +52,8 @@ static cl::opt 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 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 b5c63ab0a9183..6679909121fab 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::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 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 c2b2a938bfbc6..709f1bf1339d9 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 @@ class GraphDiffRenderer { 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 a97aacfd67b7a..71d30295e4dbf 100644 --- a/llvm/tools/llvm-xray/xray-graph.cpp +++ b/llvm/tools/llvm-xray/xray-graph.cpp @@ -153,7 +153,9 @@ static cl::opt GraphVertexColorType( static cl::alias GraphVertexColorType2("b", cl::aliasopt(GraphVertexColorType), cl::desc("Alias for -edge-label")); -template T diff(T L, T R) { return std::max(L, R) - std::min(L, R); } +template 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::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 23372d40f05ee..fd9644908426f 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 34ac07ebe45c1..ae18f8d6f57c1 100644 --- a/llvm/tools/llvm-xray/xray-registry.cpp +++ b/llvm/tools/llvm-xray/xray-registry.cpp @@ -13,8 +13,8 @@ #include -namespace llvm { -namespace xray { +using namespace llvm; +using namespace xray; using HandlerType = std::function; @@ -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 d6fae78ea53cc..3921a423c8fad 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 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 b11d732a4fcc0..8101cad28ca1c 100644 --- a/llvm/tools/llvm-xray/xray-stacks.cpp +++ b/llvm/tools/llvm-xray/xray-stacks.cpp @@ -107,6 +107,8 @@ static cl::opt 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 { @@ -252,10 +254,9 @@ struct format_xray_record : public FormatAdapter { /// 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 TerminalDurations; - llvm::SmallVector IntermediateDurations; + SmallVector TerminalDurations; + SmallVector 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 @@ class StackTrie { OS << "\n"; } }; +} // namespace static std::string CreateErrorMessage(StackTrie::AccountRecordStatus Error, const XRayRecord &Record,