HookIt provides an implementation for the Microsoft Visual C++ _penter() and _pexit() instrumentation functions.
_penter(), if enabled via the /Gh compiler switch, is called on every function entry before the prologue code is executed. _pexit(), if enabled via the /GH compiler switch, is called on every exit (return) from a function, after the epilogue code is executed but before the return. The _penter/_pexit() implementation is provided in hookit.lib, which contains hookit.obj, and is used at link time to resolve _penter/_pexit().
HookIt calls into JProf on every function entry/exit.
Loader
|
+----> main(argc, argv)
call _penter ----> if (first_time) {initialize};
<---+ send event to jprof;
+-------
push ebp
mov ebp, esp
*
*
*
push arg2
push arg1
call function(arg1, arg2) ---+
|
+-> function()
<--------+ call _penter ---> send event to jprof;
add esp, 8 | <----------
* | push ebp
* | mov ebp,esp
* | *
* | *
* | *
* | call _pexit ---> send event to jprof;
* | <----------
* +----------------- ret
*
*
call _pexit ----> send event to profiler
<----------
<-------- ret
add esp, 8
process termination
blah
blah
The following flags are optional:
Only one command needed to build a simple, instrumented application. For larger applications you will have to modify your makefile accordingly. The application is comprised of a C source file named foo.c. hookit.lib is located in the C:\ibmperf\lib directory.
The command compiles and links foo.exe and produces debug symbols in foo.pdb. The symbols are required if you want to see function names in the JProf reports.
Assuming jprof.dll and a2n.dll reside in directory C:\ibmperf\bin, the commands required are:
After setting the PATH and JPROFOPTS just run your application (.exe).
Hookit can be configured to use other profiler libraries (besides JProf) by setting the HOOKIT_PROFILER environment variable. Similarly the HOOKIT_DEBUG environment variable may be used to display debug output from Hookit. In some cases the HOOKIT_PROFILING variable may be used to enable or disable profiling. However this is often overridden by the profiler itself.