MODULE HierarchicalProfiler0;
IMPORT
SYSTEM, Machine, Objects, Modules, Kernel;
CONST
HandlerNotInstalled = 0;
HandlerInstalled = 1;
WaitTime = 100;
TYPE
Callback = PROCEDURE (id : LONGINT; process : Objects.Process; pc, bp, lowAdr, highAdr : SYSTEM.ADDRESS);
VAR
callback : Callback;
state : LONGINT;
PROCEDURE HandleTimer(id: LONGINT; CONST state: Machine.State);
VAR process : Objects.Process;
BEGIN
process := Objects.running[id];
callback(id, process, state.PC, state.BP, state.SP, SHORT(0FFFFFFFFH));
END HandleTimer;
PROCEDURE Enable*(proc : Callback);
BEGIN {EXCLUSIVE}
ASSERT(proc # NIL);
ASSERT(state = HandlerNotInstalled);
Machine.InstallEventHandler(HandleTimer);
state := HandlerInstalled;
END Enable;
PROCEDURE Disable*;
VAR timer : Kernel.Timer;
BEGIN {EXCLUSIVE}
ASSERT(state = HandlerInstalled);
Machine.InstallEventHandler(NIL);
NEW(timer); timer.Sleep(WaitTime);
END Disable;
PROCEDURE Cleanup;
BEGIN
Machine.InstallEventHandler(NIL);
END Cleanup;
BEGIN
callback := NIL;
state := HandlerNotInstalled;
Modules.InstallTermHandler(Cleanup);
END HierarchicalProfiler0.