Home arrow FAQ arrow LTProf Frequently Asked Questions arrow Instrumentation vs Sampling
May 25, 2017 at 05:06 PM
Contact Us
Instrumentation vs Sampling


Instrumentation is the process of injecting code into each of the functions that need to be analyzed, typically all the functions in your program. This code queries the current time at the beginning of the function and again at the end, thus calculating the amount of time spent within the function. There are a number of disadvantages associated with this method:

  • The instrumentation itself is a lengthy process and it usually requires rebuilding your program to include the additional code.
  • Instrumented code is a lot slower, especially functions that are called very often. It is not uncommon that a time-consuming process becomes completely unusable after instrumentation.
  • It has a function-level resolution, which means it can tell which function took longer to execute but it cannot 'see' sequences of code inside a function.


In the sampling technique a separate process is running side-by-side with the profiled application and it 'peeks' at random times at its state. From this information it can determine which sequences of code were 'caught' executing more often.
This technique does not inject any code so it does not require the rebuild of the application: it can work on a regular debug build. Another advantage is that the profiled process will run at virtually the same speed as usually.
But maybe the best of all, it has a line-level resolution, which means that it can report the usage of each line of code. Displayed graphically, the line level information provides a very good visibility on the cost of various code constructs.

Copyright (C) 2002-2009 Lightweight Technologies LLC. All rights reserved. Read our Privacy Policy