Reports CPU usage.
tprof [ -c ] [ -C { all | CPUList } ] [ -d ] -D ] [ -e ] [ -F ] [ -j ] [ -k ] [ -l ] [ -m ObjectsList ] [ -M SourcePathList ] [ -p ProcessList ] [ -P { all | PIDsList } ] [ -s ] [ -S SearchPathList ] [ -t ] [ -T BufferSize ] [ -u ] [ -v ] [ -V VerboseFileName ] [ -z ] { { -r RootString } | { [ -A { all | CPUList }] [ -r RootString ] -x Program } }
The tprof command reports CPU usage for individual programs and the system as a whole. This command is a useful tool for anyone with a JAVA, C, C++, or FORTRAN program that might be CPU-bound and who wants to know which sections of the program are most heavily using the CPU.
The tprof command can charge CPU time to object files, processes, threads, subroutines (user mode, kernel mode and shared library) and even to source lines of programs or individual instructions. Charging CPU time to subroutines is called profiling and charging CPU time to source program lines is called micro-profiling.
For subroutine-level profiling, the tprof command can be run without modifying executable programs, that is no recompilation with special compiler flags is necessary. This is still true if the executables have been stripped, unless the back tables have also been removed. However, recompilation is required to get a micro-profile, unless a listing file is already available. To perform micro-profiling on a program, either the program should be compiled with -g and the source files should be accessible to tprof or the program should be compiled with -qlist and either both the object listing files and the source files or just the object listing files should be accessible to tprof. To take full advantage of tprof micro-profiling capabilities, it is best to provide both the .lst and the source file.
tprof can run in the following four modes:
If the -x flag is specified but the -A flag is not specified, tprof runs in realtime mode. In realtime mode tprof starts the AIX trace utility in the background, and processes the trace data as it gets generated. When the program being profiled ends, tprof collects symbolic name information, and generates the reports.
If the -A flag is specified with the -x flag, tprof runs in automated offline mode. In this mode tprof starts the AIX trace utility and logs the trace data into a file. Once the trace data collection is done, it collect symbolic name information, and tprof opens the trace log file and processes the data to generate reports. In this mode tprof generates the following files in addition to tprof report files:
The tprof command can re-process these files any time to generate profiling reports. This is called manual offline mode. The RootString.syms file contains symbolic name information similar to the output of the gensyms command. The RootString.trc[-cpuid] file(s) are trace log file(s). The -cpuid is added to the names when per-CPU tracing is on. In that case, each file contains trace data from one CPU only.
Those files are cooked, that is they are a pre-processed version of the normal trace and name files. tprof post-processes cooked file much faster.
If neither -A flag nor -x are specified, tprof runs either in manual offline or in post-processing mode. For tprof to run in post-processing mode the following files must be available:
Those are generated when tprof runs (in any mode except post-processing mode) with the -c flag. For tprof to run in manual offline mode the following files must be available:
These files are generated by a user manually using the gensyms command and AIX trace facility or by running tprof in automated offline mode without the -c flag.
tprof generates a report file named RootString.prof which holds the process, thread, object file and subroutine level profiling report. The file can contains the following sections and subsections:
The summary report section is always present in the RootString.prof report file. Based on the profiling flags the various subsections of the global profile section can be turned on and off:
The process and thread level profile sections are created for processes and threads selected with the -p, -P and -t flags. The subsections present within each of the per-process of per-thread sections are identical to the subsections present in the global section, they are selected using the profiling flags (-u,-s,-k,-e,-j).
Optionally (when called with the -C flag) tprof also generates per-CPU profiling reports (one profiling report per CPU). The generated tprof reports have the same structure and are named using the convention: RootString.prof[-cpuid].
If -m is specified, tprof generates micro-profiling reports. The reports use the following naming convention: RootString.source.mprof, where source is the base name of a source file. If more than one source file has the same base name, then a number to uniquely identify them is appended to the report file name, for example, RootString.Filename.c.mprof-1. The micro-profiling report has the following information:
If a source file is not present, but a .lst file is present, tprof only shows the CPU usage based on the source lines and the instructions from the .lst file.
If neither files are present, but the source file was compiled with -g, tprof can retrieve the source line numbers and it generates a similar report, but with the source code column missing.
The degree to which CPU activity can be resolved is determined by the number of samples captured and the degree to which hot spots dominate. While a program with a few hot spots can be profiled with relatively few samples, less-frequently executed sections of the program are not visible in the profiling reports unless more samples are captured. In cases where user programs run less than a minute, there may be insufficient resolution to have a high degree of confidence in the estimates.
A simple solution is to repeatedly execute the user program or script until you achieve the degree of resolution you need. The longer a program is run, the finer the degree of resolution of the profile. If you doubt the accuracy of a profile, run the tprof command several times and compare the resulting profiles.
The most significant differences between these three commands is that tprof collects data with no impact on the execution time of the programs being profiled, and works on optimized and stripped binaries without any need for recompilation, except to generate micro-profiling reports. Neither gprof nor prof have micro-profiling capabilities or work on optimized or stripped binaries, while they do require special compilation flags, and induce a slowdown in the execution time that can be significant.
The prof and gprof tools are standard, supported profiling tools on many UNIX systems, including this operating system. Both prof and gprof provide subprogram profiling and exact counts of the number of times every subprogram is called. The gprof command also provides a very useful call graph showing the number of times each subprogram was called by a specific parent and the number of times each subprogram called a child. The tprof command provides neither subprogram call counts nor call graph information.
Like the tprof command, both the prof and gprof commands obtain their CPU consumption estimates for each subprogram by sampling the program counter of the user program.
tprof collects CPU usage information for the whole system, while prof and gprof collect only profiling information for a single program and only for the time spent in user mode.tprof also provides summary for all processes active during the execution of the profiled user program and fully support libraries and kernel mode profiling.
tprof support the profiling of JAVA applications, which prof and gprof do not.
$ tprof -x sleep 10 Mon May 20 00:39:26 2002 System: AIX 5.2 Node: dreaming Machine: 000671894C00 Starting Command sleep 10 stopping trace collection. Generating sleep.prof
The resulting sleep.prof file only contains the summary report section.
$ tprof -skeuj -x sleep 10 Mon May 20 00:39:26 2002 System: AIX 5.2 Node: drea ming Machine: 000671894C00 Starting Command sleep 10 stopping trace collection. Generating sleep.prof
The resulting sleep.prof file contains the summary report and global profile sections.
$ tprof -u -p workload -x workload Mon May 20 00:39:26 2002 System: AIX 5.2 Node: drea ming Machine: 000671894C00 Starting Command workload stopping trace collection. Generating workload.prof
The resulting workload.prof file contains the summary report and the global user mode profile sections, and one process level profile section for the process 'workload' that contains only a user mode profile subsection.
$ tprof -se -p send,receive -x startall Mon May 20 00:39:26 2002 System: AIX 5.2 Node: dreaming Machine: 000671894C00 Starting Command startall stopping trace collection. Generating startall.prof
The resulting startall.prof file contains the summary report, the global shared libary mode profile, and the global kernel extension profile sections, and two process level profile sections: one for the process 'send', and one for the process 'receive'. The process level sections each contain two subsections: one with shared libary profiling information and one with kernel extentions profiling information.
$ tprof -m ./tcalc -u -x ./tcalc Mon May 20 00:47:09 2002 System: AIX 5.2 Node: dreaming Machine: 000671894C00 Starting Command ./tcalc stopping trace collection. Generating tcalc.prof Generating tcalc.tcalc.c.mprof
The resulting tcalc.prof file contains the summary report and the global user mode profile sections. The resulting tcalc.tcalc.c.mprof file contains the micro-profiling report.
tprof -c -A all -x sleep 10 Starting Command sleep 10 stopping trace collection. Mon May 20 00:52:52 2002 System: AIX 5.2 Node: dreaming Machine: 000671894C00 Generating sleep.ctrc Generating sleep.csyms Generating sleep.prof
The resulting sleep.prof file only has a summary report section, while the two cooked files are ready to be re-postprocessed.
If your system displays the following message:
/dev/systrace: device busy or trcon: TRCON:no such device
This means the trace facility is already in use. Stop your program and try again after typing trcstop, stops the trace.
The gensyms command, gprof command, prof command, stripnm command, and trace daemon.