2.3. Instrumentation methods

Commonly, the target application must include some instrumentation to enable the profiling mechanisms to operate. Sometimes only preliminary start-up code needs to be added, and this is easily acheived via mechanisms such as LD_PRELOAD. Accounting profilers often need to add instrumentation at a fine-grained level, and there are a number of different techniques in use :

Simulation
A simulator can easily collect detailed data as part of the simulation run. Such techniques tend to be very obtrusive and slow, so are best used when the level of detail is critical.
Source-level instrumentation
Source-level instrumentation involves altering the source code that eventually becomes the application by inserting profiling code. This can happen semi-automatically via a pre-processor, or may require a programmer to add explicit calls to some profiling API.
Compile-time instrumentation
The compiler itself can be used to insert profiling code. This has the advantage above source-level instrumentation of being more convenient, but of course requires the source code to be recompiled, which is not always practicable.
Offline binary instrumentation
Binary images that contain the text sections for shared libraries or applications can be rewritten to add instrumentation. This technique is complex to implement, but is relatively unobtrusive unless system-wide performance data is needed.
Online binary instrumentation
Mapped binary images are rewritten to add instrumentation. To some degree, just-in-time compiling environments are in this class of techniques.