Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm doing some performance test for apps in Ubuntu. Is there a nice way (or an application) to measure the CPU usage of a single app?

I would be great if it was also possible to create charts of CPU usage over time, but that's not a necessity.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

You could try using top | grep <application-name>, gives you a bunch of stats including CPU usage in percent.

Example: The output while monitoring the application clementine using top, the column with numbers 8's, 9's and a single 22 and 7 is the line that charts the CPU usage percentage of clementine over a period of time it runs

nits@nits-workstation:~$ top | grep clementine
 4729 nits      20   0  408m 101m  23m S    8  5.1   8:59.36 clementine         
 4729 nits      20   0  408m 101m  23m S    8  5.1   8:59.61 clementine         
 4729 nits      20   0  408m 101m  23m S    8  5.1   8:59.86 clementine         
 4729 nits      20   0  408m 101m  23m S    8  5.1   9:00.10 clementine         
 4729 nits      20   0  408m 101m  23m S    9  5.1   9:00.37 clementine         
 4729 nits      20   0  408m 101m  23m S    8  5.1   9:00.62 clementine         
 4729 nits      20   0  408m 101m  23m S    9  5.1   9:00.88 clementine         
 4729 nits      20   0  408m 101m  23m S    9  5.1   9:01.14 clementine         
 4729 nits      20   0  408m 101m  23m S    8  5.1   9:01.39 clementine         
 4729 nits      20   0  408m 101m  23m S    8  5.1   9:01.63 clementine         
 4729 nits      20   0  408m 101m  23m S    8  5.1   9:01.88 clementine         
 4729 nits      20   0  408m 101m  23m S    8  5.1   9:02.11 clementine         
 4729 nits      20   0  408m 101m  23m S    9  5.1   9:02.37 clementine         
 4729 nits      20   0  408m 101m  23m S    8  5.1   9:02.61 clementine         
 4729 nits      20   0  408m 101m  23m S    9  5.1   9:02.89 clementine         
 4729 nits      20   0  408m 101m  23m S   22  5.1   9:03.56 clementine         
 4729 nits      20   0  408m 101m  23m S    9  5.1   9:03.82 clementine         
 4729 nits      20   0  408m 101m  23m S    8  5.1   9:04.07 clementine         
 4729 nits      20   0  408m 101m  23m S    9  5.1   9:04.33 clementine         
 4729 nits      20   0  408m 101m  23m S    9  5.1   9:04.59 clementine         
 4729 nits      20   0  408m 101m  23m S    8  5.1   9:04.83 clementine         
 4729 nits      20   0  408m 101m  23m S    9  5.1   9:05.09 clementine         
 4729 nits      20   0  408m 101m  23m S    8  5.1   9:05.32 clementine         
 4729 nits      20   0  408m 101m  23m S    8  5.1   9:05.56 clementine         
 4729 nits      20   0  408m 101m  23m S    9  5.1   9:05.82 clementine         
 4729 nits      20   0  408m 101m  23m S    8  5.1   9:06.07 clementine         
 4729 nits      20   0  408m 101m  23m S    8  5.1   9:06.32 clementine         
 4729 nits      20   0  408m 101m  23m S    8  5.1   9:06.56 clementine         
 4729 nits      20   0  408m 101m  23m S    9  5.1   9:06.82 clementine         
 4729 nits      20   0  408m 101m  23m S    8  5.1   9:07.07 clementine         
 4729 nits      20   0  408m 101m  23m S    8  5.1   9:07.32 clementine         
 4729 nits      20   0  408m 101m  23m S    7  5.1   9:07.54 clementine         
 4729 nits      20   0  408m 101m  23m S    8  5.1   9:07.79 clementine         
 4729 nits      20   0  408m 101m  23m S    8  5.1   9:08.03 clementine         
 4729 nits      20   0  408m 101m  23m S    8  5.1   9:08.28 clementine         
 4729 nits      20   0  408m 101m  23m S    9  5.1   9:08.54 clementine         
 4729 nits      20   0  408m 101m  23m S    8  5.1   9:08.77 clementine         
 4729 nits      20   0  408m 101m  23m S    9  5.1   9:09.03 clementine         
 4729 nits      20   0  408m 101m  23m S    9  5.1   9:09.29 clementine         
 4729 nits      20   0  408m 101m  23m S    9  5.1   9:09.55 clementine         
 4729 nits      20   0  408m 101m  23m S    8  5.1   9:09.79 clementine         
 4729 nits      20   0  408m 101m  23m S    8  5.1   9:10.03 clementine  
share|improve this answer

You can use pidstat for that. It's in the package sysstat.

pidstat -p <PID> 1

shows CPU utilisation of the given process every 1 second until you cancel it.

pidstat can also show lots of other interesting information about a running process, consult the manual page for details.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.