A Real-time Performance Visualizer for Java.
by John Whaley and John J. Barton

Listing One
void CALLBACK
JavaProfiler::Callback  (
                UINT uID=0,     // identifier of the timer event
                UINT uMsg=0,    // reserved
                DWORD dwUser=0, // user instance data
                DWORD dw1=0,    // reserved
                DWORD dw2=0)    // reserved
{
        // create context object
        CONTEXT context;
        context.ContextFlags = CONTEXT_CONTROL;
        // get the control registers of the worker thread
        HANDLE worker = TaskManager._workerThreadHandle;
        assert(worker);
        GetThreadContext(worker, &context);
        // store the PC
        JavaProf.add((INTEL_OP *)context.Eip);
}


Listing Two
void JavaProfiler::start()
  if (!_procID) { // if we haven't already started ...
    // find the maximum precision of the timer device
    TIMECAPS time; timeGetDevCaps(&time, sizeof(time));
    // start the quick timer tick profiler
    _procID = timeSetEvent (max(_period,time.wPeriodMin), // delay in ms
                           0,    // resolution (higher -> less overhead)
                           &Callback, // callback function
                           0,    // user-supplied callback data
                           TIME_PERIODIC);
  }
}


1


