diff options
author | Anton Afanasyev <anton.a.afanasyev@gmail.com> | 2019-04-16 20:36:56 +0000 |
---|---|---|
committer | Anton Afanasyev <anton.a.afanasyev@gmail.com> | 2019-04-16 20:36:56 +0000 |
commit | 3a00b020aab096e7aa8c94b28b4cef86aa3adbd9 (patch) | |
tree | a95d2ee9c75b7df8ff4ba27744c557e5d9f0015e /llvm/lib/Support/TimeProfiler.cpp | |
parent | 52b24ee932aabdea16b603f405359f5270dfd38b (diff) | |
download | llvm-3a00b020aab096e7aa8c94b28b4cef86aa3adbd9.zip llvm-3a00b020aab096e7aa8c94b28b4cef86aa3adbd9.tar.gz llvm-3a00b020aab096e7aa8c94b28b4cef86aa3adbd9.tar.bz2 |
Time profiler: optimize json output time
Summary:
Use llvm::json::Array.reserve() to optimize json output time. Here is motivation:
https://reviews.llvm.org/D60609#1468941. In short: for the json array
with ~32K entries, pushing back each entry takes ~4% of whole time compared
to the method of preliminary memory reservation: (3995-3845)/3995 = 3.75%.
Reviewers: lebedev.ri
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60792
llvm-svn: 358522
Diffstat (limited to 'llvm/lib/Support/TimeProfiler.cpp')
-rw-r--r-- | llvm/lib/Support/TimeProfiler.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/llvm/lib/Support/TimeProfiler.cpp b/llvm/lib/Support/TimeProfiler.cpp index 6c7e8de..447ddf5a 100644 --- a/llvm/lib/Support/TimeProfiler.cpp +++ b/llvm/lib/Support/TimeProfiler.cpp @@ -89,6 +89,9 @@ struct TimeTraceProfiler { "All profiler sections should be ended when calling Write"); json::Array Events; + const size_t ExpectedEntryCount = + Entries.size() + CountAndTotalPerName.size() + 1; + Events.reserve(ExpectedEntryCount); // Emit all events for the main flame graph. for (const auto &E : Entries) { @@ -149,6 +152,8 @@ struct TimeTraceProfiler { {"args", json::Object{{"name", "clang"}}}, }); + assert(Events.size() == ExpectedEntryCount && "Size prediction failed!"); + OS << formatv("{0:2}", json::Value(json::Object( {{"traceEvents", std::move(Events)}}))); } |