diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2020-01-17 20:45:01 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2020-01-17 20:45:01 +0000 |
commit | 706b4fc47bbc608932d3b491ae19a3b9cde9497b (patch) | |
tree | 4adf86a776049cbf7f69a1929c4babcbbef925eb /llvm/lib/Support/TimeProfiler.cpp | |
parent | 7cc9cf2bf09f069cb2dd947ead05d0b54301fb71 (diff) |
Notes
Diffstat (limited to 'llvm/lib/Support/TimeProfiler.cpp')
-rw-r--r-- | llvm/lib/Support/TimeProfiler.cpp | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/llvm/lib/Support/TimeProfiler.cpp b/llvm/lib/Support/TimeProfiler.cpp index ca9119e30b65..a7c85509064e 100644 --- a/llvm/lib/Support/TimeProfiler.cpp +++ b/llvm/lib/Support/TimeProfiler.cpp @@ -13,8 +13,8 @@ #include "llvm/Support/TimeProfiler.h" #include "llvm/ADT/StringMap.h" #include "llvm/Support/CommandLine.h" -#include "llvm/Support/FileSystem.h" #include "llvm/Support/JSON.h" +#include "llvm/Support/Path.h" #include <cassert> #include <chrono> #include <string> @@ -33,14 +33,14 @@ typedef std::pair<std::string, CountAndDurationType> NameAndCountAndDurationType; struct Entry { - TimePointType Start; + const TimePointType Start; TimePointType End; - std::string Name; - std::string Detail; + const std::string Name; + const std::string Detail; Entry(TimePointType &&S, TimePointType &&E, std::string &&N, std::string &&Dt) : Start(std::move(S)), End(std::move(E)), Name(std::move(N)), - Detail(std::move(Dt)){}; + Detail(std::move(Dt)) {} // Calculate timings for FlameGraph. Cast time points to microsecond precision // rather than casting duration. This avoid truncation issues causing inner @@ -59,9 +59,9 @@ struct Entry { }; struct TimeTraceProfiler { - TimeTraceProfiler() { - StartTime = steady_clock::now(); - } + TimeTraceProfiler(unsigned TimeTraceGranularity = 0, StringRef ProcName = "") + : StartTime(steady_clock::now()), ProcName(ProcName), + TimeTraceGranularity(TimeTraceGranularity) {} void begin(std::string Name, llvm::function_ref<std::string()> Detail) { Stack.emplace_back(steady_clock::now(), TimePointType(), std::move(Name), @@ -123,7 +123,9 @@ struct TimeTraceProfiler { J.attribute("ts", StartUs); J.attribute("dur", DurUs); J.attribute("name", E.Name); - J.attributeObject("args", [&] { J.attribute("detail", E.Detail); }); + if (!E.Detail.empty()) { + J.attributeObject("args", [&] { J.attribute("detail", E.Detail); }); + } }); } @@ -168,7 +170,7 @@ struct TimeTraceProfiler { J.attribute("ts", 0); J.attribute("ph", "M"); J.attribute("name", "process_name"); - J.attributeObject("args", [&] { J.attribute("name", "clang"); }); + J.attributeObject("args", [&] { J.attribute("name", ProcName); }); }); J.arrayEnd(); @@ -179,17 +181,19 @@ struct TimeTraceProfiler { SmallVector<Entry, 16> Stack; SmallVector<Entry, 128> Entries; StringMap<CountAndDurationType> CountAndTotalPerName; - TimePointType StartTime; + const TimePointType StartTime; + const std::string ProcName; // Minimum time granularity (in microseconds) - unsigned TimeTraceGranularity; + const unsigned TimeTraceGranularity; }; -void timeTraceProfilerInitialize(unsigned TimeTraceGranularity) { +void timeTraceProfilerInitialize(unsigned TimeTraceGranularity, + StringRef ProcName) { assert(TimeTraceProfilerInstance == nullptr && "Profiler should not be initialized"); - TimeTraceProfilerInstance = new TimeTraceProfiler(); - TimeTraceProfilerInstance->TimeTraceGranularity = TimeTraceGranularity; + TimeTraceProfilerInstance = new TimeTraceProfiler( + TimeTraceGranularity, llvm::sys::path::filename(ProcName)); } void timeTraceProfilerCleanup() { |