Re: [psutil] Supporting stolen time on psutil.cpu_times()

54 views
Skip to first unread message

Giampaolo Rodolà

unread,
Mar 25, 2013, 8:57:15 AM3/25/13
to psu...@googlegroups.com
This seems reasonable, also because now that I think of it
psutil.cpu_percent() is currently not taking them into account, and
that means that the CPU percentage we're getting is not accurate.
I filed an issue here:
https://code.google.com/p/psutil/issues/detail?id=361
Will fix it soon.

2013/3/23 André Oriani <aor...@gmail.com>:
>
> Hi,
>
> In Master degree project I was using psutil to collect performance metric.
> Since I was running the experiments on Amazon EC2, I also need to know th
> impact of virtualization. So I hacked psutil to get the cpu stolen time. I'm
> sharing the changes I did. Trivial changes BTW.
>
>
> Proc man file talk about two new columns to /proc/stat
> "Since Linux 2.6.11, there is an eighth column, steal - stolen time, which
> is the time spent in other operating systems when running in a virtualized
> environment
> Since Linux 2.6.24, there is a ninth column, guest, which is the time spent
> running a virtual CPU for guest operating systems under the control of the
> Linux kernel."
>
> I only implemented the first as it was what I needed and my kernel
> supported. But I think a better implementation would check the kernel
> version first.
>
>
> Regards,
> André Oriani
>
>
> diff -r dfd6641057c8 psutil/_common.py
> --- a/psutil/_common.py Tue Mar 19 15:07:23 2013 +0100
> +++ b/psutil/_common.py Sat Mar 23 15:38:26 2013 -0300
> @@ -169,7 +169,7 @@
> # --- namedtuples
>
> # system
> -nt_sys_cputimes = namedtuple('cputimes', 'user nice system idle iowait irq
> softirq')
> +nt_sys_cputimes = namedtuple('cputimes', 'user nice system idle iowait irq
> softirq steal')
> nt_sysmeminfo = namedtuple('usage', 'total used free percent')
> # XXX - would 'available' be better than 'free' as for virtual_memory() nt?
> nt_swapmeminfo = namedtuple('swap', 'total used free percent sin sout')
> diff -r dfd6641057c8 psutil/_pslinux.py
> --- a/psutil/_pslinux.py Tue Mar 19 15:07:23 2013 +0100
> +++ b/psutil/_pslinux.py Sat Mar 23 15:38:26 2013 -0300
> @@ -216,9 +216,9 @@
> finally:
> f.close()
>
> - values = values[1:8]
> + values = values[1:9]
> values = tuple([float(x) / _CLOCK_TICKS for x in values])
> - return nt_sys_cputimes(*values[:7])
> + return nt_sys_cputimes(*values[:8])
>
> def get_system_per_cpu_times():
> """Return a list of namedtuple representing the CPU times
> @@ -231,9 +231,9 @@
> f.readline()
> for line in f.readlines():
> if line.startswith('cpu'):
> - values = line.split()[1:8]
> + values = line.split()[1:9]
> values = tuple([float(x) / _CLOCK_TICKS for x in values])
> - entry = nt_sys_cputimes(*values[:7])
> + entry = nt_sys_cputimes(*values[:8])
> cpus.append(entry)
> return cpus
> finally:
>
> --
> --
> You received this message because you are subscribed to the "Python process
> utilities (psutil)" project group:
> http://code.google.com/p/psutil
> To post to this group, send email to psu...@googlegroups.com
> To unsubscribe from this group, send email to
> psutil-un...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/psutil
> ---
> You received this message because you are subscribed to the Google Groups
> "psutil" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to psutil+un...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Giampaolo Rodolà

unread,
Mar 25, 2013, 9:40:47 AM3/25/13
to psu...@googlegroups.com
This is now fixed as of
https://code.google.com/p/psutil/source/detail?r=563562aba003
I plan to release a 0.6.2 version soon (less than a month).
Thanks.

2013/3/25 Giampaolo Rodolà <g.ro...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages