Re: division and cpu usage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.
> 
> 


Attachment: signature.asc
Description: OpenPGP digital signature


[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux