diff --git a/llvm/lib/Support/TimeProfiler.cpp b/llvm/lib/Support/TimeProfiler.cpp --- a/llvm/lib/Support/TimeProfiler.cpp +++ b/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)}}))); }