Skip to content

Commit ffe3292

Browse files
authored
Rollup merge of #72666 - ivanloz:profile_emit_flag, r=matthewjasper
Add -Z profile-emit=<path> for Gcov gcda output. Adds a -Z flag to control the file path that the Gcov gcda output is written to during runtime. This flag expects a path and filename, e.g. -Z profile-emit=gcov/out/lib.gcda. This works similar to GCC/Clang's -fprofile-dir flag which allows control over the output path for gcda coverage files.
2 parents 320de71 + 0c1ef85 commit ffe3292

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

src/librustc_codegen_llvm/debuginfo/metadata.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -959,16 +959,16 @@ pub fn compile_unit_metadata(
959959
if tcx.sess.opts.debugging_opts.profile {
960960
let cu_desc_metadata =
961961
llvm::LLVMRustMetadataAsValue(debug_context.llcontext, unit_metadata);
962+
let default_gcda_path = &tcx.output_filenames(LOCAL_CRATE).with_extension("gcda");
963+
let gcda_path =
964+
tcx.sess.opts.debugging_opts.profile_emit.as_ref().unwrap_or(default_gcda_path);
962965

963966
let gcov_cu_info = [
964967
path_to_mdstring(
965968
debug_context.llcontext,
966969
&tcx.output_filenames(LOCAL_CRATE).with_extension("gcno"),
967970
),
968-
path_to_mdstring(
969-
debug_context.llcontext,
970-
&tcx.output_filenames(LOCAL_CRATE).with_extension("gcda"),
971-
),
971+
path_to_mdstring(debug_context.llcontext, &gcda_path),
972972
cu_desc_metadata,
973973
];
974974
let gcov_metadata = llvm::LLVMMDNodeInContext(

src/librustc_interface/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ fn test_debugging_options_tracking_hash() {
557557
tracked!(plt, Some(true));
558558
tracked!(print_fuel, Some("abc".to_string()));
559559
tracked!(profile, true);
560+
tracked!(profile_emit, Some(PathBuf::from("abc")));
560561
tracked!(relro_level, Some(RelroLevel::Full));
561562
tracked!(report_delayed_bugs, true);
562563
tracked!(run_dsymutil, false);

src/librustc_session/options.rs

+3
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,9 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
955955
"print layout information for each type encountered (default: no)"),
956956
profile: bool = (false, parse_bool, [TRACKED],
957957
"insert profiling code (default: no)"),
958+
profile_emit: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
959+
"file path to emit profiling data at runtime when using 'profile' \
960+
(default based on relative source path)"),
958961
query_dep_graph: bool = (false, parse_bool, [UNTRACKED],
959962
"enable queries of the dependency graph for regression testing (default: no)"),
960963
query_stats: bool = (false, parse_bool, [UNTRACKED],

src/test/run-make-fulldeps/profile/Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ all:
77
$(call RUN,test) || exit 1
88
[ -e "$(TMPDIR)/test.gcno" ] || (echo "No .gcno file"; exit 1)
99
[ -e "$(TMPDIR)/test.gcda" ] || (echo "No .gcda file"; exit 1)
10+
$(RUSTC) -g -Z profile -Z profile-emit=$(TMPDIR)/abc/abc.gcda test.rs
11+
$(call RUN,test) || exit 1
12+
[ -e "$(TMPDIR)/abc/abc.gcda" ] || (echo "gcda file not emitted to defined path"; exit 1)

0 commit comments

Comments
 (0)