# CPU usage

**URL:** <https://community.unix.com/t/cpu-usage/277927>\
**Category:** Programming\
**Created:** [November 24, 2010, 10:54am UTC](https://community.unix.com/t/cpu-usage/277927 "2010-11-24T10:54:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dedalus](https://community.unix.com/letter_avatar/dedalus/32/5_5575768a8748004e209b776fc1b2916d.png) [@Dedalus](https://community.unix.com/u/Dedalus)\
**Post date:** [November 24, 2010, 10:54am UTC](https://community.unix.com/t/cpu-usage/277927/1 "2010-11-24T10:54:09Z")

</div>

Hi all,

I'm using python and psutil a library to get system informations like cpu usage (percent) for a given process.  
My question is if I have the value in % of the cpu usage how I could get the cpu usage in cycle number I mean not in percent?

Thanks a lot

D.

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/5_5575768a8748004e209b776fc1b2916d.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [November 24, 2010, 11:11am UTC](https://community.unix.com/t/cpu-usage/277927/2 "2010-11-24T11:11:12Z")

</div>

What does 'cycle number' even mean on a modern machine where different instructions take a different number of cycles and the CPU clock speed itself may vary over time?

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/5_5575768a8748004e209b776fc1b2916d.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [November 24, 2010, 11:22am UTC](https://community.unix.com/t/cpu-usage/277927/3 "2010-11-24T11:22:26Z")

</div>

Try psutil.process get\_cpu\_times which returns a tuple.

You can then get the sum of cpu speed x each element of the tuple. That gives you cycles. psutil does not return cpu speed AFAIK or so the docset says. You can read the /proc/cpuinfo "file" on linux to get that information.

---

<div class="post-metadata">

**Author:** ![Dedalus](https://community.unix.com/letter_avatar/dedalus/32/5_5575768a8748004e209b776fc1b2916d.png) [@Dedalus](https://community.unix.com/u/Dedalus)\
**Post date:** [November 24, 2010, 11:22am UTC](https://community.unix.com/t/cpu-usage/277927/4 "2010-11-24T11:22:39Z")

</div>

yea sorry,

I meant that I would like to evaluate the load that a given process bring to the CPU but not in percent.  
I'm giving a look around and found that I should refer to user time, system time, start time and current time for the given process and use:

```nohighlight
(user-time+system-time)/(current time - start time)

```

D.

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/5_5575768a8748004e209b776fc1b2916d.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [November 24, 2010, 11:23am UTC](https://community.unix.com/t/cpu-usage/277927/5 "2010-11-24T11:23:22Z")

</div>

@corona - I think the OP wants a generalized solution - your comment is completely correct, however.

---

<div class="post-metadata">

**Author:** ![Dedalus](https://community.unix.com/letter_avatar/dedalus/32/5_5575768a8748004e209b776fc1b2916d.png) [@Dedalus](https://community.unix.com/u/Dedalus)\
**Post date:** [November 24, 2010, 11:23am UTC](https://community.unix.com/t/cpu-usage/277927/6 "2010-11-24T11:23:54Z")

</div>

I'll do

Thanks for help

D.
