Skip to content

[Stats] Warn on failure-to-write stats / trace files. #12308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/Basic/Statistic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,11 @@ UnifiedStatsReporter::~UnifiedStatsReporter()

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

// We change behavior here depending on whether -DLLVM_ENABLE_STATS and/or
// assertions were on in this build; this is somewhat subtle, but turning on
Expand All @@ -387,8 +390,11 @@ UnifiedStatsReporter::~UnifiedStatsReporter()
if (LastTracedFrontendCounters && SourceMgr) {
std::error_code EC;
raw_fd_ostream tstream(TraceFilename, EC, fs::F_Append | fs::F_Text);
if (EC)
if (EC) {
llvm::errs() << "Error opening -trace-stats-events file '"
<< TraceFilename << "' for writing\n";
return;
}
tstream << "Time,Live,IsEntry,EventName,CounterName,"
<< "CounterDelta,CounterValue,SourceRange\n";
for (auto const &E : FrontendStatsEvents) {
Expand Down
4 changes: 4 additions & 0 deletions test/Misc/stats_dir.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@
// RUN: %FileCheck -input-file %t/driver.csv %s
// RUN: %utils/process-stats-dir.py --compare-to-csv-baseline %t/driver.csv %t

// 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

// CHECK: {{"AST.NumSourceLines" [1-9][0-9]*$}}
// CHECK: {{"IRModule.NumIRFunctions" [1-9][0-9]*$}}
// CHECK: {{"LLVM.NumLLVMBytesOutput" [1-9][0-9]*$}}

// CHECK-NODIR: {{Error opening -stats-output-dir file}}

public func foo() {
print("hello")
}