Skip to content

Commit cfa3d26

Browse files
alanzhao1IanWood1
authored andcommitted
[clang] Make -ftime-report and -ftime-report-json honor -info-output-file (llvm#138035)
This way, the output of `-ftime-report` and `-ftime-report-json` can be redirected to a specific file rather than just stderr.
1 parent ed98e4b commit cfa3d26

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

clang/test/Misc/time-passes.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
// RUN: -ftime-report %s -o /dev/null 2>&1 | \
44
// RUN: FileCheck %s --check-prefixes=TIME,NPM
55
// RUN: %clang_cc1 -emit-obj -O1 \
6+
// RUN: -ftime-report %s -o /dev/null \
7+
// RUN: -mllvm -info-output-file=%t
8+
// RUN: cat %t | FileCheck %s --check-prefixes=TIME,NPM
9+
// RUN: %clang_cc1 -emit-obj -O1 \
610
// RUN: -ftime-report=per-pass %s -o /dev/null 2>&1 | \
711
// RUN: FileCheck %s --check-prefixes=TIME,NPM
812
// RUN: %clang_cc1 -emit-obj -O1 \
@@ -11,6 +15,10 @@
1115
// RUN: %clang_cc1 -emit-obj -O1 \
1216
// RUN: -ftime-report-json %s -o /dev/null 2>&1 | \
1317
// RUN: FileCheck %s --check-prefixes=JSON
18+
// RUN: %clang_cc1 -emit-obj -O1 \
19+
// RUN: -ftime-report-json %s -o /dev/null \
20+
// RUN: -mllvm -info-output-file=%t
21+
// RUN: cat %t | FileCheck %s --check-prefixes=JSON
1422

1523
// TIME: Pass execution timing report
1624
// TIME: Total Execution Time:

clang/tools/driver/cc1_main.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,13 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
296296

297297
// If any timers were active but haven't been destroyed yet, print their
298298
// results now. This happens in -disable-free mode.
299+
std::unique_ptr<raw_ostream> IOFile = llvm::CreateInfoOutputFile();
299300
if (Clang->getCodeGenOpts().TimePassesJson) {
300-
llvm::errs() << "{\n";
301-
llvm::TimerGroup::printAllJSONValues(llvm::errs(), "");
302-
llvm::errs() << "\n}\n";
301+
*IOFile << "{\n";
302+
llvm::TimerGroup::printAllJSONValues(*IOFile, "");
303+
*IOFile << "\n}\n";
303304
} else {
304-
llvm::TimerGroup::printAll(llvm::errs());
305+
llvm::TimerGroup::printAll(*IOFile);
305306
}
306307
llvm::TimerGroup::clearAll();
307308

0 commit comments

Comments
 (0)