Proftimer.c 1.5 KB
Newer Older
1 2
/* -----------------------------------------------------------------------------
 *
3
 * (c) The GHC Team, 1998-1999
4 5 6 7 8 9 10
 *
 * Profiling interval timer
 *
 * ---------------------------------------------------------------------------*/

#if defined (PROFILING)

11
#include "PosixSource.h"
12

13
#include "Rts.h"
14
#include "Profiling.h"
sof's avatar
sof committed
15
#include "Timer.h"
16
#include "Proftimer.h"
17 18 19 20
#include "RtsFlags.h"

static rtsBool do_prof_ticks = rtsFalse;       // enable profiling ticks
static rtsBool do_heap_prof_ticks = rtsFalse;  // enable heap profiling ticks
21

22 23 24 25 26
// Number of ticks until next heap census
static int ticks_to_heap_profile;

// Time for a heap profile on the next context switch
rtsBool performHeapProfile;
27 28

void
29 30
stopProfTimer( void )
{
31
    do_prof_ticks = rtsFalse;
32
}
33 34

void
35 36
startProfTimer( void )
{
37
    do_prof_ticks = rtsTrue;
38 39 40 41 42 43 44 45 46 47 48
}

void
stopHeapProfTimer( void )
{
    do_heap_prof_ticks = rtsFalse;
}

void
startHeapProfTimer( void )
{
49 50
    if (RtsFlags.ProfFlags.doHeapProfile && 
	RtsFlags.ProfFlags.profileIntervalTicks > 0) {
51 52 53 54 55 56 57 58 59 60 61 62 63
	do_heap_prof_ticks = rtsTrue;
    }
}

void
initProfTimer( void )
{
    performHeapProfile = rtsFalse;

    ticks_to_heap_profile = RtsFlags.ProfFlags.profileIntervalTicks;

    startHeapProfTimer();
}
64

65

66 67 68 69
void
handleProfTick(void)
{
    if (do_prof_ticks) {
70
	CCCS->time_ticks++;
71
    }
72 73 74 75 76 77 78 79

    if (do_heap_prof_ticks) {
	ticks_to_heap_profile--;
	if (ticks_to_heap_profile <= 0) {
	    ticks_to_heap_profile = RtsFlags.ProfFlags.profileIntervalTicks;
	    performHeapProfile = rtsTrue;
	}
    }
80
}
81

82
#endif /* PROFILING */