<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[12909] CalendarServer/trunk/calendarserver/tools/dashboard.py</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/12909">12909</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2014-03-14 07:49:49 -0700 (Fri, 14 Mar 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Refactor to do only one server socket read for all windows. Add request status window.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkcalendarservertoolsdashboardpy">CalendarServer/trunk/calendarserver/tools/dashboard.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkcalendarservertoolsdashboardpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tools/dashboard.py (12908 => 12909)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tools/dashboard.py        2014-03-14 14:48:21 UTC (rev 12908)
+++ CalendarServer/trunk/calendarserver/tools/dashboard.py        2014-03-14 14:49:49 UTC (rev 12909)
</span><span class="lines">@@ -81,6 +81,7 @@
</span><span class="cx">         def _wrapped(stdscrn):
</span><span class="cx">             curses.curs_set(0)
</span><span class="cx">             curses.use_default_colors()
</span><ins>+            curses.init_pair(1, curses.COLOR_RED, curses.COLOR_WHITE)
</ins><span class="cx">             d = Dashboard(stdscrn, True)
</span><span class="cx">             d.run()
</span><span class="cx">         curses.wrapper(_wrapped)
</span><span class="lines">@@ -90,6 +91,11 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+def safeDivision(value, total, factor=1):
+    return value * factor / total if total else 0
+
+
+
</ins><span class="cx"> class Dashboard(object):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Main dashboard controller. Use Python's L{sched} feature to schedule
</span><span class="lines">@@ -98,13 +104,15 @@
</span><span class="cx"> 
</span><span class="cx">     screen = None
</span><span class="cx">     registered_windows = {}
</span><ins>+    registered_order = []
</ins><span class="cx"> 
</span><span class="cx">     def __init__(self, screen, usesCurses):
</span><span class="cx">         self.screen = screen
</span><span class="cx">         self.usesCurses = usesCurses
</span><span class="cx">         self.paused = False
</span><del>-        self.seconds = 0.1
</del><ins>+        self.seconds = 0.1 if usesCurses else 1.0
</ins><span class="cx">         self.sched = sched.scheduler(time.time, time.sleep)
</span><ins>+        self.client = DashboardClient((&quot;localhost&quot;, 8100), True)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classmethod
</span><span class="lines">@@ -116,6 +124,7 @@
</span><span class="cx">         available window type.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         cls.registered_windows[keypress] = wtype
</span><ins>+        cls.registered_order.append(keypress)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def run(self):
</span><span class="lines">@@ -124,7 +133,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         self.windows = []
</span><span class="cx">         self.displayWindow(None)
</span><del>-        self.sched.enter(0, 0, self.updateDisplay, ())
</del><ins>+        self.sched.enter(self.seconds, 0, self.updateDisplay, ())
</ins><span class="cx">         self.sched.run()
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -134,30 +143,33 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         if self.windows:
</span><span class="cx">             for window in self.windows:
</span><del>-                window.clear()
</del><ins>+                window.deactivate()
</ins><span class="cx">             self.windows = []
</span><span class="cx"> 
</span><span class="cx">         if wtype is not None:
</span><del>-            self.windows.append(wtype(self.usesCurses).makeWindow())
-            self.windows[-1].update()
</del><ins>+            self.windows.append(wtype(self.usesCurses, self.client).makeWindow())
+            self.windows[-1].activate()
</ins><span class="cx">         else:
</span><span class="cx">             top = 0
</span><del>-            for wtype in filter(
-                lambda x: x.all, self.registered_windows.values()
-            ):
-                self.windows.append(wtype(self.usesCurses).makeWindow(top=top))
-                self.windows[-1].update()
-                top += self.windows[-1].nlines
</del><ins>+            ordered_windows = [self.registered_windows[i] for i in self.registered_order]
+            for wtype in filter(lambda x: x.all, ordered_windows):
+                self.windows.append(wtype(self.usesCurses, self.client).makeWindow(top=top))
+                self.windows[-1].activate()
+                top += self.windows[-1].nlines + 1
</ins><span class="cx"> 
</span><ins>+        self.updateDisplay(True)
</ins><span class="cx"> 
</span><del>-    def updateDisplay(self):
</del><ins>+
+    def updateDisplay(self, initialUpdate=False):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Periodic update of the current window and check for a key press.
</span><span class="cx">         &quot;&quot;&quot;
</span><ins>+        self.client.update()
</ins><span class="cx">         try:
</span><del>-            if not self.paused:
</del><ins>+            if not self.paused or initialUpdate:
</ins><span class="cx">                 for window in filter(
</span><del>-                    lambda x: x.requiresUpdate(), self.windows
</del><ins>+                    lambda x: x.requiresUpdate() or initialUpdate,
+                    self.windows
</ins><span class="cx">                 ):
</span><span class="cx">                     window.update()
</span><span class="cx">         except Exception as e:
</span><span class="lines">@@ -182,10 +194,82 @@
</span><span class="cx">             elif c in self.registered_windows:
</span><span class="cx">                 self.displayWindow(self.registered_windows[c])
</span><span class="cx"> 
</span><del>-        self.sched.enter(self.seconds, 0, self.updateDisplay, ())
</del><ins>+        if not initialUpdate:
+            self.sched.enter(self.seconds, 0, self.updateDisplay, ())
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+class DashboardClient(object):
+    &quot;&quot;&quot;
+    Client that connects to a server and fetches information.
+    &quot;&quot;&quot;
+
+    def __init__(self, sockname, useTCP):
+        self.socket = None
+        self.sockname = sockname
+        self.useTCP = useTCP
+        self.currentData = None
+        self.items = []
+
+
+    def readSock(self, items):
+        &quot;&quot;&quot;
+        Open a socket, send the specified request, and retrieve the response. Keep the socket open.
+        &quot;&quot;&quot;
+        try:
+            if self.socket is None:
+                self.socket = socket.socket(socket.AF_INET if self.useTCP else socket.AF_UNIX, socket.SOCK_STREAM)
+                self.socket.connect(self.sockname)
+                self.socket.setblocking(0)
+            self.socket.sendall(json.dumps(items) + &quot;\r\n&quot;)
+            data = &quot;&quot;
+            while not data.endswith(&quot;\n&quot;):
+                try:
+                    d = self.socket.recv(1024)
+                except socket.error as se:
+                    if se.args[0] != errno.EWOULDBLOCK:
+                        raise
+                    continue
+                if d:
+                    data += d
+                else:
+                    break
+            data = json.loads(data)
+        except socket.error as e:
+            data = {&quot;Failed&quot;: &quot;Unable to read statistics from server: %s %s&quot; % (self.sockname, e)}
+            self.socket = None
+        return data
+
+
+    def update(self):
+        &quot;&quot;&quot;
+        Update the current data from the server.
+        &quot;&quot;&quot;
+        self.currentData = self.readSock(self.items)
+
+
+    def getOneItem(self, item):
+        &quot;&quot;&quot;
+        Update the current data from the server.
+        &quot;&quot;&quot;
+        return self.readSock([item])[item]
+
+
+    def addItem(self, item):
+        &quot;&quot;&quot;
+        Add a server data item to monitor.
+        &quot;&quot;&quot;
+        self.items.append(item)
+
+
+    def removeItem(self, item):
+        &quot;&quot;&quot;
+        No need to monitor this item.
+        &quot;&quot;&quot;
+        self.items.remove(item)
+
+
+
</ins><span class="cx"> class BaseWindow(object):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Common behavior for window types.
</span><span class="lines">@@ -193,9 +277,11 @@
</span><span class="cx"> 
</span><span class="cx">     help = &quot;Not Implemented&quot;
</span><span class="cx">     all = True
</span><ins>+    clientItem = None
</ins><span class="cx"> 
</span><del>-    def __init__(self, usesCurses):
</del><ins>+    def __init__(self, usesCurses, client):
</ins><span class="cx">         self.usesCurses = usesCurses
</span><ins>+        self.client = client
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def makeWindow(self, top=0, left=0):
</span><span class="lines">@@ -229,10 +315,20 @@
</span><span class="cx">         return True
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def clear(self):
</del><ins>+    def activate(self):
</ins><span class="cx">         &quot;&quot;&quot;
</span><ins>+        About to start displaying.
+        &quot;&quot;&quot;
+        if self.clientItem:
+            self.client.addItem(self.clientItem)
+
+
+    def deactivate(self):
+        &quot;&quot;&quot;
</ins><span class="cx">         Clear any drawing done by the current window type.
</span><span class="cx">         &quot;&quot;&quot;
</span><ins>+        if self.clientItem:
+            self.client.removeItem(self.clientItem)
</ins><span class="cx">         if self.usesCurses:
</span><span class="cx">             self.window.erase()
</span><span class="cx">             self.window.refresh()
</span><span class="lines">@@ -245,58 +341,15 @@
</span><span class="cx">         raise NotImplementedError()
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def clientData(self):
+        return self.client.currentData[self.clientItem]
</ins><span class="cx"> 
</span><del>-class BaseSocketWindow(BaseWindow):
-    &quot;&quot;&quot;
-    Common behavior for a window that reads from the server's stats socket.
-    &quot;&quot;&quot;
</del><span class="cx"> 
</span><del>-    def __init__(self, usesCurses):
-        super(BaseSocketWindow, self).__init__(usesCurses)
-        self.socket = None
-        self.sockname = (&quot;localhost&quot;, 8100)
-        self.useTCP = True
</del><ins>+    def readItem(self, item):
+        return self.client.getOneItem(item)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def readSock(self, item):
-        &quot;&quot;&quot;
-        Open a socket, send the specified request, and retrieve the response.
-        Keep the socket open.
-        &quot;&quot;&quot;
-        try:
-            if self.socket is None:
-                if self.useTCP:
-                    self.socket = socket.socket(socket.AF_INET)
-                else:
-                    self.socket = socket.socket(
-                        socket.AF_UNIX, socket.SOCK_STREAM
-                    )
-                self.socket.connect(self.sockname)
-                self.socket.setblocking(0)
-            self.socket.sendall(json.dumps([item]) + &quot;\r\n&quot;)
-            data = &quot;&quot;
-            while not data.endswith(&quot;\n&quot;):
-                try:
-                    d = self.socket.recv(1024)
-                except socket.error as se:
-                    if se.args[0] != errno.EWOULDBLOCK:
-                        raise
-                    continue
-                if d:
-                    data += d
-                else:
-                    break
-            data = json.loads(data)[item]
-        except socket.error as e:
-            data = {
-                &quot;Failed&quot;: &quot;Unable to read statistics from server: {} {}&quot;
-                .format(self.sockname, e)
-            }
-            self.socket = None
-        return data
</del><span class="cx"> 
</span><del>-
-
</del><span class="cx"> class HelpWindow(BaseWindow):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Display help for the dashboard.
</span><span class="lines">@@ -304,23 +357,19 @@
</span><span class="cx"> 
</span><span class="cx">     help = &quot;display dashboard help&quot;
</span><span class="cx">     all = False
</span><ins>+    helpItems = (
+        &quot;&quot;,
+        &quot;a - all windows&quot;,
+        &quot;  - (space) pause dashboard polling&quot;,
+        &quot;t - toggle update between 0.1 and 1.0 seconds&quot;,
+        &quot;&quot;,
+        &quot;q - exit the dashboard&quot;,
+    )
</ins><span class="cx"> 
</span><del>-    def __init__(self, usesCurses):
-        super(HelpWindow, self).__init__(usesCurses)
-        self.help = (
-            &quot;&quot;,
-            &quot;a - all windows&quot;,
-            &quot;  - (space) pause dashboard polling&quot;,
-            &quot;t - toggle update between 0.1 and 1.0 seconds&quot;,
-            &quot;&quot;,
-            &quot;q - exit the dashboard&quot;,
-        )
-
-
</del><span class="cx">     def makeWindow(self, top=0, left=0):
</span><span class="cx">         self._createWindow(
</span><span class="cx">             &quot;Help&quot;,
</span><del>-            len(self.help) + len(Dashboard.registered_windows) + 2,
</del><ins>+            len(self.helpItems) + len(Dashboard.registered_windows) + 2,
</ins><span class="cx">             begin_y=top, begin_x=left
</span><span class="cx">         )
</span><span class="cx">         return self
</span><span class="lines">@@ -345,7 +394,7 @@
</span><span class="cx">             Dashboard.registered_windows.items(), key=lambda x: x[0]
</span><span class="cx">         ):
</span><span class="cx">             items.append(&quot;{} - {}&quot;.format(keypress, wtype.help))
</span><del>-        items.extend(self.help)
</del><ins>+        items.extend(self.helpItems)
</ins><span class="cx">         for item in items:
</span><span class="cx">             if self.usesCurses:
</span><span class="cx">                 self.window.addstr(y, x, item)
</span><span class="lines">@@ -358,21 +407,22 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-class WorkWindow(BaseSocketWindow):
</del><ins>+class WorkWindow(BaseWindow):
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Display the status of the server's job queue.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">     help = &quot;display server jobs&quot;
</span><ins>+    clientItem = &quot;jobs&quot;
</ins><span class="cx"> 
</span><span class="cx">     def makeWindow(self, top=0, left=0):
</span><del>-        nlines = self.readSock(&quot;jobcount&quot;)
</del><ins>+        nlines = self.readItem(&quot;jobcount&quot;)
</ins><span class="cx">         self._createWindow(&quot;Jobs&quot;, nlines + 5, begin_y=top, begin_x=left)
</span><span class="cx">         return self
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def update(self):
</span><del>-        records = self.readSock(&quot;jobs&quot;)
</del><ins>+        records = self.clientData()
</ins><span class="cx">         self.iter += 1
</span><span class="cx"> 
</span><span class="cx">         if self.usesCurses:
</span><span class="lines">@@ -429,16 +479,17 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-class SlotsWindow(BaseSocketWindow):
</del><ins>+class SlotsWindow(BaseWindow):
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Displays the status of the server's master process worker slave slots.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">     help = &quot;display server child slots&quot;
</span><ins>+    clientItem = &quot;slots&quot;
</ins><span class="cx">     FORMAT_WIDTH = 72
</span><span class="cx"> 
</span><span class="cx">     def makeWindow(self, top=0, left=0):
</span><del>-        slots = self.readSock(&quot;slots&quot;)[&quot;slots&quot;]
</del><ins>+        slots = self.readItem(self.clientItem)[&quot;slots&quot;]
</ins><span class="cx">         self._createWindow(
</span><span class="cx">             &quot;Slots&quot;, len(slots) + 5, self.FORMAT_WIDTH,
</span><span class="cx">             begin_y=top, begin_x=left
</span><span class="lines">@@ -447,7 +498,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def update(self):
</span><del>-        data = self.readSock(&quot;slots&quot;)
</del><ins>+        data = self.clientData()
</ins><span class="cx">         records = data[&quot;slots&quot;]
</span><span class="cx">         self.iter += 1
</span><span class="cx"> 
</span><span class="lines">@@ -517,7 +568,7 @@
</span><span class="cx">             s = &quot;{:&gt;10}&quot;.format(&quot;OVERLOADED&quot; if data[&quot;overloaded&quot;] else &quot;&quot;)
</span><span class="cx">             self.window.addstr(
</span><span class="cx">                 y, x, s,
</span><del>-                curses.A_REVERSE if data[&quot;overloaded&quot;] else curses.A_NORMAL
</del><ins>+                curses.color_pair(1) + curses.A_BOLD if data[&quot;overloaded&quot;] else curses.A_NORMAL
</ins><span class="cx">             )
</span><span class="cx">         else:
</span><span class="cx">             if data[&quot;overloaded&quot;]:
</span><span class="lines">@@ -532,21 +583,22 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-class SystemWindow(BaseSocketWindow):
</del><ins>+class SystemWindow(BaseWindow):
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Displays the system information provided by the server.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">     help = &quot;display system details&quot;
</span><ins>+    clientItem = &quot;stats_system&quot;
</ins><span class="cx"> 
</span><span class="cx">     def makeWindow(self, top=0, left=0):
</span><del>-        slots = self.readSock(&quot;stats&quot;)[&quot;system&quot;]
</del><ins>+        slots = self.readItem(self.clientItem)
</ins><span class="cx">         self._createWindow(&quot;System&quot;, len(slots) + 3, begin_y=top, begin_x=left)
</span><span class="cx">         return self
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def update(self):
</span><del>-        records = self.readSock(&quot;stats&quot;)[&quot;system&quot;]
</del><ins>+        records = self.clientData()
</ins><span class="cx">         self.iter += 1
</span><span class="cx"> 
</span><span class="cx">         if self.usesCurses:
</span><span class="lines">@@ -599,10 +651,78 @@
</span><span class="cx">         self.lastResult = records
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-Dashboard.registerWindow(HelpWindow, &quot;h&quot;)
</del><ins>+
+class StatsWindow(BaseWindow):
+    &quot;&quot;&quot;
+    Displays the status of the server's master process worker slave slots.
+    &quot;&quot;&quot;
+
+    help = &quot;display server request stats&quot;
+    clientItem = &quot;stats&quot;
+    FORMAT_WIDTH = 84
+
+    def makeWindow(self, top=0, left=0):
+        self._createWindow(&quot;Request Statistics&quot;, 8, self.FORMAT_WIDTH, begin_y=top, begin_x=left)
+        return self
+
+
+    def update(self):
+        records = self.clientData()
+        self.iter += 1
+
+        if self.usesCurses:
+            self.window.erase()
+            self.window.border()
+            self.window.addstr(0, 2, self.title + &quot; {} ({})&quot;.format(len(records), self.iter,))
+
+        x = 1
+        y = 1
+        s1 = &quot; {:&lt;8}{:&gt;8}{:&gt;10}{:&gt;10}{:&gt;10}{:&gt;10}{:&gt;8}{:&gt;8}{:&gt;8} &quot;.format(
+            &quot;Period&quot;, &quot;Reqs&quot;, &quot;Av-Reqs&quot;, &quot;Av-NoWr&quot;, &quot;Av-Resp&quot;, &quot;Max-Resp&quot;, &quot;Slot&quot;, &quot;CPU &quot;, &quot;500's&quot;
+        )
+        s2 = &quot; {:&lt;8}{:&gt;8}{:&gt;10}{:&gt;10}{:&gt;10}{:&gt;10}{:&gt;8}{:&gt;8}{:&gt;8} &quot;.format(
+            &quot;&quot;, &quot;&quot;, &quot;per sec&quot;, &quot;(ms)&quot;, &quot;(ms)&quot;, &quot;(ms)&quot;, &quot;Avg.&quot;, &quot;Avg.&quot;, &quot;&quot;
+        )
+        if self.usesCurses:
+            self.window.addstr(y, x, s1, curses.A_REVERSE)
+            self.window.addstr(y + 1, x, s2, curses.A_REVERSE)
+        else:
+            print(s1)
+            print(s2)
+        y += 2
+        for key, seconds in ((&quot;current&quot;, 60,), (&quot;1m&quot;, 60,), (&quot;5m&quot;, 5 * 60,), (&quot;1h&quot;, 60 * 60,),):
+            stat = records[key]
+            s = &quot; {:&lt;8}{:&gt;8}{:&gt;10.1f}{:&gt;10.1f}{:&gt;10.1f}{:&gt;10.1f}{:&gt;8.2f}{:&gt;7.1f}%{:&gt;8} &quot;.format(
+                key,
+                stat[&quot;requests&quot;],
+                safeDivision(float(stat[&quot;requests&quot;]), seconds),
+                safeDivision(stat[&quot;t&quot;], stat[&quot;requests&quot;]),
+                safeDivision(stat[&quot;t&quot;] - stat[&quot;t-resp-wr&quot;], stat[&quot;requests&quot;]),
+                stat[&quot;T-MAX&quot;],
+                safeDivision(float(stat[&quot;slots&quot;]), stat[&quot;requests&quot;]),
+                safeDivision(stat[&quot;cpu&quot;], stat[&quot;requests&quot;]),
+                stat[&quot;500&quot;],
+            )
+            try:
+                if self.usesCurses:
+                    self.window.addstr(y, x, s)
+                else:
+                    print(s)
+            except curses.error:
+                pass
+            y += 1
+
+        if self.usesCurses:
+            self.window.refresh()
+
+        self.lastResult = records
+
+
+Dashboard.registerWindow(SystemWindow, &quot;s&quot;)
+Dashboard.registerWindow(StatsWindow, &quot;r&quot;)
</ins><span class="cx"> Dashboard.registerWindow(WorkWindow, &quot;j&quot;)
</span><span class="cx"> Dashboard.registerWindow(SlotsWindow, &quot;c&quot;)
</span><del>-Dashboard.registerWindow(SystemWindow, &quot;s&quot;)
</del><ins>+Dashboard.registerWindow(HelpWindow, &quot;h&quot;)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> if __name__ == &quot;__main__&quot;:
</span></span></pre>
</div>
</div>

</body>
</html>