1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-23 06:00:41 -08:00

Mps br/timing: mps_alert_collection_set() -- client sets a callback

function; MPS calls it synchronously on collection start/stop 
(immediately after posting start/stop message).  The callback 
receives two ints: alertcode (start|stop; see mps.h), and whycode 
(trace->why).  Note: callback is also called for heap walk 
start/stop.
amcss.c: show start/stop alerts.

Copied from Perforce
 Change: 166703
 ServerID: perforce.ravenbrook.com
This commit is contained in:
Richard Kistruck 2008-11-12 15:07:04 +00:00
parent 08fb5a0526
commit a563a76204
6 changed files with 61 additions and 1 deletions

View file

@ -47,7 +47,27 @@ static mps_addr_t exactRoots[exactRootsCOUNT];
static mps_addr_t ambigRoots[ambigRootsCOUNT];
/* report - report statistics from any messages */
/* alert -- synchronous alert of collection start/stop */
static void alertfn(int alertcode, int whycode)
{
switch(alertcode) {
case MPS_ALERT_COLLECTION_START: {
printf("\n^^^^^^ START (why: %d) ^^^^^^\n", whycode);
break;
}
case MPS_ALERT_COLLECTION_STOP: {
printf("vvvvvv STOP (why: %d) vvvvvv\n", whycode);
break;
}
default: {
cdie(0, "unknown alertcode");
break;
}
}
}
/* report -- report statistics from any messages */
static void report(mps_arena_t arena)
{
@ -313,6 +333,7 @@ int main(int argc, char **argv)
"arena_create");
mps_message_type_enable(arena, mps_message_type_gc());
mps_message_type_enable(arena, mps_message_type_gc_start());
mps_alert_collection_set(arena, &alertfn);
die(mps_arena_commit_limit_set(arena, testArenaSIZE), "set limit");
die(mps_thread_reg(&thread, arena), "thread_reg");
mps_tramp(&r, test, arena, 0);

View file

@ -136,6 +136,8 @@ Bool ArenaCheck(Arena arena)
CHECKL(LocusCheck(arena));
/* nothing to check for alertCollection */
return TRUE;
}
@ -177,6 +179,8 @@ Res ArenaInit(Arena arena, ArenaClass class)
LocusInit(arena);
arena->alertCollection = 0;
res = GlobalsInit(ArenaGlobals(arena));
if (res != ResOK)
goto failGlobalsInit;

View file

@ -688,6 +688,9 @@ typedef struct ArenaStruct {
Bool isFinalPool; /* indicator for finalPool */
Pool finalPool; /* either NULL or an MRG pool */
/* alert fields <code/trace.c> */
mps_alert_collection_fn_t alertCollection; /* client alert fn or 0 */
/* thread fields (<code/thread.c>) */
RingStruct threadRing; /* ring of attached threads */
Serial threadSerial; /* serial of next thread */

View file

@ -550,6 +550,18 @@ extern mps_res_t mps_finalize(mps_arena_t, mps_addr_t *);
extern mps_res_t mps_definalize(mps_arena_t, mps_addr_t *);
/* Alert */
/* Alert codes. */
enum {
MPS_ALERT_COLLECTION_START,
MPS_ALERT_COLLECTION_STOP
};
typedef void (*mps_alert_collection_fn_t)(int, int);
extern mps_res_t mps_alert_collection_set(mps_arena_t,
mps_alert_collection_fn_t);
/* Telemetry */
extern mps_word_t mps_telemetry_control(mps_word_t, mps_word_t);

View file

@ -1799,6 +1799,20 @@ const char *mps_message_gc_start_why(mps_arena_t mps_arena,
return s;
}
/* Alert */
mps_res_t mps_alert_collection_set(mps_arena_t mps_arena,
mps_alert_collection_fn_t fn)
{
Arena arena = (Arena)mps_arena;
ArenaEnter(arena);
arena->alertCollection = fn;
ArenaLeave(arena);
return MPS_RES_OK;
}
/* Telemetry */
mps_word_t mps_telemetry_control(mps_word_t resetMask, mps_word_t flipMask)

View file

@ -1056,6 +1056,9 @@ static void tracePostMessage(Trace trace)
message->notCondemnedSize = trace->notCondemned;
MessagePost(arena, TraceMessageMessage(message));
}
if(arena->alertCollection) {
(*arena->alertCollection)(MPS_ALERT_COLLECTION_STOP, trace->why);
}
return;
}
@ -1859,6 +1862,9 @@ void TraceStart(Trace trace, double mortality, double finishingTime)
if(!MessageOnQueue(message)) {
MessagePost(arena, message);
}
if(arena->alertCollection) {
(*arena->alertCollection)(MPS_ALERT_COLLECTION_START, trace->why);
}
/* From the already set up white set, derive a grey set. */