{
    "mode": "man",
    "parameter": "sprof",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/sprof/1/json",
    "generated": "2026-06-16T03:25:05Z",
    "synopsis": "sprof [option]... shared-object-path [profile-data-path]",
    "sections": {
        "NAME": {
            "content": "sprof - read and display shared object profiling data\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "sprof [option]... shared-object-path [profile-data-path]\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The  sprof command displays a profiling summary for the shared object (shared library) speci‐\nfied as its first command-line argument.  The profiling summary is created  using  previously\ngenerated  profiling  data  in the (optional) second command-line argument.  If the profiling\ndata pathname is omitted, then sprof will attempt to deduce it using the soname of the shared\nobject, looking for a file with the name <soname>.profile in the current directory.\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "The following command-line options specify the profile output to be produced:\n",
            "subsections": [
                {
                    "name": "-c --call-pairs",
                    "content": "Print  a list of pairs of call paths for the interfaces exported by the shared object,\nalong with the number of times each path is used.\n",
                    "flag": "-c",
                    "long": "--call-pairs"
                },
                {
                    "name": "-p --flat-profile",
                    "content": "Generate a flat profile of all of the functions in the monitored object,  with  counts\nand ticks.\n",
                    "flag": "-p",
                    "long": "--flat-profile"
                },
                {
                    "name": "-q --graph",
                    "content": "Generate a call graph.\n\nIf  none  of  the  above options is specified, then the default behavior is to display a flat\nprofile and a call graph.\n\nThe following additional command-line options are available:\n\n-?, --help\nDisplay a summary of command-line options and arguments and exit.\n",
                    "flag": "-q",
                    "long": "--graph"
                },
                {
                    "name": "--usage",
                    "content": "Display a short usage message and exit.\n",
                    "long": "--usage"
                },
                {
                    "name": "-V --version",
                    "content": "Display the program version and exit.\n",
                    "flag": "-V",
                    "long": "--version"
                }
            ]
        },
        "CONFORMING TO": {
            "content": "The sprof command is a GNU extension, not present in POSIX.1.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "The following example demonstrates the use of sprof.  The example consists of a main  program\nthat calls two functions in a shared object.  First, the code of the main program:\n\n$ cat prog.c\n#include <stdlib.h>\n\nvoid x1(void);\nvoid x2(void);\n\nint\nmain(int argc, char *argv[])\n{\nx1();\nx2();\nexit(EXITSUCCESS);\n}\n\nThe  functions  x1()  and  x2() are defined in the following source file that is used to con‐\nstruct the shared object:\n\n$ cat libdemo.c\n#include <unistd.h>\n\nvoid\nconsumeCpu1(int lim)\n{\nfor (int j = 0; j < lim; j++)\ngetppid();\n}\n\nvoid\nx1(void) {\nfor (int j = 0; j < 100; j++)\nconsumeCpu1(200000);\n}\n\nvoid\nconsumeCpu2(int lim)\n{\nfor (int j = 0; j < lim; j++)\ngetppid();\n}\n\nvoid\nx2(void)\n{\nfor (int j = 0; j < 1000; j++)\nconsumeCpu2(10000);\n}\n\nNow we construct the shared object with the real name libdemo.so.1.0.1, and the  soname  lib‐\ndemo.so.1:\n\n$ cc -g -fPIC -shared -Wl,-soname,libdemo.so.1 \\\n-o libdemo.so.1.0.1 libdemo.c\n\nThen we construct symbolic links for the library soname and the library linker name:\n\n$ ln -sf libdemo.so.1.0.1 libdemo.so.1\n$ ln -sf libdemo.so.1 libdemo.so\n\nNext,  we  compile  the main program, linking it against the shared object, and then list the\ndynamic dependencies of the program:\n\n$ cc -g -o prog prog.c -L. -ldemo\n$ ldd prog\nlinux-vdso.so.1 =>  (0x00007fff86d66000)\nlibdemo.so.1 => not found\nlibc.so.6 => /lib64/libc.so.6 (0x00007fd4dc138000)\n/lib64/ld-linux-x86-64.so.2 (0x00007fd4dc51f000)\n\nIn order to get profiling information for the shared object, we define the environment  vari‐\nable LDPROFILE with the soname of the library:\n\n$ export LDPROFILE=libdemo.so.1\n\nWe  then define the environment variable LDPROFILEOUTPUT with the pathname of the directory\nwhere profile output should be written, and create that directory if it does  not  exist  al‐\nready:\n\n$ export LDPROFILEOUTPUT=$(pwd)/profdata\n$ mkdir -p $LDPROFILEOUTPUT\n\nLDPROFILE causes profiling output to be appended to the output file if it already exists, so\nwe ensure that there is no preexisting profiling data:\n\n$ rm -f $LDPROFILEOUTPUT/$LDPROFILE.profile\n\nWe then run the program to produce the profiling output, which is written to a  file  in  the\ndirectory specified in LDPROFILEOUTPUT:\n\n$ LDLIBRARYPATH=. ./prog\n$ ls profdata\nlibdemo.so.1.profile\n\nWe then use the sprof -p option to generate a flat profile with counts and ticks:\n\n$ sprof -p libdemo.so.1 $LDPROFILEOUTPUT/libdemo.so.1.profile\nFlat profile:\n\nEach sample counts as 0.01 seconds.\n%   cumulative   self              self     total\ntime   seconds   seconds    calls  us/call  us/call  name\n60.00      0.06     0.06      100   600.00           consumeCpu1\n40.00      0.10     0.04     1000    40.00           consumeCpu2\n0.00      0.10     0.00        1     0.00           x1\n0.00      0.10     0.00        1     0.00           x2\n\nThe sprof -q option generates a call graph:\n\n$ sprof -q libdemo.so.1 $LDPROFILEOUTPUT/libdemo.so.1.profile\n\nindex % time    self  children    called     name\n\n0.00    0.00      100/100         x1 [1]\n[0]    100.0    0.00    0.00      100         consumeCpu1 [0]\n-----------------------------------------------\n0.00    0.00        1/1           <UNKNOWN>\n[1]      0.0    0.00    0.00        1         x1 [1]\n0.00    0.00      100/100         consumeCpu1 [0]\n-----------------------------------------------\n0.00    0.00     1000/1000        x2 [3]\n[2]      0.0    0.00    0.00     1000         consumeCpu2 [2]\n-----------------------------------------------\n0.00    0.00        1/1           <UNKNOWN>\n[3]      0.0    0.00    0.00        1         x2 [3]\n0.00    0.00     1000/1000        consumeCpu2 [2]\n-----------------------------------------------\n\nAbove  and  below, the \"<UNKNOWN>\" strings represent identifiers that are outside of the pro‐\nfiled object (in this example, these are instances of main()).\n\nThe sprof -c option generates a list of call pairs and the number of their occurrences:\n\n$ sprof -c libdemo.so.1 $LDPROFILEOUTPUT/libdemo.so.1.profile\n<UNKNOWN>                  x1                                 1\nx1                         consumeCpu1                      100\n<UNKNOWN>                  x2                                 1\nx2                         consumeCpu2                     1000\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "gprof(1), ldd(1), ld.so(8)\n",
            "subsections": []
        },
        "COLOPHON": {
            "content": "This page is part of release 5.10 of the Linux  man-pages  project.   A  description  of  the\nproject,  information about reporting bugs, and the latest version of this page, can be found\nat https://www.kernel.org/doc/man-pages/.\n\n\n\nLinux                                        2020-11-01                                     SPROF(1)",
            "subsections": []
        }
    },
    "summary": "sprof - read and display shared object profiling data",
    "flags": [
        {
            "flag": "-c",
            "long": "--call-pairs",
            "arg": null,
            "description": "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."
        },
        {
            "flag": "-p",
            "long": "--flat-profile",
            "arg": null,
            "description": "Generate a flat profile of all of the functions in the monitored object, with counts and ticks."
        },
        {
            "flag": "-q",
            "long": "--graph",
            "arg": null,
            "description": "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: -?, --help Display a summary of command-line options and arguments and exit."
        },
        {
            "flag": "",
            "long": "--usage",
            "arg": null,
            "description": "Display a short usage message and exit."
        },
        {
            "flag": "-V",
            "long": "--version",
            "arg": null,
            "description": "Display the program version and exit."
        }
    ],
    "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(EXITSUCCESS);",
        "The  functions  x1()  and  x2() are defined in the following source file that is used to con‐",
        "struct the shared object:",
        "$ cat libdemo.c",
        "#include <unistd.h>",
        "void",
        "consumeCpu1(int lim)",
        "for (int j = 0; j < lim; j++)",
        "getppid();",
        "void",
        "x1(void) {",
        "for (int j = 0; j < 100; j++)",
        "consumeCpu1(200000);",
        "void",
        "consumeCpu2(int lim)",
        "for (int j = 0; j < lim; j++)",
        "getppid();",
        "void",
        "x2(void)",
        "for (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  lib‐",
        "demo.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  vari‐",
        "able LDPROFILE with the soname of the library:",
        "$ export LDPROFILE=libdemo.so.1",
        "We  then define the environment variable LDPROFILEOUTPUT with the pathname of the directory",
        "where profile output should be written, and create that directory if it does  not  exist  al‐",
        "ready:",
        "$ export LDPROFILEOUTPUT=$(pwd)/profdata",
        "$ mkdir -p $LDPROFILEOUTPUT",
        "LDPROFILE 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 $LDPROFILEOUTPUT/$LDPROFILE.profile",
        "We then run the program to produce the profiling output, which is written to a  file  in  the",
        "directory specified in LDPROFILEOUTPUT:",
        "$ LDLIBRARYPATH=. ./prog",
        "$ ls profdata",
        "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 $LDPROFILEOUTPUT/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 $LDPROFILEOUTPUT/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 pro‐",
        "filed 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 $LDPROFILEOUTPUT/libdemo.so.1.profile",
        "<UNKNOWN>                  x1                                 1",
        "x1                         consumeCpu1                      100",
        "<UNKNOWN>                  x2                                 1",
        "x2                         consumeCpu2                     1000"
    ],
    "see_also": [
        {
            "name": "gprof",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/gprof/1/json"
        },
        {
            "name": "ldd",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/ldd/1/json"
        },
        {
            "name": "ld.so",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/ld.so/8/json"
        }
    ],
    "tldr": {
        "source": "official",
        "description": "Read and display shared object profiling data.",
        "examples": [
            {
                "description": "Generate a flat profile and call graph (default output)",
                "command": "sprof {{path/to/library.so}} {{path/to/library.so.profile}}"
            },
            {
                "description": "Generate a flat profile with counts and ticks",
                "command": "sprof {{-p|--flat-profile}} {{path/to/library.so}} {{path/to/library.so.profile}}"
            },
            {
                "description": "Generate a call graph",
                "command": "sprof {{-q|--graph}} {{path/to/library.so}} {{path/to/library.so.profile}}"
            },
            {
                "description": "Print call pairs and their usage counts",
                "command": "sprof {{-c|--call-pairs}} {{path/to/library.so}} {{path/to/library.so.profile}}"
            },
            {
                "description": "Use profile data from current directory (auto-detected by soname)",
                "command": "sprof {{path/to/library.so}}"
            }
        ]
    }
}