ia64/xen-unstable

changeset 7934:f5dafee503ba

This patch is to fix a few performance "bugs" in the xenmon.py script.
No functionality is added or removed. Tested on x86/32 smp and x86/64.

Signed-off-by: Rob Gardner <rob.gardner@hp.com>
author kaf24@firebug.cl.cam.ac.uk
date Sat Nov 19 10:29:28 2005 +0100 (2005-11-19)
parents 5c7d103efb99
children cc1d77bba4b0
files tools/xenmon/xenmon.py
line diff
     1.1 --- a/tools/xenmon/xenmon.py	Sat Nov 19 10:28:24 2005 +0100
     1.2 +++ b/tools/xenmon/xenmon.py	Sat Nov 19 10:29:28 2005 +0100
     1.3 @@ -58,6 +58,8 @@ IOCOUNT = "I/O Count"
     1.4  EXCOUNT = "Exec Count"
     1.5  
     1.6  # globals
     1.7 +dom_in_use = []
     1.8 +
     1.9  # our curses screen
    1.10  stdscr = None
    1.11  
    1.12 @@ -88,18 +90,18 @@ def setup_cmdline_parser():
    1.13  # encapsulate information about a domain
    1.14  class DomainInfo:
    1.15      def __init__(self):
    1.16 -        self.allocated_samples = []
    1.17 -        self.gotten_samples = []
    1.18 -        self.blocked_samples = []
    1.19 -        self.waited_samples = []
    1.20 -        self.execcount_samples = []
    1.21 -        self.iocount_samples = []
    1.22 +        self.allocated_sum = 0
    1.23 +        self.gotten_sum = 0
    1.24 +        self.blocked_sum = 0
    1.25 +        self.waited_sum = 0
    1.26 +        self.exec_count = 0;
    1.27 +        self.iocount_sum = 0
    1.28          self.ffp_samples = []
    1.29  
    1.30      def gotten_stats(self, passed):
    1.31 -        total = float(sum(self.gotten_samples))
    1.32 +        total = float(self.gotten_sum)
    1.33          per = 100*total/passed
    1.34 -        exs = sum(self.execcount_samples)
    1.35 +        exs = self.exec_count
    1.36          if exs > 0:
    1.37              avg = total/exs
    1.38          else:
    1.39 @@ -107,9 +109,9 @@ class DomainInfo:
    1.40          return [total/(float(passed)/10**9), per, avg]
    1.41  
    1.42      def waited_stats(self, passed):
    1.43 -        total = float(sum(self.waited_samples))
    1.44 +        total = float(self.waited_sum)
    1.45          per = 100*total/passed
    1.46 -        exs = sum(self.execcount_samples)
    1.47 +        exs = self.exec_count
    1.48          if exs > 0:
    1.49              avg = total/exs
    1.50          else:
    1.51 @@ -117,9 +119,9 @@ class DomainInfo:
    1.52          return [total/(float(passed)/10**9), per, avg]
    1.53  
    1.54      def blocked_stats(self, passed):
    1.55 -        total = float(sum(self.blocked_samples))
    1.56 +        total = float(self.blocked_sum)
    1.57          per = 100*total/passed
    1.58 -        ios = sum(self.iocount_samples)
    1.59 +        ios = self.iocount_sum
    1.60          if ios > 0:
    1.61              avg = total/float(ios)
    1.62          else:
    1.63 @@ -127,20 +129,20 @@ class DomainInfo:
    1.64          return [total/(float(passed)/10**9), per, avg]
    1.65  
    1.66      def allocated_stats(self, passed):
    1.67 -        total = sum(self.allocated_samples)
    1.68 -        exs = sum(self.execcount_samples)
    1.69 +        total = self.allocated_sum
    1.70 +        exs = self.exec_count
    1.71          if exs > 0:
    1.72              return float(total)/exs
    1.73          else:
    1.74              return 0
    1.75  
    1.76      def ec_stats(self, passed):
    1.77 -        total = float(sum(self.execcount_samples))/(float(passed)/10**9)
    1.78 -        return total
    1.79 +        total = float(self.exec_count/(float(passed)/10**9))
    1.80 +	return total
    1.81  
    1.82      def io_stats(self, passed):
    1.83 -        total = float(sum(self.iocount_samples))
    1.84 -        exs = sum(self.execcount_samples)
    1.85 +        total = float(self.iocount_sum)
    1.86 +        exs = self.exec_count
    1.87          if exs > 0:
    1.88              avg = total/exs
    1.89          else:
    1.90 @@ -165,12 +167,13 @@ def summarize(startat, endat, duration, 
    1.91      
    1.92      while passed < duration:
    1.93          for i in range(0, NDOMAINS):
    1.94 -            dominfos[i].gotten_samples.append(samples[curid][0*NDOMAINS + i])
    1.95 -            dominfos[i].allocated_samples.append(samples[curid][1*NDOMAINS + i])
    1.96 -            dominfos[i].waited_samples.append(samples[curid][2*NDOMAINS + i])
    1.97 -            dominfos[i].blocked_samples.append(samples[curid][3*NDOMAINS + i])
    1.98 -            dominfos[i].execcount_samples.append(samples[curid][4*NDOMAINS + i])
    1.99 -            dominfos[i].iocount_samples.append(samples[curid][5*NDOMAINS + i])
   1.100 +            if dom_in_use[i]:
   1.101 +                dominfos[i].gotten_sum += samples[curid][0*NDOMAINS + i]
   1.102 +                dominfos[i].allocated_sum += samples[curid][1*NDOMAINS + i]
   1.103 +                dominfos[i].waited_sum += samples[curid][2*NDOMAINS + i]
   1.104 +                dominfos[i].blocked_sum += samples[curid][3*NDOMAINS + i]
   1.105 +                dominfos[i].exec_count += samples[curid][4*NDOMAINS + i]
   1.106 +                dominfos[i].iocount_sum += samples[curid][5*NDOMAINS + i]
   1.107      
   1.108          passed += samples[curid][6*NDOMAINS]
   1.109          lost_samples.append(samples[curid][6*NDOMAINS + 2])
   1.110 @@ -187,7 +190,13 @@ def summarize(startat, endat, duration, 
   1.111  
   1.112      lostinfo = [min(lost_samples), sum(lost_samples), max(lost_samples)]
   1.113      ffpinfo = [min(ffp_samples), sum(ffp_samples), max(ffp_samples)]
   1.114 -    ldoms = map(lambda x: dominfos[x].stats(passed), range(0, NDOMAINS))
   1.115 +
   1.116 +    ldoms = []
   1.117 +    for x in range(0, NDOMAINS):
   1.118 +        if dom_in_use[x]:
   1.119 +            ldoms.append(dominfos[x].stats(passed))
   1.120 +        else:
   1.121 +            ldoms.append(0)
   1.122  
   1.123      return [ldoms, lostinfo, ffpinfo]
   1.124  
   1.125 @@ -222,6 +231,7 @@ def show_livestats():
   1.126      cpu = 0          # cpu of interest to display data for
   1.127      ncpu = 1         # number of cpu's on this platform
   1.128      slen = 0         # size of shared data structure, incuding padding
   1.129 +    global dom_in_use
   1.130      
   1.131      # mmap the (the first chunk of the) file
   1.132      shmf = open(SHM_FILE, "r+")
   1.133 @@ -229,6 +239,7 @@ def show_livestats():
   1.134  
   1.135      samples = []
   1.136      doms = []
   1.137 +    dom_in_use = []
   1.138  
   1.139      # initialize curses
   1.140      stdscr = _c.initscr()
   1.141 @@ -238,9 +249,7 @@ def show_livestats():
   1.142      stdscr.keypad(1)
   1.143      stdscr.timeout(1000)
   1.144      [maxy, maxx] = stdscr.getmaxyx()
   1.145 -
   1.146      
   1.147 -
   1.148      # display in a loop
   1.149      while True:
   1.150  
   1.151 @@ -264,6 +273,11 @@ def show_livestats():
   1.152                  len = struct.calcsize(ST_DOM_INFO)
   1.153                  dom = struct.unpack(ST_DOM_INFO, shm[idx:idx+len])
   1.154                  doms.append(dom)
   1.155 +#		(last_update_time, start_time, runnable_start_time, blocked_start_time,
   1.156 +#		 ns_since_boot, ns_oncpu_since_boot, runnable_at_last_update,
   1.157 +#		 runnable, in_use, domid, name) = dom
   1.158 +#		dom_in_use.append(in_use)
   1.159 +                dom_in_use.append(dom[8])
   1.160                  idx += len
   1.161  
   1.162              len = struct.calcsize("4i")
   1.163 @@ -293,6 +307,7 @@ def show_livestats():
   1.164          [h1, l1, f1] = summarize(startat, endat, 10**9, samples)
   1.165          [h2, l2, f2] = summarize(startat, endat, 10 * 10**9, samples)
   1.166  
   1.167 +
   1.168          # the actual display code
   1.169          row = 0
   1.170          display(stdscr, row, 1, "CPU = %d" % cpu, _c.A_STANDOUT)
   1.171 @@ -305,6 +320,9 @@ def show_livestats():
   1.172          total_h2_cpu = 0
   1.173  
   1.174          for dom in range(0, NDOMAINS):
   1.175 +            if not dom_in_use[dom]:
   1.176 +                continue
   1.177 +
   1.178              if h1[dom][0][1] > 0 or dom == NDOMAINS - 1:
   1.179                  # display gotten
   1.180                  row += 1 
   1.181 @@ -475,6 +493,7 @@ class Delayed(file):
   1.182  
   1.183  def writelog():
   1.184      global options
   1.185 +    global dom_in_use
   1.186  
   1.187      ncpu = 1        # number of cpu's
   1.188      slen = 0        # size of shared structure inc. padding
   1.189 @@ -490,11 +509,13 @@ def writelog():
   1.190  
   1.191      while options.duration == 0 or interval < (options.duration * 1000):
   1.192          for cpuidx in range(0, ncpu):
   1.193 +
   1.194              idx = cpuidx * slen      # offset needed in mmap file
   1.195  
   1.196  
   1.197              samples = []
   1.198              doms = []
   1.199 +            dom_in_use = []
   1.200  
   1.201              for i in range(0, NSAMPLES):
   1.202                  len = struct.calcsize(ST_QDATA)
   1.203 @@ -505,7 +526,11 @@ def writelog():
   1.204              for i in range(0, NDOMAINS):
   1.205                  len = struct.calcsize(ST_DOM_INFO)
   1.206                  dom = struct.unpack(ST_DOM_INFO, shm[idx:idx+len])
   1.207 -                doms.append(dom)
   1.208 +#                doms.append(dom)
   1.209 +#		(last_update_time, start_time, runnable_start_time, blocked_start_time,
   1.210 +#		 ns_since_boot, ns_oncpu_since_boot, runnable_at_last_update,
   1.211 +#		 runnable, in_use, domid, name) = dom
   1.212 +                dom_in_use.append(dom[8])
   1.213                  idx += len
   1.214  
   1.215              len = struct.calcsize("4i")
   1.216 @@ -524,6 +549,8 @@ def writelog():
   1.217  
   1.218              [h1,l1, f1] = summarize(startat, endat, options.interval * 10**6, samples)
   1.219              for dom in range(0, NDOMAINS):
   1.220 +                if not dom_in_use[dom]:
   1.221 +                    continue
   1.222                  if h1[dom][0][1] > 0 or dom == NDOMAINS - 1:
   1.223                      outfiles[dom].write("%.3f %d %d %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f\n" %
   1.224                                       (interval, cpuidx, dom,