* How to find the CPU usage of a process
@ 2006-02-18 17:42 Irfan Habib
2006-02-18 18:44 ` Bernd Eckenfels
0 siblings, 1 reply; 8+ messages in thread
From: Irfan Habib @ 2006-02-18 17:42 UTC (permalink / raw)
To: linux-kernel
Hi,
I'm a research student, working on self-organizing
grids.
I wanted to ask how can I find the cpu usage of a
process, as opposed to runtime, with cpu usage I mean
actually how many time slices were awarded to a
specific process, like the runtime of job may be 4 s,
but this also includes time it was suspended by some
interrupt, or had to wait for the scheduler etc..
Thanks in advance
Irfan Habib
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to find the CPU usage of a process
2006-02-18 17:42 How to find the CPU usage of a process Irfan Habib
@ 2006-02-18 18:44 ` Bernd Eckenfels
2006-02-18 18:55 ` Ulrich Drepper
0 siblings, 1 reply; 8+ messages in thread
From: Bernd Eckenfels @ 2006-02-18 18:44 UTC (permalink / raw)
To: linux-kernel
Irfan Habib <irfanhab@yahoo.com> wrote:
> I wanted to ask how can I find the cpu usage of a
> process, as opposed to runtime, with cpu usage I mean
> actually how many time slices were awarded to a
> specific process
It is accounted in seconds in usermode and kernelmode (io processing), not
in slicess.
You can use the result wof wait3(2) if you are the parent:
/usr/bin/time -v sleep 3
Command being timed: "sleep 3"
User time (seconds): 0.00
System time (seconds): 0.00
Percent of CPU this job got: 0%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:03.00
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 0
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 175
Voluntary context switches: 2
Involuntary context switches: 0
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
You could maybe also use BSD Job Accounting.
At runtime, the /proc interface is for you. See libproc for the data you can
query. /usr/include/proc/readroc.h:
utime, // stat user-mode CPU time accumulated by proces
stime, // stat kernel-mode CPU time accumulated by process
Gruss
Bernd
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to find the CPU usage of a process
2006-02-18 18:44 ` Bernd Eckenfels
@ 2006-02-18 18:55 ` Ulrich Drepper
2006-02-18 19:27 ` Bernd Eckenfels
0 siblings, 1 reply; 8+ messages in thread
From: Ulrich Drepper @ 2006-02-18 18:55 UTC (permalink / raw)
To: Bernd Eckenfels; +Cc: linux-kernel
On 2/18/06, Bernd Eckenfels <be-news06@lina.inka.de> wrote:
> You can use the result wof wait3(2) if you are the parent:
> [...]
That's after the fact. Programs which want to get the information
while running can use the CPU clocks:
struct timespec ts;
if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts) != 0)
fatal("cannot get CPU time");
/* result is in TS */
It's also possible to get a thread's CPU consumption. Use
CLOCK_THREAD_CPUTIME_ID in that case.
All this works as it should ever since Roland's clock patches landed,
in early 2.6 kernels. Before that the time returned did not discount
the time the process wasn't scheduled.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to find the CPU usage of a process
2006-02-18 18:55 ` Ulrich Drepper
@ 2006-02-18 19:27 ` Bernd Eckenfels
2006-02-18 20:15 ` Ulrich Drepper
0 siblings, 1 reply; 8+ messages in thread
From: Bernd Eckenfels @ 2006-02-18 19:27 UTC (permalink / raw)
To: linux-kernel
Ulrich Drepper <drepper@gmail.com> wrote:
> That's after the fact. Programs which want to get the information
> while running can use the CPU clocks:
>
> struct timespec ts;
> if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts) != 0)
> fatal("cannot get CPU time");
> /* result is in TS */
But thats only for yourself, right?
Gruss
Bernd
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to find the CPU usage of a process
2006-02-18 19:27 ` Bernd Eckenfels
@ 2006-02-18 20:15 ` Ulrich Drepper
0 siblings, 0 replies; 8+ messages in thread
From: Ulrich Drepper @ 2006-02-18 20:15 UTC (permalink / raw)
To: Bernd Eckenfels; +Cc: linux-kernel
On 2/18/06, Bernd Eckenfels <be-news06@lina.inka.de> wrote:
> But thats only for yourself, right?
In that abbreviated form, yes.
To get an arbitrary process' time use
clockid_t cl;
clock_getcpuclockid(pid, &cl);
struct timespec ts;
clock_gettime(cl, &ts);
This is all documented in POSIX.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to find the CPU usage of a process
2006-02-19 19:06 ` Chris Wedgwood
@ 2006-02-20 0:42 ` Irfan Habib
0 siblings, 0 replies; 8+ messages in thread
From: Irfan Habib @ 2006-02-20 0:42 UTC (permalink / raw)
To: Chris Wedgwood, linux-kernel
thank you very much for every one who replied.
It really helped me big times :)
On 2/20/06, Chris Wedgwood <cw@f00f.org> wrote:
> On Sat, Feb 18, 2006 at 09:42:29AM -0800, Irfan Habib wrote:
>
> > I wanted to ask how can I find the cpu usage of a process, as
> > opposed to runtime, with cpu usage I mean actually how many time
> > slices were awarded to a specific process, like the runtime of job
> > may be 4 s, but this also includes time it was suspended by some
> > interrupt, or had to wait for the scheduler etc..
>
> getrusage(2) or if it's not a child then grovel through /proc (i think
> there is an argument for a better interface)
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to find the CPU usage of a process
2006-02-18 17:42 Irfan Habib
@ 2006-02-19 19:06 ` Chris Wedgwood
2006-02-20 0:42 ` Irfan Habib
0 siblings, 1 reply; 8+ messages in thread
From: Chris Wedgwood @ 2006-02-19 19:06 UTC (permalink / raw)
To: Irfan Habib; +Cc: linux-kernel
On Sat, Feb 18, 2006 at 09:42:29AM -0800, Irfan Habib wrote:
> I wanted to ask how can I find the cpu usage of a process, as
> opposed to runtime, with cpu usage I mean actually how many time
> slices were awarded to a specific process, like the runtime of job
> may be 4 s, but this also includes time it was suspended by some
> interrupt, or had to wait for the scheduler etc..
getrusage(2) or if it's not a child then grovel through /proc (i think
there is an argument for a better interface)
^ permalink raw reply [flat|nested] 8+ messages in thread
* How to find the CPU usage of a process
@ 2006-02-18 17:42 Irfan Habib
2006-02-19 19:06 ` Chris Wedgwood
0 siblings, 1 reply; 8+ messages in thread
From: Irfan Habib @ 2006-02-18 17:42 UTC (permalink / raw)
To: linux-kernel
Hi,
I'm a research student, working on self-organizing
grids.
I wanted to ask how can I find the cpu usage of a
process, as opposed to runtime, with cpu usage I mean
actually how many time slices were awarded to a
specific process, like the runtime of job may be 4 s,
but this also includes time it was suspended by some
interrupt, or had to wait for the scheduler etc..
What is the easiest way to do that? is their any
userlevel tool for it?
Thanks in advance
Irfan Habib
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2006-02-20 0:42 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-18 17:42 How to find the CPU usage of a process Irfan Habib
2006-02-18 18:44 ` Bernd Eckenfels
2006-02-18 18:55 ` Ulrich Drepper
2006-02-18 19:27 ` Bernd Eckenfels
2006-02-18 20:15 ` Ulrich Drepper
2006-02-18 17:42 Irfan Habib
2006-02-19 19:06 ` Chris Wedgwood
2006-02-20 0:42 ` Irfan Habib
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®