* How to get cpu utilization through code with least overhead?
@ 2011-07-28 17:38 Vaibhav Jain
2011-07-28 17:45 ` Mulyadi Santosa
0 siblings, 1 reply; 7+ messages in thread
From: Vaibhav Jain @ 2011-07-28 17:38 UTC (permalink / raw)
To: kernelnewbies
Hi,
I need to write code to get and record the cpu utilization in certain
interval with the least overhead.
Could anybody please advise me on how to proceed ? I tried looking at the
code for "top" command to see
how it works but couldn't figure out much.
I don't want to write script that uses commands and pulls out the results as
I want the overhead to be as small as possible.
Thanks
Vaibhav Jain
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110728/b6cc95da/attachment.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* How to get cpu utilization through code with least overhead?
2011-07-28 17:38 How to get cpu utilization through code with least overhead? Vaibhav Jain
@ 2011-07-28 17:45 ` Mulyadi Santosa
2011-07-28 17:51 ` Vaibhav Jain
0 siblings, 1 reply; 7+ messages in thread
From: Mulyadi Santosa @ 2011-07-28 17:45 UTC (permalink / raw)
To: kernelnewbies
On Fri, Jul 29, 2011 at 00:38, Vaibhav Jain <vjoss197@gmail.com> wrote:
> Hi,
>
> I need to write code to get and record the cpu utilization in certain
> interval with the least overhead.
try to derive them from /proc/loadavg or /proc/stat...
--
regards,
Mulyadi Santosa
Freelance Linux trainer and consultant
blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* How to get cpu utilization through code with least overhead?
2011-07-28 17:45 ` Mulyadi Santosa
@ 2011-07-28 17:51 ` Vaibhav Jain
2011-07-28 23:56 ` Vaibhav Jain
0 siblings, 1 reply; 7+ messages in thread
From: Vaibhav Jain @ 2011-07-28 17:51 UTC (permalink / raw)
To: kernelnewbies
Thanks! Just curious to know if this is how "top" does it.
Thanks
Vaibhav Jain
On Thu, Jul 28, 2011 at 10:45 AM, Mulyadi Santosa <mulyadi.santosa@gmail.com
> wrote:
> On Fri, Jul 29, 2011 at 00:38, Vaibhav Jain <vjoss197@gmail.com> wrote:
> > Hi,
> >
> > I need to write code to get and record the cpu utilization in certain
> > interval with the least overhead.
>
> try to derive them from /proc/loadavg or /proc/stat...
>
> --
> regards,
>
> Mulyadi Santosa
> Freelance Linux trainer and consultant
>
> blog: the-hydra.blogspot.com
> training: mulyaditraining.blogspot.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110728/484b3c5c/attachment.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* How to get cpu utilization through code with least overhead?
2011-07-28 17:51 ` Vaibhav Jain
@ 2011-07-28 23:56 ` Vaibhav Jain
2011-07-29 0:30 ` Raghu Udiyar
2011-07-29 19:15 ` Jonathan Neuschäfer
0 siblings, 2 replies; 7+ messages in thread
From: Vaibhav Jain @ 2011-07-28 23:56 UTC (permalink / raw)
To: kernelnewbies
Hi,
Is there any other way to do this? If I need to write a kernel module that
needs to get cpu utilization
should I still use proc/stat ? Is there a kernel function that can be used
in a module ?
Thanks
Vaibhav Jain
On Thu, Jul 28, 2011 at 10:51 AM, Vaibhav Jain <vjoss197@gmail.com> wrote:
> Thanks! Just curious to know if this is how "top" does it.
>
> Thanks
> Vaibhav Jain
>
> On Thu, Jul 28, 2011 at 10:45 AM, Mulyadi Santosa <
> mulyadi.santosa at gmail.com> wrote:
>
>> On Fri, Jul 29, 2011 at 00:38, Vaibhav Jain <vjoss197@gmail.com> wrote:
>> > Hi,
>> >
>> > I need to write code to get and record the cpu utilization in certain
>> > interval with the least overhead.
>>
>> try to derive them from /proc/loadavg or /proc/stat...
>>
>> --
>> regards,
>>
>> Mulyadi Santosa
>> Freelance Linux trainer and consultant
>>
>> blog: the-hydra.blogspot.com
>> training: mulyaditraining.blogspot.com
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110728/05531af9/attachment.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* How to get cpu utilization through code with least overhead?
2011-07-28 23:56 ` Vaibhav Jain
@ 2011-07-29 0:30 ` Raghu Udiyar
2011-07-29 19:15 ` Jonathan Neuschäfer
1 sibling, 0 replies; 7+ messages in thread
From: Raghu Udiyar @ 2011-07-29 0:30 UTC (permalink / raw)
To: kernelnewbies
On Fri, Jul 29, 2011 at 5:26 AM, Vaibhav Jain <vjoss197@gmail.com> wrote:
> Hi,
>
> Is there any other way to do this? If I need to write a kernel module that
> needs to get cpu utilization
> should I still use proc/stat ? Is there a kernel function that can be used
> in a module ?
>
> Thanks
> Vaibhav Jain
>
The kernel writes all cpu metrics and more to /proc/stat. I/O data goes to
/proc/diskstat and memory to /proc/vmstat. Top and other tools interpret
the counters written to these files.
You can also look at hardware performance counters, as used by the perf
utility.
--
Raghu S Udiyar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110729/31a1d71a/attachment.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* How to get cpu utilization through code with least overhead?
2011-07-28 23:56 ` Vaibhav Jain
2011-07-29 0:30 ` Raghu Udiyar
@ 2011-07-29 19:15 ` Jonathan Neuschäfer
2011-07-30 16:29 ` Vaibhav Jain
1 sibling, 1 reply; 7+ messages in thread
From: Jonathan Neuschäfer @ 2011-07-29 19:15 UTC (permalink / raw)
To: kernelnewbies
On Thu, Jul 28, 2011 at 04:56:16PM -0700, Vaibhav Jain wrote:
> Hi,
>
> Is there any other way to do this? If I need to write a kernel module that
> needs to get cpu utilization
> should I still use proc/stat ? Is there a kernel function that can be used
> in a module ?
To get the information that's shown in /proc/stat, I'd suggest having a
look at fs/proc/stat.c in the kernel tree.
HTH,
Jonathan Neusch?fer
^ permalink raw reply [flat|nested] 7+ messages in thread
* How to get cpu utilization through code with least overhead?
2011-07-29 19:15 ` Jonathan Neuschäfer
@ 2011-07-30 16:29 ` Vaibhav Jain
0 siblings, 0 replies; 7+ messages in thread
From: Vaibhav Jain @ 2011-07-30 16:29 UTC (permalink / raw)
To: kernelnewbies
Thanks !!
I looked at the code for top command again and I could see /proc/stat being
used. So I guess
that should be the best way to do it.
On Fri, Jul 29, 2011 at 12:15 PM, Jonathan Neusch?fer <j.neuschaefer@gmx.net
> wrote:
> On Thu, Jul 28, 2011 at 04:56:16PM -0700, Vaibhav Jain wrote:
> > Hi,
> >
> > Is there any other way to do this? If I need to write a kernel module
> that
> > needs to get cpu utilization
> > should I still use proc/stat ? Is there a kernel function that can be
> used
> > in a module ?
>
> To get the information that's shown in /proc/stat, I'd suggest having a
> look at fs/proc/stat.c in the kernel tree.
>
> HTH,
> Jonathan Neusch?fer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110730/b9b4cbb6/attachment.html
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-07-30 16:29 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-28 17:38 How to get cpu utilization through code with least overhead? Vaibhav Jain
2011-07-28 17:45 ` Mulyadi Santosa
2011-07-28 17:51 ` Vaibhav Jain
2011-07-28 23:56 ` Vaibhav Jain
2011-07-29 0:30 ` Raghu Udiyar
2011-07-29 19:15 ` Jonathan Neuschäfer
2011-07-30 16:29 ` Vaibhav Jain
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.