Linux profiling (kernel + user)

There’s a special performance and counter subsystem is added to linux kernel (since 2.6.31), and can be enabled by CONFIG_PERF_EVENTS in

Symbol: PERF_EVENTS [=y]                                                                                                                                                     
 │ Prompt: Kernel performance events and counters                                                                                                                           
 │   Defined at init/Kconfig:983                                                                                                                                              
 │   Depends on: HAVE_PERF_EVENTS [=y]                                                                                                                          
 │   Location:                                                                                                                                                               
 │     -> General setup                                                                                                                                               
 │       -> Kernel Performance Events And Counters                                                                                        
 │   Selects: ANON_INODES [=y]                      

There’s a user space utility called “perf” which makes the job quite easy. For example, if you want to do profiling for a command, here’s what you need to do.

# perf record -a dd if=/dev/zero oflag=direct of=/tmp/zerofile bs=1024 count=16384
# perf report

1st command will take the performance data, and 2nd will do the reporting (quite nice) from whatever data is collected by 1st command. Really nice.

The entire wiki on how to use perf can be found at :


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s