WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-users

Re: [Xen-users] Measuring overall CPU utlization

On Wed, 2006-04-26 at 14:07 -0700, Diwaker Gupta wrote:
> > <snip>
> > I'm sorry; I should have specified that I am running Xen 2.0.7.  I do
> > not see or have a xm top command.  What do I do in 2.0.7?
> 
> This works for me in Xen 2.0.7 (or you can write a wrapper around 'xm
> list'). This is not guaranteed to be correct/accurate -- you at your
> own risk :-) :
> 
> ====================================
> import sys
> import curses
> import curses.ascii
> import time
> 
> sys.path.append('/usr/lib/python')
> import xen.lowlevel.xc
> 
> xc = xen.lowlevel.xc.new()
> 
> # initialize curses
> stdscr = curses.initscr()
> curses.noecho()
> curses.cbreak()
> stdscr.keypad(1)
> 
> # timeout getch after 1s
> stdscr.timeout(1000)
> 
> (maxy, maxx) = stdscr.getmaxyx()
> 
> vtop_start = time.time()
> first_run = True
> 
> shares = {}
> while True:
>     # sleep for 1 second
>     # between outputs
>     dlist = xc.domain_getinfo()
>     idx = 1
>     cpusum=0
>     if first_run:
>         for d in dlist:
>             shares[d['dom']] = d['cpu_time']
>         first_run = False
>     else:
>         for d in dlist:
>             now = time.time()
>             share = d['cpu_time'] - shares[d['dom']]
>             p = (share*100)/((now - vtop_start) * 10**9)
>             cpusum+=p
>             stdscr.addstr(idx, 1, "%d\t\t%d\t\t%.2f" % (d['dom'], d['cpu'], 
> p))
>             idx += 1
> 
>     stdscr.addstr(idx, 1, "\t\t\t\t%.2f" % cpusum)
>     idx += 1
>     c = stdscr.getch()
>     # quit on q
>     if c == ord('q'):
>         break
>     stdscr.erase()
>     stdscr.refresh()
> 
> curses.nocbreak()
> stdscr.keypad(0)
> curses.echo()
> curses.endwin()
<snip>
That looks like it's working.  Thanks! - John
-- 
John A. Sullivan III
Open Source Development Corporation
+1 207-985-7880
jsullivan@xxxxxxxxxxxxxxxxxxx

Financially sustainable open source development
http://www.opensourcedevel.com


_______________________________________________
Xen-users mailing list
Xen-users@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-users