Commit 373c9cb3 authored by Daniel Gröber (dxld)'s avatar Daniel Gröber (dxld) Committed by Marge Bot

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.
parent db948dae
......@@ -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
......
......@@ -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)
......
......@@ -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();
}
}
/* -----------------------------------------------------------------------------
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment