LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-28-2011, 02:08 PM   #1
neyshule
LQ Newbie
 
Registered: Apr 2011
Posts: 11

Rep: Reputation: 0
How to record a process's CPU usage and dump it out??


Hi all:
I want to monitor the CPU usage of a process which running for one hour, I know top can show all the stuff on screen but I want to record the usage in a file so that it can be used later, is there any tools that can achieves this??
 
Old 10-28-2011, 02:39 PM   #2
deloquencia
LQ Newbie
 
Registered: Oct 2011
Distribution: Debian & Ubuntu
Posts: 2

Rep: Reputation: 0
Please check the manual page, but I already checked, cause it sounded interesting - and, yes it's possible with top.

top -b -n <x> -p <p>, where x is the iteration value and p is the PID(s) to monitor.

You'll have at each iteration step tops default output, you can configure the output with .toprc to suit your needs or you can go along with grep, sed or (g)awk to post-process the output.

For example...

top -b -n <x> -p <pid> >> pid-monitoring
grep <pid> pid-monitoring | awk -F" " '{ print $9 }' >> pid.monitoring.csv


In default top's configuration the 9th col is the CPU usage. Please check with your config to get the right col for (g)awk. So you get a file for further post-processing with a spreadsheed application for example, guess thats what you're about to doing - charting CPU usage, do you?

Hope that helps you...

PS: I like the idea of monitoring processes and generating charts, it'll get on my scratch list for future spare-time coding projects

Last edited by deloquencia; 10-28-2011 at 02:43 PM. Reason: addes the PS...
 
Old 10-28-2011, 07:15 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Have a look at collectl - it produces good stats per process. Mark has posted several how-to's, with luck he'll drop in on this thread.
 
  


Reply

Tags
cpu, monitor, top



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
CPU Usage of a process matt9949 Linux - General 2 07-15-2011 07:48 AM
How to get %CPU usage of a process devershetty Linux - Newbie 13 08-16-2008 11:51 AM
How to get %CPU usage of a process romydmisc Linux - Newbie 2 05-24-2006 01:02 PM
process cpu usage vanv101 Fedora 9 06-24-2005 05:53 PM
CPU usage of a process asharma Solaris / OpenSolaris 7 03-29-2003 02:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration