summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gröber <dxld@darkboxed.org>2019-07-10 17:16:33 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-07-16 02:41:23 -0400
commit373c9cb379bd64c4d295becf3afce122a6e199f4 (patch)
treed1d50715bb8d9fd90865268d54a2937839866d4f
parentdb948daea6c01c073f8d09a79fa5adda279fbf0c (diff)
downloadhaskell-373c9cb379bd64c4d295becf3afce122a6e199f4.tar.gz
rts: Divorce init of Heap profiler from CCS profiler
Currently initProfiling gets defined by Profiling.c only if PROFILING is defined. Otherwise the ProfHeap.c defines it. This is just needlessly complicated so in this commit I make Profiling and ProfHeap into properly seperate modules and call their respective init functions from RtsStartup.c.
-rw-r--r--rts/ProfHeap.c96
-rw-r--r--rts/ProfHeap.h3
-rw-r--r--rts/Profiling.c23
-rw-r--r--rts/RtsStartup.c9
4 files changed, 52 insertions, 79 deletions
diff --git a/rts/ProfHeap.c b/rts/ProfHeap.c
index b63bc527ef..1023f7ccbe 100644
--- a/rts/ProfHeap.c
+++ b/rts/ProfHeap.c
@@ -26,6 +26,9 @@
#include <fs_rts.h>
#include <string.h>
+FILE *hp_file;
+static char *hp_filename; /* heap profile (hp2ps style) log file */
+
/* -----------------------------------------------------------------------------
* era stores the current time period. It is the same as the
* number of censuses that have been performed.
@@ -311,57 +314,6 @@ nextEra( void )
* Heap profiling by info table
* ------------------------------------------------------------------------- */
-#if !defined(PROFILING)
-FILE *hp_file;
-static char *hp_filename;
-
-void freeProfiling (void)
-{
-}
-
-void initProfiling (void)
-{
- char *prog;
-
- prog = stgMallocBytes(strlen(prog_name) + 1, "initProfiling2");
- strcpy(prog, 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';
- }
- }
-#endif
-
- if (RtsFlags.ProfFlags.doHeapProfile) {
- /* Initialise the log file name */
- hp_filename = stgMallocBytes(strlen(prog) + 6, "hpFileName");
- sprintf(hp_filename, "%s.hp", prog);
-
- /* 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);
- return;
- }
- }
-
- stgFree(prog);
-
- initHeapProfiling();
-}
-
-void endProfiling( void )
-{
- endHeapProfiling();
-}
-#endif /* !PROFILING */
-
static void
printEscapedString(const char* string)
{
@@ -398,16 +350,52 @@ dumpCostCentresToEventLog(void)
#endif
}
+void freeHeapProfiling (void)
+{
+}
+
/* --------------------------------------------------------------------------
* Initialize the heap profilier
* ----------------------------------------------------------------------- */
-uint32_t
+void
initHeapProfiling(void)
{
if (! RtsFlags.ProfFlags.doHeapProfile) {
- return 0;
+ return;
}
+ char *prog;
+
+ prog = stgMallocBytes(strlen(prog_name) + 1, "initHeapProfiling");
+ strcpy(prog, 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';
+ }
+ }
+#endif
+
+ if (RtsFlags.ProfFlags.doHeapProfile) {
+ /* Initialise the log file name */
+ hp_filename = stgMallocBytes(strlen(prog) + 6, "hpFileName");
+ sprintf(hp_filename, "%s.hp", prog);
+
+ /* 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);
+ return;
+ }
+ }
+
+ stgFree(prog);
+
#if defined(PROFILING)
if (doingLDVProfiling() && doingRetainerProfiling()) {
errorBelch("cannot mix -hb and -hr");
@@ -475,8 +463,6 @@ initHeapProfiling(void)
traceHeapProfBegin(0);
dumpCostCentresToEventLog();
-
- return 0;
}
void
diff --git a/rts/ProfHeap.h b/rts/ProfHeap.h
index aa4056b111..f63433fece 100644
--- a/rts/ProfHeap.h
+++ b/rts/ProfHeap.h
@@ -11,8 +11,9 @@
#include "BeginPrivate.h"
void heapCensus (Time t);
-uint32_t initHeapProfiling (void);
+void initHeapProfiling (void);
void endHeapProfiling (void);
+void freeHeapProfiling (void);
bool strMatchesSelector (const char* str, const char* sel);
#if defined(PROFILING)
diff --git a/rts/Profiling.c b/rts/Profiling.c
index 3c7f52b6f4..4931898fe0 100644
--- a/rts/Profiling.c
+++ b/rts/Profiling.c
@@ -51,9 +51,6 @@ static unsigned int CCS_ID = 1;
static char *prof_filename; /* prof report file name = <program>.prof */
FILE *prof_file;
-static char *hp_filename; /* heap profile (hp2ps style) log file */
-FILE *hp_file;
-
// List of all cost centres. Used for reporting.
CostCentre *CC_LIST = NULL;
// All cost centre stacks temporarily appear here, to be able to make CCS_MAIN a
@@ -190,10 +187,6 @@ void initProfiling (void)
if (RtsFlags.CcFlags.doCostCentres) {
initTimeProfiling();
}
-
- if (RtsFlags.ProfFlags.doHeapProfile) {
- initHeapProfiling();
- }
}
//
@@ -280,19 +273,6 @@ initProfilingLogFile(void)
}
}
}
-
- if (RtsFlags.ProfFlags.doHeapProfile) {
- /* Initialise the log file name */
- hp_filename = arenaAlloc(prof_arena, strlen(stem) + 6);
- 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;
- }
- }
}
void
@@ -308,9 +288,6 @@ endProfiling ( void )
if (RtsFlags.CcFlags.doCostCentres) {
stopProfTimer();
}
- if (RtsFlags.ProfFlags.doHeapProfile) {
- endHeapProfiling();
- }
}
/* -----------------------------------------------------------------------------
diff --git a/rts/RtsStartup.c b/rts/RtsStartup.c
index 5e5aef3505..a202d53960 100644
--- a/rts/RtsStartup.c
+++ b/rts/RtsStartup.c
@@ -31,6 +31,7 @@
#include "StaticPtrTable.h"
#include "Hash.h"
#include "Profiling.h"
+#include "ProfHeap.h"
#include "Timer.h"
#include "Globals.h"
#include "FileLock.h"
@@ -300,7 +301,10 @@ hs_init_ghc(int *argc, char **argv[], RtsConfig rts_config)
initThreadLabelTable();
#endif
+#if defined(PROFILING)
initProfiling();
+#endif
+ initHeapProfiling();
/* start the virtual timer 'subsystem'. */
initTimer();
@@ -469,8 +473,13 @@ hs_exit_(bool wait_foreign)
reportCCSProfiling();
#endif
+ endHeapProfiling();
+ freeHeapProfiling();
+
+#if defined(PROFILING)
endProfiling();
freeProfiling();
+#endif
#if defined(PROFILING)
// Originally, this was in report_ccs_profiling(). Now, retainer