Man page - sprof(1)
Packages contas this manual
- pts(4)
- initrd(4)
- bootparam(7)
- proc_driver(5)
- udp(7)
- proc_pid_numa_maps(5)
- standards(7)
- epoll(7)
- proc(5)
- proc_net(5)
- urandom(4)
- proc_pid_fdinfo(5)
- mailaddr(7)
- iso-8859-5(7)
- iso_8859-6(7)
- iconv(1)
- full(4)
- user-keyring(7)
- intro(5)
- ftm(7)
- shm_overview(7)
- feature_test_macros(7)
- proc_crypto(5)
- tzfile(5)
- aio(7)
- boot(7)
- proc_profile(5)
- proc_cgroups(5)
- cpuset(7)
- proc_pid_coredump_filter(5)
- proc_pid_cwd(5)
- proc_uptime(5)
- st(4)
- precedence(7)
- ddp(7)
- proc_zoneinfo(5)
- iso_8859_3(7)
- proc_pid_root(5)
- latin4(7)
- proc_tid_children(5)
- proc_pid_oom_adj(5)
- proc_mounts(5)
- iso_8859-14(7)
- ld-linux(8)
- capabilities(7)
- ptmx(4)
- mouse(4)
- sysfs(5)
- rtld-audit(7)
- proc_partitions(5)
- iso_8859_6(7)
- queue(7)
- proc_pid_pagemap(5)
- proc_pid_stack(5)
- proc_pid_mem(5)
- uri(7)
- ttytype(5)
- namespaces(7)
- proc_sys_user(5)
- latin5(7)
- procfs(5)
- charmap(5)
- proc_sys_kernel(5)
- getent(1)
- ip(7)
- iso_8859-5(7)
- queue(3)
- proc_sys_vm(5)
- random(7)
- iso-8859-10(7)
- process-keyring(7)
- protocols(5)
- system_data_types(7)
- operator(7)
- proc_pid_timerslack_ns(5)
- wtmp(5)
- iso_8859_15(7)
- cp1252(7)
- iso_8859_11(7)
- pkeys(7)
- kmem(4)
- proc_pid_clear_refs(5)
- proc_meminfo(5)
- latin8(7)
- zdump(8)
- fuse(4)
- utf-8(7)
- proc_kpagecount(5)
- futex(7)
- complex(7)
- iso_8859-13(7)
- proc_kcore(5)
- iso_8859-8(7)
- iso_8859_14(7)
- iconvconfig(8)
- network_namespaces(7)
- thread-keyring(7)
- locale(5)
- proc_pid_oom_score_adj(5)
- proc_pid_statm(5)
- signal-safety(7)
- units(7)
- re_format(7)
- proc_pid_comm(5)
- latin1(7)
- glibc(7)
- environ(7)
- iso_8859-9(7)
- tty(4)
- proc_pid_projid_map(5)
- urn(7)
- iso_8859_8(7)
- proc_loadavg(5)
- ipc_namespaces(7)
- proc_pid_syscall(5)
- proc_pid_cgroup(5)
- proc_pid_mountstats(5)
- proc_kpageflags(5)
- utmpx(5)
- termio(7)
- iso-8859-13(7)
- suffixes(7)
- iso_8859-16(7)
- intro(1)
- hostname(7)
- proc_pid_status(5)
- proc_pid_fd(5)
- proc_malloc(5)
- proc_sys_debug(5)
- proc_pid_mounts(5)
- console_codes(4)
- iso_8859_2(7)
- iso-8859-16(7)
- proc_thread-self(5)
- socket(7)
- sock_diag(7)
- null(4)
- raw(7)
- memusagestat(1)
- proc_pid_mountinfo(5)
- proc_sys_sunrpc(5)
- iso-8859-1(7)
- motd(5)
- iso_8859-7(7)
- utmp(5)
- proc_pid_auxv(5)
- latin2(7)
- intro(2)
- proc_modules(5)
- user_namespaces(7)
- iso-8859-2(7)
- proc_version(5)
- ldd(1)
- iso_8859-3(7)
- proc_diskstats(5)
- session-keyring(7)
- ascii(7)
- hosts.equiv(5)
- group(5)
- intro(4)
- proc_cmdline(5)
- resolver(5)
- time(7)
- packet(7)
- proc_kpagecgroup(5)
- hosts(5)
- proc_pid_maps(5)
- proc_tty(5)
- inotify(7)
- msr(4)
- tzselect(8)
- proc_locks(5)
- hpsa(4)
- mount_namespaces(7)
- cgroups(7)
- fanotify(7)
- latin7(7)
- intro(6)
- proc_slabinfo(5)
- proc_timer_list(5)
- proc_kallsyms(5)
- mq_overview(7)
- proc_buddyinfo(5)
- iso_8859-15(7)
- proc_pid_wchan(5)
- iso-8859-8(7)
- proc_stat(5)
- attributes(7)
- proc_bus(5)
- sln(8)
- iso_8859_4(7)
- cgroup_namespaces(7)
- symlink(7)
- fifo(7)
- proc_keys(5)
- locale(1)
- proc_devices(5)
- inode(7)
- iso_8859_13(7)
- nptl(7)
- svipc(7)
- proc_sys_proc(5)
- xattr(7)
- proc_key-users(5)
- iso_8859_10(7)
- erofs(5)
- sd(4)
- proc_ide(5)
- proc_dma(5)
- proc_pid_environ(5)
- utf8(7)
- proc_pid_seccomp(5)
- tcp(7)
- localedef(1)
- path_resolution(7)
- proc_kmsg(5)
- regex(7)
- unix(7)
- netdevice(7)
- host.conf(5)
- nss(5)
- proc_pid_io(5)
- issue(5)
- iso_8859-10(7)
- pipe(7)
- nologin(5)
- vcs(4)
- proc_mtrr(5)
- networks(5)
- resolv.conf(5)
- pldd(1)
- koi8-r(7)
- arp(7)
- ld.so(8)
- wavelan(4)
- proc_pid_uid_map(5)
- zero(4)
- iso-8859-7(7)
- memusage(1)
- iso-8859-6(7)
- latin6(7)
- user-session-keyring(7)
- armscii-8(7)
- shells(5)
- cp1251(7)
- rtnetlink(7)
- koi8-u(7)
- address_families(7)
- cpuid(4)
- core(5)
- pty(7)
- tis-620(7)
- iso_8859-1(7)
- math_error(7)
- iso_8859-4(7)
- proc_pid_autogroup(5)
- man(7)
- cciss(4)
- icmp(7)
- sprof(1)
- glob(7)
- iso-8859-9(7)
- proc_sys_dev(5)
- url(7)
- zic(8)
- sched(7)
- services(5)
- proc_pid(5)
- securetty(5)
- acct(5)
- loop(4)
- vcsa(4)
- iso_8859-2(7)
- proc_vmstat(5)
- pthreads(7)
- proc_timer_stats(5)
- uts_namespaces(7)
- elf(5)
- libc(7)
- proc_sysrq-trigger(5)
- credentials(7)
- proc_sys_net(5)
- numa(7)
- bpf-helpers(7)
- netlink(7)
- proc_pid_personality(5)
- iso_8859-11(7)
- mem(4)
- proc_apm(5)
- proc_pid_task(5)
- proc_cpuinfo(5)
- iso_8859_7(7)
- random(4)
- proc_sys_fs(5)
- proc_pid_ns(5)
- proc_filesystems(5)
- slabinfo(5)
- proc_sys_abi(5)
- latin9(7)
- proc_pid_stat(5)
- proc_execdomains(5)
- proc_swaps(5)
- keyrings(7)
- proc_ioports(5)
- iso_8859_1(7)
- hd(4)
- proc_self(5)
- landlock(7)
- proc_interrupts(5)
- port(4)
- proc_pid_cpuset(5)
- vdso(7)
- iso_8859_5(7)
- intro(7)
- mtrace(1)
- latin3(7)
- proc_sys(5)
- repertoiremap(5)
- lirc(4)
- filesystems(5)
- proc_ksyms(5)
- unicode(7)
- iso_8859_9(7)
- man-pages(7)
- pid_namespaces(7)
- proc_pid_attr(5)
- proc_sysvipc(5)
- intro(3)
- spufs(7)
- proc_config.gz(5)
- sem_overview(7)
- ldconfig(8)
- loop-control(4)
- iso-8859-4(7)
- proc_pid_timers(5)
- smartpqi(4)
- posixoptions(7)
- nsswitch.conf(5)
- proc_pid_map_files(5)
- time_namespaces(7)
- string_copying(7)
- iso-8859-11(7)
- proc_pid_gid_map(5)
- latin10(7)
- proc_pid_setgroups(5)
- ld-linux.so(8)
- ram(4)
- iso-8859-3(7)
- intro(8)
- proc_fb(5)
- vsock(7)
- termcap(5)
- fs(5)
- proc_iomem(5)
- iso-8859-15(7)
- signal(7)
- persistent-keyring(7)
- rtc(4)
- dsp56k(4)
- proc_pid_net(5)
- rpc(5)
- lp(4)
- veth(4)
- hier(7)
- kernel_lockdown(7)
- iso-8859-14(7)
- dir_colors(5)
- proc_scsi(5)
- proc_pid_cmdline(5)
- proc_fs(5)
- x25(7)
- proc_tid(5)
- proc_pid_smaps(5)
- proc_pid_limits(5)
- proc_pid_oom_score(5)
- locale(7)
- proc_pci(5)
- charsets(7)
- iso_8859_16(7)
- ipv6(7)
- tmpfs(5)
- proc_pid_exe(5)
- sysvipc(7)
- udplite(7)
- gai.conf(5)
apt-get install manpages
Available languages:
en fr da ja ru ro deManual
| sprof(1) | General Commands Manual | sprof(1) |
NAME
sprof - read and display shared object profiling data
SYNOPSIS
sprof [option]... shared-object-path [profile-data-path]
DESCRIPTION
The sprof command displays a profiling summary for the 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 command-line argument. If the profiling data pathname is omitted, then sprof will attempt to deduce it using the soname of the shared object, looking for a file with the name <soname>.profile in the current directory.
OPTIONS
The following command-line options specify the profile output to be produced:
- --call-pairs
- -c
- 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.
- --flat-profile
- -p
- Generate a flat profile of all of the functions in the monitored object, with counts and ticks.
- --graph
- -q
- Generate a call graph.
If none of the above options is specified, then the default behavior is to display a flat profile and a call graph.
The following additional command-line options are available:
STANDARDS
GNU.
EXAMPLES
The following example demonstrates the use of sprof. The example consists of a main program that calls two functions in a shared object. First, the code of the main program:
$ cat prog.c
#include <stdlib.h>
void x1(void);
void x2(void);
int
main(int argc, char *argv[])
{
x1();
x2();
exit(EXIT_SUCCESS);
}
The functions x1() and x2() are defined in the following source file that is used to construct the shared object:
$ cat libdemo.c
#include <unistd.h>
void
consumeCpu1(int lim)
{
for (unsigned int j = 0; j < lim; j++)
getppid();
}
void
x1(void) {
for (unsigned int j = 0; j < 100; j++)
consumeCpu1(200000);
}
void
consumeCpu2(int lim)
{
for (unsigned int j = 0; j < lim; j++)
getppid();
}
void
x2(void)
{
for (unsigned int j = 0; j < 1000; j++)
consumeCpu2(10000);
}
Now we construct the shared object with the real name libdemo.so.1.0.1, and the soname libdemo.so.1:
$ cc -g -fPIC -shared -Wl,-soname,libdemo.so.1 \
-o libdemo.so.1.0.1 libdemo.c
Then we construct symbolic links for the library soname and the library linker name:
$ ln -sf libdemo.so.1.0.1 libdemo.so.1 $ ln -sf libdemo.so.1 libdemo.so
Next, we compile the main program, linking it against the shared object, and then list the dynamic dependencies of the program:
$ cc -g -o prog prog.c -L. -ldemo $ ldd prog linux-vdso.so.1 => (0x00007fff86d66000) libdemo.so.1 => not found libc.so.6 => /lib64/libc.so.6 (0x00007fd4dc138000) /lib64/ld-linux-x86-64.so.2 (0x00007fd4dc51f000)
In order to get profiling information for the shared object, we define the environment variable LD_PROFILE with the soname of the library:
$ export LD_PROFILE=libdemo.so.1
We then define the environment variable LD_PROFILE_OUTPUT with the pathname of the directory where profile output should be written, and create that directory if it does not exist already:
$ export LD_PROFILE_OUTPUT=$(pwd)/prof_data $ mkdir -p $LD_PROFILE_OUTPUT
LD_PROFILE causes profiling output to be appended to the output file if it already exists, so we ensure that there is no preexisting profiling data:
$ rm -f $LD_PROFILE_OUTPUT/$LD_PROFILE.profile
We then run the program to produce the profiling output, which is written to a file in the directory specified in LD_PROFILE_OUTPUT:
$ LD_LIBRARY_PATH=. ./prog $ ls prof_data libdemo.so.1.profile
We then use the sprof -p option to generate a flat profile with counts and ticks:
$ sprof -p libdemo.so.1 $LD_PROFILE_OUTPUT/libdemo.so.1.profile Flat profile: Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls us/call us/call name
60.00 0.06 0.06 100 600.00 consumeCpu1
40.00 0.10 0.04 1000 40.00 consumeCpu2
0.00 0.10 0.00 1 0.00 x1
0.00 0.10 0.00 1 0.00 x2
The sprof -q option generates a call graph:
$ sprof -q libdemo.so.1 $LD_PROFILE_OUTPUT/libdemo.so.1.profile index % time self children called name
0.00 0.00 100/100 x1 [1] [0] 100.0 0.00 0.00 100 consumeCpu1 [0] -----------------------------------------------
0.00 0.00 1/1 <UNKNOWN> [1] 0.0 0.00 0.00 1 x1 [1]
0.00 0.00 100/100 consumeCpu1 [0] -----------------------------------------------
0.00 0.00 1000/1000 x2 [3] [2] 0.0 0.00 0.00 1000 consumeCpu2 [2] -----------------------------------------------
0.00 0.00 1/1 <UNKNOWN> [3] 0.0 0.00 0.00 1 x2 [3]
0.00 0.00 1000/1000 consumeCpu2 [2] -----------------------------------------------
Above and below, the "<UNKNOWN>" strings represent identifiers that are outside of the profiled object (in this example, these are instances of main()).
The sprof -c option generates a list of call pairs and the number of their occurrences:
$ sprof -c libdemo.so.1 $LD_PROFILE_OUTPUT/libdemo.so.1.profile <UNKNOWN> x1 1 x1 consumeCpu1 100 <UNKNOWN> x2 1 x2 consumeCpu2 1000
SEE ALSO
gprof(1), ldd(1), ld.so(8)
| 2024-06-15 | Linux man-pages 6.9.1 |