{
    "mode": "man",
    "parameter": "gprof",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/gprof/1/json",
    "generated": "2026-06-03T03:33:15Z",
    "synopsis": "gprof [ -[abcDhilLrsTvwxyz] ] [ -[ACeEfFJnNOpPqQRStZ][name] ]\n[ -I dirs ] [ -d[num] ] [ -k from/to ]\n[ -m min-count ] [ -R mapfile ] [ -t table-length ]\n[ --[no-]annotated-source[=name] ]\n[ --[no-]exec-counts[=name] ]\n[ --[no-]flat-profile[=name] ] [ --[no-]graph[=name] ]\n[ --[no-]time=name] [ --all-lines ] [ --brief ]\n[ --debug[=level] ] [ --function-ordering ]\n[ --file-ordering mapfile ] [ --directory-path=dirs ]\n[ --display-unused-functions ] [ --file-format=name ]\n[ --file-info ] [ --help ] [ --line ] [ --inline-file-names ]\n[ --min-count=n ] [ --no-static ] [ --print-path ]\n[ --separate-files ] [ --static-call-graph ] [ --sum ]\n[ --table-length=len ] [ --traditional ] [ --version ]\n[ --width=n ] [ --ignore-non-functions ]\n[ --demangle[=STYLE] ] [ --no-demangle ]\n[--external-symbol-table=name]\n[ image-file ] [ profile-file ... ]",
    "sections": {
        "NAME": {
            "content": "gprof - display call graph profile data\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "gprof [ -[abcDhilLrsTvwxyz] ] [ -[ACeEfFJnNOpPqQRStZ][name] ]\n[ -I dirs ] [ -d[num] ] [ -k from/to ]\n[ -m min-count ] [ -R mapfile ] [ -t table-length ]\n[ --[no-]annotated-source[=name] ]\n[ --[no-]exec-counts[=name] ]\n[ --[no-]flat-profile[=name] ] [ --[no-]graph[=name] ]\n[ --[no-]time=name] [ --all-lines ] [ --brief ]\n[ --debug[=level] ] [ --function-ordering ]\n[ --file-ordering mapfile ] [ --directory-path=dirs ]\n[ --display-unused-functions ] [ --file-format=name ]\n[ --file-info ] [ --help ] [ --line ] [ --inline-file-names ]\n[ --min-count=n ] [ --no-static ] [ --print-path ]\n[ --separate-files ] [ --static-call-graph ] [ --sum ]\n[ --table-length=len ] [ --traditional ] [ --version ]\n[ --width=n ] [ --ignore-non-functions ]\n[ --demangle[=STYLE] ] [ --no-demangle ]\n[--external-symbol-table=name]\n[ image-file ] [ profile-file ... ]\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "\"gprof\" produces an execution profile of C, Pascal, or Fortran77 programs.  The effect of\ncalled routines is incorporated in the profile of each caller.  The profile data is taken\nfrom the call graph profile file (gmon.out default) which is created by programs that are\ncompiled with the -pg option of \"cc\", \"pc\", and \"f77\".  The -pg option also links in versions\nof the library routines that are compiled for profiling.  \"Gprof\" reads the given object file\n(the default is \"a.out\") and establishes the relation between its symbol table and the call\ngraph profile from gmon.out.  If more than one profile file is specified, the \"gprof\" output\nshows the sum of the profile information in the given profile files.\n\nIf you use gcc 2.95.x or 3.0 to compile your binaries, you may need to add the -fprofile-arcs\nto the compile command line in order for the call graphs to be properly stored in gmon.out.\n\n\"Gprof\" calculates the amount of time spent in each routine.  Next, these times are\npropagated along the edges of the call graph.  Cycles are discovered, and calls into a cycle\nare made to share the time of the cycle.\n\nSeveral forms of output are available from the analysis.\n\nThe flat profile shows how much time your program spent in each function, and how many times\nthat function was called.  If you simply want to know which functions burn most of the\ncycles, it is stated concisely here.\n\nThe call graph shows, for each function, which functions called it, which other functions it\ncalled, and how many times.  There is also an estimate of how much time was spent in the\nsubroutines of each function.  This can suggest places where you might try to eliminate\nfunction calls that use a lot of time.\n\nThe annotated source listing is a copy of the program's source code, labeled with the number\nof times each line of the program was executed.\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "These options specify which of several output formats \"gprof\" should produce.\n\nMany of these options take an optional symspec to specify functions to be included or\nexcluded.  These options can be specified multiple times, with different symspecs, to include\nor exclude sets of symbols.\n\nSpecifying any of these options overrides the default (-p -q), which prints a flat profile\nand call graph analysis for all functions.\n\n\"-A[symspec]\"\n\"--annotated-source[=symspec]\"\nThe -A option causes \"gprof\" to print annotated source code.  If symspec is specified,\nprint output only for matching symbols.\n\n\"-b\"\n\"--brief\"\nIf the -b option is given, \"gprof\" doesn't print the verbose blurbs that try to explain\nthe meaning of all of the fields in the tables.  This is useful if you intend to print\nout the output, or are tired of seeing the blurbs.\n\n\"-C[symspec]\"\n\"--exec-counts[=symspec]\"\nThe -C option causes \"gprof\" to print a tally of functions and the number of times each\nwas called.  If symspec is specified, print tally only for matching symbols.\n\nIf the profile data file contains basic-block count records, specifying the -l option,\nalong with -C, will cause basic-block execution counts to be tallied and displayed.\n\n\"-i\"\n\"--file-info\"\nThe -i option causes \"gprof\" to display summary information about the profile data\nfile(s) and then exit.  The number of histogram, call graph, and basic-block count\nrecords is displayed.\n\n\"-I dirs\"\n\"--directory-path=dirs\"\nThe -I option specifies a list of search directories in which to find source files.\nEnvironment variable GPROFPATH can also be used to convey this information.  Used mostly\nfor annotated source output.\n\n\"-J[symspec]\"\n\"--no-annotated-source[=symspec]\"\nThe -J option causes \"gprof\" not to print annotated source code.  If symspec is\nspecified, \"gprof\" prints annotated source, but excludes matching symbols.\n\n\"-L\"\n\"--print-path\"\nNormally, source filenames are printed with the path component suppressed.  The -L option\ncauses \"gprof\" to print the full pathname of source filenames, which is determined from\nsymbolic debugging information in the image file and is relative to the directory in\nwhich the compiler was invoked.\n\n\"-p[symspec]\"\n\"--flat-profile[=symspec]\"\nThe -p option causes \"gprof\" to print a flat profile.  If symspec is specified, print\nflat profile only for matching symbols.\n\n\"-P[symspec]\"\n\"--no-flat-profile[=symspec]\"\nThe -P option causes \"gprof\" to suppress printing a flat profile.  If symspec is\nspecified, \"gprof\" prints a flat profile, but excludes matching symbols.\n\n\"-q[symspec]\"\n\"--graph[=symspec]\"\nThe -q option causes \"gprof\" to print the call graph analysis.  If symspec is specified,\nprint call graph only for matching symbols and their children.\n\n\"-Q[symspec]\"\n\"--no-graph[=symspec]\"\nThe -Q option causes \"gprof\" to suppress printing the call graph.  If symspec is\nspecified, \"gprof\" prints a call graph, but excludes matching symbols.\n\n\"-t\"\n\"--table-length=num\"\nThe -t option causes the num most active source lines in each source file to be listed\nwhen source annotation is enabled.  The default is 10.\n\n\"-y\"\n\"--separate-files\"\nThis option affects annotated source output only.  Normally, \"gprof\" prints annotated\nsource files to standard-output.  If this option is specified, annotated source for a\nfile named path/filename is generated in the file filename-ann.  If the underlying file\nsystem would truncate filename-ann so that it overwrites the original filename, \"gprof\"\ngenerates annotated source in the file filename.ann instead (if the original file name\nhas an extension, that extension is replaced with .ann).\n\n\"-Z[symspec]\"\n\"--no-exec-counts[=symspec]\"\nThe -Z option causes \"gprof\" not to print a tally of functions and the number of times\neach was called.  If symspec is specified, print tally, but exclude matching symbols.\n\n\"-r\"\n\"--function-ordering\"\nThe --function-ordering option causes \"gprof\" to print a suggested function ordering for\nthe program based on profiling data.  This option suggests an ordering which may improve\npaging, tlb and cache behavior for the program on systems which support arbitrary\nordering of functions in an executable.\n\nThe exact details of how to force the linker to place functions in a particular order is\nsystem dependent and out of the scope of this manual.\n\n\"-R mapfile\"\n\"--file-ordering mapfile\"\nThe --file-ordering option causes \"gprof\" to print a suggested .o link line ordering for\nthe program based on profiling data.  This option suggests an ordering which may improve\npaging, tlb and cache behavior for the program on systems which do not support arbitrary\nordering of functions in an executable.\n\nUse of the -a argument is highly recommended with this option.\n\nThe mapfile argument is a pathname to a file which provides function name to object file\nmappings.  The format of the file is similar to the output of the program \"nm\".\n\nc-parse.o:00000000 T yyparse\nc-parse.o:00000004 C yyerrflag\nc-lang.o:00000000 T maybeobjcmethodname\nc-lang.o:00000000 T printlangstatistics\nc-lang.o:00000000 T recognizeobjckeyword\nc-decl.o:00000000 T printlangidentifier\nc-decl.o:00000000 T printlangtype\n...\n\nTo create a mapfile with GNU \"nm\", type a command like \"nm --extern-only --defined-only\n-v --print-file-name program-name\".\n\n\"-T\"\n\"--traditional\"\nThe -T option causes \"gprof\" to print its output in \"traditional\" BSD style.\n\n\"-w width\"\n\"--width=width\"\nSets width of output lines to width.  Currently only used when printing the function\nindex at the bottom of the call graph.\n\n\"-x\"\n\"--all-lines\"\nThis option affects annotated source output only.  By default, only the lines at the\nbeginning of a basic-block are annotated.  If this option is specified, every line in a\nbasic-block is annotated by repeating the annotation for the first line.  This behavior\nis similar to \"tcov\"'s -a.\n\n\"--demangle[=style]\"\n\"--no-demangle\"\nThese options control whether C++ symbol names should be demangled when printing output.\nThe default is to demangle symbols.  The \"--no-demangle\" option may be used to turn off\ndemangling. Different compilers have different mangling styles.  The optional demangling\nstyle argument can be used to choose an appropriate demangling style for your compiler.\n",
            "subsections": [
                {
                    "name": "Analysis Options",
                    "content": "\"-a\"\n\"--no-static\"\nThe -a option causes \"gprof\" to suppress the printing of statically declared (private)\nfunctions.  (These are functions whose names are not listed as global, and which are not\nvisible outside the file/function/block where they were defined.)  Time spent in these\nfunctions, calls to/from them, etc., will all be attributed to the function that was\nloaded directly before it in the executable file.  This option affects both the flat\nprofile and the call graph.\n\n\"-c\"\n\"--static-call-graph\"\nThe -c option causes the call graph of the program to be augmented by a heuristic which\nexamines the text space of the object file and identifies function calls in the binary\nmachine code.  Since normal call graph records are only generated when functions are\nentered, this option identifies children that could have been called, but never were.\nCalls to functions that were not compiled with profiling enabled are also identified, but\nonly if symbol table entries are present for them.  Calls to dynamic library routines are\ntypically not found by this option.  Parents or children identified via this heuristic\nare indicated in the call graph with call counts of 0.\n\n\"-D\"\n\"--ignore-non-functions\"\nThe -D option causes \"gprof\" to ignore symbols which are not known to be functions.  This\noption will give more accurate profile data on systems where it is supported (Solaris and\nHPUX for example).\n\n\"-k from/to\"\nThe -k option allows you to delete from the call graph any arcs from symbols matching\nsymspec from to those matching symspec to.\n\n\"-l\"\n\"--line\"\nThe -l option enables line-by-line profiling, which causes histogram hits to be charged\nto individual source code lines, instead of functions.  This feature only works with\nprograms compiled by older versions of the \"gcc\" compiler.  Newer versions of \"gcc\" are\ndesigned to work with the \"gcov\" tool instead.\n\nIf the program was compiled with basic-block counting enabled, this option will also\nidentify how many times each line of code was executed.  While line-by-line profiling can\nhelp isolate where in a large function a program is spending its time, it also\nsignificantly increases the running time of \"gprof\", and magnifies statistical\ninaccuracies.\n\n\"--inline-file-names\"\nThis option causes \"gprof\" to print the source file after each symbol in both the flat\nprofile and the call graph. The full path to the file is printed if used with the -L\noption.\n\n\"-m num\"\n\"--min-count=num\"\nThis option affects execution count output only.  Symbols that are executed less than num\ntimes are suppressed.\n\n\"-nsymspec\"\n\"--time=symspec\"\nThe -n option causes \"gprof\", in its call graph analysis, to only propagate times for\nsymbols matching symspec.\n\n\"-Nsymspec\"\n\"--no-time=symspec\"\nThe -n option causes \"gprof\", in its call graph analysis, not to propagate times for\nsymbols matching symspec.\n\n\"-Sfilename\"\n\"--external-symbol-table=filename\"\nThe -S option causes \"gprof\" to read an external symbol table file, such as\n/proc/kallsyms, rather than read the symbol table from the given object file (the default\nis \"a.out\"). This is useful for profiling kernel modules.\n\n\"-z\"\n\"--display-unused-functions\"\nIf you give the -z option, \"gprof\" will mention all functions in the flat profile, even\nthose that were never called, and that had no time spent in them.  This is useful in\nconjunction with the -c option for discovering which routines were never called.\n"
                },
                {
                    "name": "Miscellaneous Options",
                    "content": "\"-d[num]\"\n\"--debug[=num]\"\nThe -d num option specifies debugging options.  If num is not specified, enable all\ndebugging.\n\n\"-h\"\n\"--help\"\nThe -h option prints command line usage.\n\n\"-Oname\"\n\"--file-format=name\"\nSelects the format of the profile data files.  Recognized formats are auto (the default),\nbsd, 4.4bsd, magic, and prof (not yet supported).\n\n\"-s\"\n\"--sum\"\nThe -s option causes \"gprof\" to summarize the information in the profile data files it\nread in, and write out a profile data file called gmon.sum, which contains all the\ninformation from the profile data files that \"gprof\" read in.  The file gmon.sum may be\none of the specified input files; the effect of this is to merge the data in the other\ninput files into gmon.sum.\n\nEventually you can run \"gprof\" again without -s to analyze the cumulative data in the\nfile gmon.sum.\n\n\"-v\"\n\"--version\"\nThe -v flag causes \"gprof\" to print the current version number, and then exit.\n"
                },
                {
                    "name": "Deprecated Options",
                    "content": "These options have been replaced with newer versions that use symspecs.\n\n\"-e functionname\"\nThe -e function option tells \"gprof\" to not print information about the function\nfunctionname (and its children...) in the call graph.  The function will still be listed\nas a child of any functions that call it, but its index number will be shown as [not\nprinted].  More than one -e option may be given; only one functionname may be indicated\nwith each -e option.\n\n\"-E functionname\"\nThe \"-E function\" option works like the \"-e\" option, but time spent in the function (and\nchildren who were not called from anywhere else), will not be used to compute the\npercentages-of-time for the call graph.  More than one -E option may be given; only one\nfunctionname may be indicated with each -E option.\n\n\"-f functionname\"\nThe -f function option causes \"gprof\" to limit the call graph to the function\nfunctionname and its children (and their children...).  More than one -f option may be\ngiven; only one functionname may be indicated with each -f option.\n\n\"-F functionname\"\nThe -F function option works like the \"-f\" option, but only time spent in the function\nand its children (and their children...) will be used to determine total-time and\npercentages-of-time for the call graph.  More than one -F option may be given; only one\nfunctionname may be indicated with each -F option.  The -F option overrides the -E\noption.\n"
                }
            ]
        },
        "FILES": {
            "content": "\"a.out\"\nthe namelist and text space.\n\n\"gmon.out\"\ndynamic call graph and profile.\n\n\"gmon.sum\"\nsummarized dynamic call graph and profile.\n",
            "subsections": []
        },
        "BUGS": {
            "content": "The granularity of the sampling is shown, but remains statistical at best.  We assume that\nthe time for each execution of a function can be expressed by the total time for the function\ndivided by the number of times the function is called.  Thus the time propagated along the\ncall graph arcs to the function's parents is directly proportional to the number of times\nthat arc is traversed.\n\nParents that are not themselves profiled will have the time of their profiled children\npropagated to them, but they will appear to be spontaneously invoked in the call graph\nlisting, and will not have their time propagated further.  Similarly, signal catchers, even\nthough profiled, will appear to be spontaneous (although for more obscure reasons).  Any\nprofiled children of signal catchers should have their times propagated properly, unless the\nsignal catcher was invoked during the execution of the profiling routine, in which case all\nis lost.\n\nThe profiled program must call \"exit\"(2) or return normally for the profiling information to\nbe saved in the gmon.out file.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "cc(1), prof(1), and the Info entry for gprof.\n\n\"An Execution Profiler for Modular Programs\", by S. Graham, P. Kessler, M. McKusick; Software\n- Practice and Experience, Vol. 13, pp. 671-685, 1983.\n\n\"gprof: A Call Graph Execution Profiler\", by S. Graham, P. Kessler, M. McKusick; Proceedings\nof the SIGPLAN '82 Symposium on Compiler Construction, SIGPLAN Notices, Vol. 17, No  6, pp.\n120-126, June 1982.\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright (c) 1988-2022 Free Software Foundation, Inc.\n\nPermission is granted to copy, distribute and/or modify this document under the terms of the\nGNU Free Documentation License, Version 1.3 or any later version published by the Free\nSoftware Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-\nCover Texts.  A copy of the license is included in the section entitled \"GNU Free\nDocumentation License\".\n\n\n\nbinutils-2.38                                2025-12-03                                     GPROF(1)",
            "subsections": []
        }
    },
    "summary": "gprof - display call graph profile data",
    "flags": [],
    "examples": [],
    "see_also": [
        {
            "name": "cc",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/cc/1/json"
        },
        {
            "name": "prof",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/prof/1/json"
        }
    ],
    "tldr": {
        "source": "official",
        "description": "Performance analysis tool for many programming languages.",
        "examples": [
            {
                "description": "Compile binary to default `a.out` with gprof information and run it to get `gmon.out`",
                "command": "gcc {{-p|-pg}} {{program.c}} && ./a.out"
            },
            {
                "description": "Run gprof on default `a.out` and `gmon.out` to obtain profile output",
                "command": "gprof"
            },
            {
                "description": "Run gprof on a named binary",
                "command": "gprof {{path/to/binary}} {{path/to/gmon.out}}"
            },
            {
                "description": "Suppress profile field's description",
                "command": "gprof {{-b|--brief}}"
            },
            {
                "description": "Display routines that have zero usage",
                "command": "gprof {{-bz|--brief --display-unused-functions}}"
            }
        ]
    }
}