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,7 @@ "All profiler sections should be ended when calling Write"); json::Array Events; + Events.reserve(Entries.size() + CountAndTotalPerName.size() + 1); // Emit all events for the main flame graph. for (const auto &E : Entries) { @@ -149,6 +150,9 @@ {"args", json::Object{{"name", "clang"}}}, }); + assert( + (Entries.size() + CountAndTotalPerName.size() + 1 == Events.size()) && + "Events reserved size should be enough!"); OS << formatv("{0:2}", json::Value(json::Object( {{"traceEvents", std::move(Events)}}))); }