linux profiler perf - ghdrako/doc_snipets GitHub Wiki

# perf

 usage: perf [--version] [--help] [OPTIONS] COMMAND [ARGS]

 The most commonly used perf commands are:
   annotate        Read perf.data (created by perf record) and display annotated code
   archive         Create archive with object files with build-ids found in perf.data file
   bench           General framework for benchmark suites
   buildid-cache   Manage build-id cache.
   buildid-list    List the buildids in a perf.data file
   config          Get and set variables in a configuration file.
   data            Data file related processing
   diff            Read perf.data files and display the differential profile
   evlist          List the event names in a perf.data file
   inject          Filter to augment the events stream with additional information
   kmem            Tool to trace/measure kernel memory properties
   kvm             Tool to trace/measure kvm guest os
   list            List all symbolic event types
   lock            Analyze lock events
   mem             Profile memory accesses
   record          Run a command and record its profile into perf.data
   report          Read perf.data (created by perf record) and display the profile
   sched           Tool to trace/measure scheduler properties (latencies)
   script          Read perf.data (created by perf record) and display trace output
   stat            Run a command and gather performance counter statistics
   test            Runs sanity tests.
   timechart       Tool to visualize total system behavior during a workload
   top             System profiling tool.
   probe           Define new dynamic tracepoints
   trace           strace inspired tool

 See 'perf help COMMAND' for more information on a specific command.

Allow Regular Users to Use perf

sudo su -
echo 0 > /proc/sys/kernel/perf_event_paranoid
exit

persist usage perf after reboot

sudo nano /etc/sysctl.conf
kernel.perf_event_paranoid = 0
 perf <options> subcommand <options/arguments>
Subcommand Description
annotate Reads perf.data and shows annotated code.
list Lists all measurable events. stat Gathers performance statistics.
stat Gathers performance statistics.
record Records samples into perf.data.
report Reads perf.data and displays the profile.
script Reads perf.data and displays trace output.
top Profiling tool.

View CPU Performance for a Command

sudo perf stat <command>
sudo perf stat ls

memory usage

$ ps -o pid,user,%mem,command ax | sort -b -k3 -r

$ sudo pmap 917
$ sudo pmap 917 | tail -n 1  # show only total memory usage
$ sudo pmap 917 | tail -n 1 | awk '/[0-9]K/{print $2}'  # show only total memory usage in KB

$ top | grep <PROCESS NAME>
$ /usr/bin/time --verbose ls # trzeba zainstalowa 

$ valgrind --tool=massif <executable> <arguments>
⚠️ **GitHub.com Fallback** ⚠️