Information Technology Reference
In-Depth Information
Box 7. continued
decrementAC(3);
if(getValue(ac) <= 0)
setValue(ac, processSample(mids, sp));
if(from > to) {
decrementAC(2);
if(getValue(ac) <= 0)
setValue(ac, processSample(mids, sp));
return result;
}
decrementAC(7);
if(getValue(ac) <= 0)
setValue(ac, processSample(mids, sp));
result += f(from, ac, mids, sp );
++from;
}
}
static int sum(int from, int to) {
Thread t = Thread.currentThread();
return sum(from, to, ac, new MID[STACKSIZE], 0);
}
}
Although the VM and profiling agent provide
the monitoring infrastructure, profiler develop-
ers are responsible for certain tasks, such as
synchronization. For example, multithreaded
applications can spawn multiple instances of the
same event simultaneously, which will invoke the
same callback method on the same instance of
the profiling agent. Callbacks must therefore be
made reentrant via synchronization mechanisms,
such as mutexes, to avoid compromising profiler
internal state.
The Microsoft Common Language Runtime
(CLR) profiler and the Java Virtual Machine
Tool Interface (JVMTI) are two examples of
VM profilers that that support VM hooks, as
described below.
provided in the form of a pluggable dynamic
link library, written in a native language like C
or C++. The plug-in module, termed the agent,
accesses profiling services of the CLR via the
(ICorProfilerInfo2). interface. The agent must
also implement the ICorProfilerCallback2
interface so the CLR can call the agent back to
indicate the occurrence of events in the context
of the profiled application.
At startup, the CLR initializes the agent and
sets the events of interest. When an event occurs,
the CLR calls the corresponding method on the
ICorProfilerCallback2 interface. The
agent can then inspect the execution state of the
application by calling methods back on the CLR
( (ICorProfilerInfo2). ).
Figure 11 shows the series of communications
triggered by each function entered in the CLR
execution. In this example, in between processing
function enter/exit call-backs, the profiling agent
requests a stack snapshot so it can identify the
CLR Profiler
The CLR Profiler (Hilyard, 2005) interface allows
the integration of custom profiling functionality
 
Search WWH ::




Custom Search