profiling (computer programming) program execution general concepts code translation compiler compiletime optimizing compiler intermediate representation ir execution runtime system runtime executable interpreter virtual machine types of code source code object code bytecode machine code microcode compilation strategies justintime jit tracing justintime aheadoftime aot transcompilation recompilation notable runtimes android runtime art common language runtime clr mono crt0 hhvm java virtual machine jvm objectivec v8 nodejs pypy zend engine notable compilers toolchains gnu compiler collection gcc llvm clang vte in software engineering profiling program profiling software profiling is a form of dynamic program analysis that measures for example the space memory or time complexity of a program the usage of particular instructions or the frequency and duration of function calls most commonly profiling information serves to aid program optimization profiling is achieved by instrumenting either the program source code or its binary executable form using a tool called a profiler or code profiler profilers may use a number of different techniques such as eventbased statistical instrumented and simulation methods gathering program events profilers use a wide variety of techniques to collect data including hardware interrupts code instrumentation instruction set simulation operating system hooks and performance counters profilers are used in the performance engineering process use of profilers graphical output of the codeanalyst profiler mwparseroutput templatequoteoverflowhiddenmargin1em 0padding0 40pxmwparseroutput templatequote templatequotecitelineheight15emtextalignleftpaddingleft16emmargintop0 program analysis tools are extremely important for understanding program behavior computer architects need such tools to evaluate how well programs will perform on new architectures software writers need tools to analyze their programs and identify critical sections of code compiler writers often use such tools to find out how well their instruction scheduling or branch prediction algorithm is performingatom pldi 94 the output of a profiler may be a statistical summary of the events observed a profile summary profile information is often shown annotated against the source code statements where the events occur so the size of measurement data is linear to the code size of the program source count 0001 if x a 0055 0002 then do 0003 add 1 to xcount 0032 0004 else 0005 if x b 0055 a stream of recorded events a trace for sequential programs a summary profile is usually sufficient but performance problems in parallel programs waiting for messages or synchronization issues often depend on the time relationship of events thus requiring a full trace to get an understanding of what is happening the size of a full trace is linear to the programs instruction path length making it somewhat impractical a trace may therefore be initiated at one point in a program and terminated at another point to limit the output an ongoing interaction with the hypervisor continuous or periodic monitoring via onscreen display for instance this provides the opportunity to switch a trace on or off at any desired point during execution in addition to viewing ongoing metrics about the still executing program it also provides the opportunity to suspend asynchronous processes at critical points to examine interactions with other parallel processes in more detail a profiler can be applied to an individual method or at the scale of a module or program to identify performance bottlenecks by making longrunning code obvious history performanceanalysis tools existed on ibm360 and ibm370 platforms from the early 1970s usually based on timer interrupts which recorded the program status word psw at set timerintervals to detect hot spots in executing code profilerdriven program analysis on unix dates back to 1973 in 1994 amitabh srivastava and alan eustace of digital equipment corporation published a paper describing atomanalysis tools with om the atom platform converts a program into its own profiler at compile time it inserts code into the program to be analyzed that inserted code outputs analysis data this technique modifying a program to analyze itself is known as instrumentation in 2004 both the gprof and atom papers appeared on the list of the 50 most influential pldi papers for the 20year period ending in 1999 profiler types based on output flat profiler flat profilers compute the average call times from the calls and do not break down the call times based on the callee or the context callgraph profiler call graph profilers show the call times and frequencies of the functions and also the callchains involved based on the callee in some tools full context is not preserved inputsensitive profiler inputsensitive profilers add a further dimension to flat or callgraph profilers by relating performance measures to features of the input workloads such as input size or input values they generate charts that characterize how an applications performance scales as a function of its input data granularity in profiler types profilers which are also programs themselves analyze target programs by collecting information on their execution based on their data granularity on how profilers collect information they are classified into event based or statistical profilers profilers interrupt program execution to collect information which may result in a limited resolution in the time measurements which should be taken with a grain of salt basic block profilers report a number of machine clock cycles devoted to executing each line of code or a timing based on adding these together the timings reported per basic block may not reflect a difference between cache hits and misses eventbased profilers the programming languages listed here have eventbased profilers java the jvmti jvm tools interface api formerly jvmpi jvm profiling interface provides hooks to profilers for trapping events like calls classload unload thread enter leave net can attach a profiling agent as a com server to the clr using profiling api like java the runtime then provides various callbacks into the agent for trapping events like method jit enter leave object creation etc particularly powerful in that the profiling agent can rewrite the target applications bytecode in arbitrary ways python python profiling includes the profile module hotshot which is callgraph based and using the syssetprofile function to trap events like ccallreturnexception pythoncallreturnexception ruby ruby also uses a similar interface to python for profiling flatprofiler in profilerb module and rubyprof a cextension are present statistical profilers some profilers operate by sampling a sampling profiler probes the target programs call stack at regular intervals using operating system interrupts sampling profiles are typically less numerically accurate and specific but allow the target program to run at near full speed the resulting data are not exact but a statistical approximation the actual amount of error is usually more than one sampling period in fact if a value is n times the sampling period the expected error in it is the squareroot of n sampling periods in practice sampling profilers can often provide a more accurate picture of the target programs execution than other approaches as they are not as intrusive to the target program and thus dont have as many side effects such as on memory caches or instruction decoding pipelines also since they dont affect the execution speed as much they can detect issues that would otherwise be hidden they are also relatively immune to overevaluating the cost of small frequently called routines or tight loops they can show the relative amount of time spent in user mode versus interruptible kernel mode such as system call processing still kernel code to handle the interrupts entails a minor loss of cpu cycles diverted cache usage and is unable to distinguish the various tasks occurring in uninterruptible kernel code microsecondrange activity dedicated hardware can go beyond this arm cortexm3 and some recent mips processors jtag interface have a pcsample register which samples the program counter in a truly undetectable manner allowing nonintrusive collection of a flat profile some commonly used among others instrumentation this technique effectively adds instructions to the target program to collect the required information note that instrumenting a program can cause performance changes and may in some cases lead to inaccurate results andor heisenbugs the effect will depend on what information is being collected on the level of timing details reported and on whether basic block profiling is used in conjunction with instrumentation for example adding code to count every procedureroutine call will probably have less effect than counting how many times each statement is obeyed a few computers have special hardware to collect information in this case the impact on the program is minimal instrumentation is key to determining the level of control and amount of time resolution available to the profilers manual performed by the programmer eg by adding instructions to explicitly calculate runtimes simply count events or calls to measurement apis such as the application response measurement standard automatic source level instrumentation added to the source code by an automatic tool according to an instrumentation policy intermediate language instrumentation added to assembly or decompiled bytecodes giving support for multiple higherlevel source languages and avoiding nonsymbolic binary offset rewriting issues compiler assisted binary translation the tool adds instrumentation to a compiled executable runtime instrumentation directly before execution the code is instrumented the program run is fully supervised and controlled by the tool runtime injection more lightweight than runtime instrumentation code is modified at runtime to have jumps to helper functions interpreter instrumentation interpreter debug options can enable the collection of performance metrics as the interpreter encounters each target statement a bytecode control table or jit interpreters are three examples that usually have complete control over execution of the target code thus enabling extremely comprehensive data collection opportunities hypervisorsimulator hypervisor data are collected by running the usually unmodified program under a hypervisor example simmon simulator and hypervisor data collected interactively and selectively by running the unmodified program under an instruction set simulator software testing portal algorithmic efficiency benchmark java performance list of performance analysis tools papi is a portable interface in the form of a library to hardware performance counters on modern microprocessors performance engineering performance prediction performance tuning runtime verification profileguided optimization static code analysis software archaeology worstcase execution time wcet article need for speed eliminating performance bottlenecks on doing execution time analysis of java applications using ibm rational application developer profiling runtime generated and interpreted code using the vtune performance analyzer 