[PATCH] D60792: Time profiler: optimize json output time

Anton Afanasyev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 16 13:35:39 PDT 2019


anton-afanasyev updated this revision to Diff 195447.
anton-afanasyev added a comment.

Update


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60792/new/

https://reviews.llvm.org/D60792

Files:
  llvm/lib/Support/TimeProfiler.cpp


Index: llvm/lib/Support/TimeProfiler.cpp
===================================================================
--- llvm/lib/Support/TimeProfiler.cpp
+++ llvm/lib/Support/TimeProfiler.cpp
@@ -89,6 +89,9 @@
            "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 @@
         {"args", json::Object{{"name", "clang"}}},
     });
 
+    assert(Events.size() == ExpectedEntryCount && "Size prediction failed!");
+
     OS << formatv("{0:2}", json::Value(json::Object(
                                {{"traceEvents", std::move(Events)}})));
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60792.195447.patch
Type: text/x-patch
Size: 827 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190416/33eb7696/attachment.bin>


More information about the llvm-commits mailing list