|
25 | 25 | #include "llvm/Support/Path.h"
|
26 | 26 | #include "llvm/Support/Process.h"
|
27 | 27 | #include "llvm/Support/raw_ostream.h"
|
| 28 | +#include "llvm/Support/SaveAndRestore.h" |
28 | 29 | #include <chrono>
|
29 | 30 | #include <limits>
|
30 | 31 |
|
@@ -348,7 +349,8 @@ UnifiedStatsReporter::UnifiedStatsReporter(StringRef ProgramName,
|
348 | 349 | ProgramName, "Running Program")),
|
349 | 350 | SourceMgr(SM),
|
350 | 351 | ClangSourceMgr(CSM),
|
351 |
| - RecursiveTimers(llvm::make_unique<RecursionSafeTimers>()) |
| 352 | + RecursiveTimers(llvm::make_unique<RecursionSafeTimers>()), |
| 353 | + IsFlushingTracesAndProfiles(false) |
352 | 354 | {
|
353 | 355 | path::append(StatsFilename, makeStatsFileName(ProgramName, AuxName));
|
354 | 356 | path::append(TraceFilename, makeTraceFileName(ProgramName, AuxName));
|
@@ -557,6 +559,13 @@ UnifiedStatsReporter::saveAnyFrontendStatsEvents(
|
557 | 559 | bool IsEntry)
|
558 | 560 | {
|
559 | 561 | assert(MainThreadID == std::this_thread::get_id());
|
| 562 | + |
| 563 | + // Don't record any new stats if we're currently flushing the ones we've |
| 564 | + // already recorded. This can happen when requests get kicked off when |
| 565 | + // computing source ranges. |
| 566 | + if (IsFlushingTracesAndProfiles) |
| 567 | + return; |
| 568 | + |
560 | 569 | // First make a note in the recursion-safe timers; these
|
561 | 570 | // are active anytime UnifiedStatsReporter is active.
|
562 | 571 | if (IsEntry) {
|
@@ -711,6 +720,10 @@ UnifiedStatsReporter::~UnifiedStatsReporter()
|
711 | 720 |
|
712 | 721 | void
|
713 | 722 | UnifiedStatsReporter::flushTracesAndProfiles() {
|
| 723 | + // Note that we're currently flushing statistics and shouldn't record any |
| 724 | + // more until we've finished. |
| 725 | + llvm::SaveAndRestore<bool> flushing(IsFlushingTracesAndProfiles, true); |
| 726 | + |
714 | 727 | if (FrontendStatsEvents && SourceMgr) {
|
715 | 728 | std::error_code EC;
|
716 | 729 | raw_fd_ostream tstream(TraceFilename, EC, fs::F_Append | fs::F_Text);
|
|
0 commit comments