From 374554bb6b68fd8916cf2e95cb200b3a1390eb03 Mon Sep 17 00:00:00 2001 From: Teo Camarasu Date: Wed, 27 Apr 2022 21:53:53 +0100 Subject: Respect -po when heap profiling (#21446) --- rts/ProfHeap.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'rts/ProfHeap.c') diff --git a/rts/ProfHeap.c b/rts/ProfHeap.c index 7921041a5a..ab65feab2b 100644 --- a/rts/ProfHeap.c +++ b/rts/ProfHeap.c @@ -430,37 +430,43 @@ initHeapProfiling(void) init_prof_locale(); set_prof_locale(); - char *prog; + char *stem; - prog = stgMallocBytes(strlen(prog_name) + 1, "initHeapProfiling"); - strcpy(prog, prog_name); + if (RtsFlags.CcFlags.outputFileNameStem) { + stem = stgMallocBytes(strlen(RtsFlags.CcFlags.outputFileNameStem) + 1, "initHeapProfiling"); + strcpy(stem, RtsFlags.CcFlags.outputFileNameStem); + } else { + + stem = stgMallocBytes(strlen(prog_name) + 1, "initHeapProfiling"); + strcpy(stem, prog_name); #if defined(mingw32_HOST_OS) - // on Windows, drop the .exe suffix if there is one - { - char *suff; - suff = strrchr(prog,'.'); - if (suff != NULL && !strcmp(suff,".exe")) { - *suff = '\0'; - } - } + // on Windows, drop the .exe suffix if there is one + { + char *suff; + suff = strrchr(stem,'.'); + if (suff != NULL && !strcmp(suff,".exe")) { + *suff = '\0'; + } + } #endif + } if (RtsFlags.ProfFlags.doHeapProfile) { /* Initialise the log file name */ - hp_filename = stgMallocBytes(strlen(prog) + 6, "hpFileName"); - sprintf(hp_filename, "%s.hp", prog); + hp_filename = stgMallocBytes(strlen(stem) + 6, "hpFileName"); + sprintf(hp_filename, "%s.hp", stem); /* open the log file */ if ((hp_file = __rts_fopen(hp_filename, "w+")) == NULL) { debugBelch("Can't open profiling report file %s\n", hp_filename); RtsFlags.ProfFlags.doHeapProfile = 0; - stgFree(prog); + stgFree(stem); return; } } - stgFree(prog); + stgFree(stem); #if defined(PROFILING) if (doingLDVProfiling() && doingRetainerProfiling()) { -- cgit v1.2.1