← 返回命令列表

Linux command

sprof 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Set up profiling

LD_PROFILE=[libfoo.so.1] LD_PROFILE_OUTPUT=[/tmp/prof] [./myprogram]

Display flat profile and call graph

sprof [libfoo.so.1] [libfoo.so.1.profile]

Display only the flat profile

sprof -p [libfoo.so.1] [libfoo.so.1.profile]

Display only the call graph

sprof -q [libfoo.so.1] [libfoo.so.1.profile]

Display call pairs

sprof -c [libfoo.so.1] [libfoo.so.1.profile]

说明

sprof displays a profiling summary for a shared object (shared library) specified as its first command-line argument. The profiling summary is created using previously generated profiling data in the optional second argument. If the profiling data path is omitted, sprof looks for a file named \<soname\>.profile in the current directory. Profiling data is generated by setting the LD_PROFILE environment variable to the soname of the shared library and optionally LD_PROFILE_OUTPUT to a directory for the profile data file. Running any application that loads the library then causes the dynamic linker to collect profiling data automatically. If none of -c, -p, or -q is specified, the default behavior is to display both a flat profile and a call graph.

参数

-c, --call-pairs
Print a list of pairs of call paths for the interfaces exported by the shared object, along with the number of times each path is used.
-p, --flat-profile
Generate a flat profile of all of the functions in the monitored object, with counts and ticks.
-q, --graph
Generate a call graph.
-?, --help
Display a summary of command-line options and arguments and exit.
--usage
Display a short usage message and exit.
-V, --version
Display the program version and exit.

FAQ

What is the sprof command used for?

sprof displays a profiling summary for a shared object (shared library) specified as its first command-line argument. The profiling summary is created using previously generated profiling data in the optional second argument. If the profiling data path is omitted, sprof looks for a file named \<soname\>.profile in the current directory. Profiling data is generated by setting the LD_PROFILE environment variable to the soname of the shared library and optionally LD_PROFILE_OUTPUT to a directory for the profile data file. Running any application that loads the library then causes the dynamic linker to collect profiling data automatically. If none of -c, -p, or -q is specified, the default behavior is to display both a flat profile and a call graph.

How do I run a basic sprof example?

Run `LD_PROFILE=[libfoo.so.1] LD_PROFILE_OUTPUT=[/tmp/prof] [./myprogram]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -c, --call-pairs do in sprof?

Print a list of pairs of call paths for the interfaces exported by the shared object, along with the number of times each path is used.