Dynamic Program Analysis
Profiling
Profiling as in “program profiling”, or “software profiling” is a form of dynamic program analysis that measures such things as memory space and time complexity of a program, the usage of particular instructions, or the frequency and duration of a function call. The tooling used to provide this functionality is frequently referred to as a profiler or code profiler. These tools instrument either the source code itself or the binary executable via a number of techniques such as event-based, statistical, instrumented, and or simulation methods.
Types of Profilers
- Timing
Timing profiling is generally achieved by using internal and external timing tools to time the execution of the code sections and as a whole. This could be done in a C program with time.h or std::chrono in C++ or some other such library. Timing is generally available in every programming language. Systems themselves have very granular CPU timing facilities that can be used such as sys/time.h in nix systems and QueryPerformanceCounter in Windows.
- CPU
CPU profiling is what most people mean when they say the term ‘profiler’ as this is generally what is most needed. There are two main methods used in CPU profiling: tracing and sampling. The tracing profilers keeps a record of every function call the program makes and sampling profilers probe the program periodically and record the state of the program’s stack.
- Memory
Memory profiling tools are used to analyze the state and usage of the program’s memory in order to discover memory leaks. A common tool used for memory profiling and debugging is Valgrind which is a generic framework for creating dynamic analysis tools such as profilers and checkers but was originally developed for memory debugging on Linux x86 platforms.
- Event
Event profiling involves the recording an analysis of events that occur during the runtime of a program. Tools such as ‘perf’ on Linux can record and report on things such as poor cache locality, high amounts of page faults or livelocks, as well as other such events related to the running of a program and the system