sprof(1) General Commands Manual sprof(1) (NAME) sprof - (SYNOPSIS) sprof []... shared-object-path [profile-data-path] (DESCRIPTION) sprof ( ) . () . sprof soname .profile . (OPTIONS) : --call-pairs -c . --flat-profile -p (Flat profile) . --graph -q (Call graph). . : --help -? . --usage . --version -V . (STANDARDS) (GNU). (EXAMPLES) sprof . . : $ cat prog.c #include void x1(void); void x2(void); int main(int argc, char *argv[]) { x1(); x2(); exit(EXIT_SUCCESS); } x1() x2() : $ cat libdemo.c #include 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); } libdemo.so.1.0.1 soname libdemo.so.1 : $ cc -g -fPIC -shared -Wl,-soname,libdemo.so.1 \ -o libdemo.so.1.0.1 libdemo.c soname : $ ln -sf libdemo.so.1.0.1 libdemo.so.1 $ ln -sf libdemo.so.1 libdemo.so : $ 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) LD_PROFILE soname : $ export LD_PROFILE=libdemo.so.1 LD_PROFILE_OUTPUT : $ export LD_PROFILE_OUTPUT=$(pwd)/prof_data $ mkdir -p $LD_PROFILE_OUTPUT LD_PROFILE (append) : $ rm -f $LD_PROFILE_OUTPUT/$LD_PROFILE.profile LD_PROFILE_OUTPUT : $ LD_LIBRARY_PATH=. ./prog $ ls prof_data libdemo.so.1.profile sprof -p : $ 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 sprof -q : $ 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 [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 [3] 0.0 0.00 0.00 1 x2 [3] 0.00 0.00 1000/1000 consumeCpu2 [2] ----------------------------------------------- "" ( main() ). sprof -c : $ sprof -c libdemo.so.1 $LD_PROFILE_OUTPUT/libdemo.so.1.profile x1 1 x1 consumeCpu1 100 x2 1 x2 consumeCpu2 1000 (SEE ALSO) gprof(1), ldd(1), ld.so(8) Linux man-pages 6.9.1 2024-06-15 sprof(1)