Saturday, 12 October 2013

Performance Analysis With Perf

Requires debugging symbols to be installed
            kernel-debuginfo / vmlinux for kernel
            Applications compiled with -g

By default Perf commands restricted to root
             Security checks can be disabled (temporarily) with
             #echo 0 > / proc / sys / kernel / perf_event_paranoid

#perf list
  

Lists all events supported by the current architecture
Any event names in first column can be used
Hardware events use the PMU
       Low overhead
Software events are triggered by the kernel
Many hardware events missing
       Can be set as a raw event
       Documented by CPU manufacturers

#perf record
Reads performance data and generates a file in the current directory:
       file name: perf.data

Can generate a large dataset if profiling the whole system
Or if recording with call-graphs (-g)
Which is event is recorded can be specified with -e:
#perf record -e instructions sleep 5
#perf record -e LLC-loads /usr/bin/firefox

Recording can be restricted in different ways
          1) Specific command (default)
              #perf record command
          2)All CPU's for the duration of specified command
              #perf record -a commmand
          3)Specific CPU's only
              #perf record -C CPU_number command

command : any command you want to check
CPU_number: 0,1,2 i.e id of cpu you want to check
#perf report

To generate report (using perf.data file)




Attaching perf to exesting process

#perf record -p $(pidof process)

Attaching to thread using tid

#perf record -t thread_id

For group of thread

#perf record -G groupname