LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

gprof

GNU execution profiler

TLDR

Generate profile report
$ gprof [program] [gmon.out]
copy
Flat profile only
$ gprof -p [program]
copy
Call graph only
$ gprof -q [program]
copy
Suppress static functions
$ gprof -a [program]
copy
Output to file
$ gprof [program] > [profile.txt]
copy

SYNOPSIS

gprof [options] [executable] [profile-data]

DESCRIPTION

gprof analyzes program execution profiles to identify performance bottlenecks. It requires programs compiled with the -pg flag and produces reports showing time spent in each function and call relationships.The tool generates two main reports: a flat profile showing time per function, and a call graph showing function relationships and cumulative times.

PARAMETERS

-p, --flat-profile

Print flat profile only.
-q, --graph
Print call graph only.
-b, --brief
Suppress explanatory text.
-a, --no-static
Suppress static functions.
-z, --display-unused-functions
Show functions never called.
-c, --static-call-graph
Discover child functions by scanning the machine code, even if never called at runtime.
-A, --annotated-source
Print annotated source.
-l, --line
Line-by-line profiling.
-s, --sum
Accumulate several profile data files into a summary `gmon.sum`.
-i, --file-info
Print summary information about the profile data file, then exit.

WORKFLOW

$ # 1. Compile with profiling
gcc -pg -o program program.c

# 2. Run program (generates gmon.out)
./program

# 3. Analyze profile
gprof program gmon.out > analysis.txt
copy

INSTALL

sudo apt install binutils
copy
sudo dnf install binutils
copy
sudo pacman -S binutils
copy
sudo apk add binutils
copy
sudo zypper install binutils
copy
brew install binutils
copy
nix profile install nixpkgs#binutils
copy

CAVEATS

Requires recompilation with -pg. Adds overhead to execution. Sampling-based; short-running functions may be underrepresented. Modern alternatives include perf and valgrind.

HISTORY

gprof was developed at UC Berkeley in the early 1980s by Susan Graham, Peter Kessler, and Marshall McKusick. It became the standard Unix profiler and remains part of GNU binutils.

SEE ALSO

perf(1), valgrind(1), gcov(1), gcc(1)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid