Skip to content

Commit 5d08866

Browse files
committed
[Stats] Warn on failure-to-write stats / trace files.
1 parent b954f99 commit 5d08866

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/Basic/Statistic.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,11 @@ UnifiedStatsReporter::~UnifiedStatsReporter()
361361

362362
std::error_code EC;
363363
raw_fd_ostream ostream(StatsFilename, EC, fs::F_Append | fs::F_Text);
364-
if (EC)
364+
if (EC) {
365+
llvm::errs() << "Error opening -stats-output-dir file '"
366+
<< TraceFilename << "' for writing\n";
365367
return;
368+
}
366369

367370
// We change behavior here depending on whether -DLLVM_ENABLE_STATS and/or
368371
// assertions were on in this build; this is somewhat subtle, but turning on
@@ -387,8 +390,11 @@ UnifiedStatsReporter::~UnifiedStatsReporter()
387390
if (LastTracedFrontendCounters && SourceMgr) {
388391
std::error_code EC;
389392
raw_fd_ostream tstream(TraceFilename, EC, fs::F_Append | fs::F_Text);
390-
if (EC)
393+
if (EC) {
394+
llvm::errs() << "Error opening -trace-stats-events file '"
395+
<< TraceFilename << "' for writing\n";
391396
return;
397+
}
392398
tstream << "Time,Live,IsEntry,EventName,CounterName,"
393399
<< "CounterDelta,CounterValue,SourceRange\n";
394400
for (auto const &E : FrontendStatsEvents) {

test/Misc/stats_dir.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@
2323
// RUN: %FileCheck -input-file %t/driver.csv %s
2424
// RUN: %utils/process-stats-dir.py --compare-to-csv-baseline %t/driver.csv %t
2525

26+
// RUN: %target-swiftc_driver -c -o %t/out.o -stats-output-dir %t/this/is/not/a/directory %s 2>&1 | %FileCheck -check-prefix=CHECK-NODIR %s
27+
2628
// CHECK: {{"AST.NumSourceLines" [1-9][0-9]*$}}
2729
// CHECK: {{"IRModule.NumIRFunctions" [1-9][0-9]*$}}
2830
// CHECK: {{"LLVM.NumLLVMBytesOutput" [1-9][0-9]*$}}
2931

32+
// CHECK-NODIR: {{Error opening -stats-output-dir file}}
33+
3034
public func foo() {
3135
print("hello")
3236
}

0 commit comments

Comments
 (0)