[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <46D3FBDF.3080508@gmail.com>
Date: Tue, 28 Aug 2007 12:41:35 +0200
From: Luka Napotnik <luka.napotnik@...il.com>
To: Jan Engelhardt <jengelh@...putergmbh.de>
CC: "linux-os (Dick Johnson)" <linux-os@...logic.com>,
linux-kernel@...r.kernel.org
Subject: Re: division and cpu usage
How about this:
===============================
old_stime = task->stime;
old_utime = task->utime
old_j = jiffies;
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(1 * HZ);
new_stime = task->stime;
new_utime = task->utime;
new_j = jiffies;
sum = ((new_stime - old_stime) + (new_utime - old_utime)) * 100 / (new_j
- old_j)
===============================
I get how much time the task has spent in 1 sec in the scheduler and
then get the percentage?
Greets,
Luka
Jan Engelhardt pravi:
> On Aug 28 2007 00:07, Luka Napotnik wrote:
>>>>> 2. I'm trying to get the percentage of CPU used for a certain
>>>>> task_struct and figured the following formula:
>>>>>
>>>>> (task->utime + task->stime) / jiffies
>> This formula just doesn't work. I have a task with 99% CPU (top) but the
>> result of that formula is random (4, sometimes 8). What am I doing
>> wrong? Please help.
>
> You are calculating the CPU time the process has used since the start.
> That is definitely not the same as the "%CPU" that top shows, more like
> the "TIME+" top shows by default.
>
>
Download attachment "signature.asc" of type "application/pgp-signature" (253 bytes)
Powered by blists - more mailing lists