<!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>[15703] CalendarServer/trunk</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/15703">15703</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2016-06-24 10:03:43 -0700 (Fri, 24 Jun 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add -i option to dashtime for location to store saved images to. Add options to skip ahead 1 and 5 minutes in dashview replay mode.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkcalendarservertoolsdashtimepy">CalendarServer/trunk/calendarserver/tools/dashtime.py</a></li>
<li><a href="#CalendarServertrunkcalendarservertoolsdashviewpy">CalendarServer/trunk/calendarserver/tools/dashview.py</a></li>
<li><a href="#CalendarServertrunkdocAdminDashboardmd">CalendarServer/trunk/doc/Admin/Dashboard.md</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkcalendarservertoolsdashtimepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tools/dashtime.py (15702 => 15703)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tools/dashtime.py        2016-06-24 02:17:34 UTC (rev 15702)
+++ CalendarServer/trunk/calendarserver/tools/dashtime.py        2016-06-24 17:03:43 UTC (rev 15703)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx"> import matplotlib.pyplot as plt
</span><span class="cx"> import operator
</span><span class="cx"> import os
</span><ins>+import sys
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> verbose = False
</span><span class="lines">@@ -431,19 +432,21 @@
</span><span class="cx">             verbose = True
</span><span class="cx"> 
</span><span class="cx">         # Get the log file
</span><del>-        self.logname = args.l
</del><ins>+        self.logname = os.path.expanduser(args.l)
</ins><span class="cx">         try:
</span><del>-            if args.l.endswith(&quot;.bz2&quot;):
-                self.logfile = BZ2File(os.path.expanduser(args.l))
</del><ins>+            if self.logname.endswith(&quot;.bz2&quot;):
+                self.logfile = BZ2File(self.logname)
</ins><span class="cx">             else:
</span><del>-                self.logfile = open(os.path.expanduser(args.l))
</del><ins>+                self.logfile = open(self.logname)
</ins><span class="cx">         except:
</span><span class="cx">             print(&quot;Failed to open logfile {}&quot;.format(args.l))
</span><ins>+            sys.exit(1)
</ins><span class="cx"> 
</span><span class="cx">         self.pod = getattr(args, &quot;p&quot;, None)
</span><span class="cx">         self.single_server = getattr(args, &quot;s&quot;, None)
</span><span class="cx"> 
</span><span class="cx">         self.save = args.save
</span><ins>+        self.savedir = getattr(args, &quot;i&quot;, None)
</ins><span class="cx">         self.noshow = args.noshow
</span><span class="cx"> 
</span><span class="cx">         self.mode = args.mode
</span><span class="lines">@@ -505,7 +508,8 @@
</span><span class="cx">                     line = decompress(line.decode(&quot;base64&quot;))
</span><span class="cx">                 jline = json.loads(line)
</span><span class="cx"> 
</span><del>-                self.x.append(ctr)
</del><ins>+                timestamp = jline[&quot;timestamp&quot;]
+                self.x.append(int(timestamp[14:16]) * 60 + int(timestamp[17:19]))
</ins><span class="cx">                 ctr += 1
</span><span class="cx"> 
</span><span class="cx">                 # Initialize the plot arrays when we know how many hosts there are
</span><span class="lines">@@ -565,7 +569,8 @@
</span><span class="cx">                     line = decompress(line.decode(&quot;base64&quot;))
</span><span class="cx">                 jline = json.loads(line)
</span><span class="cx"> 
</span><del>-                self.x.append(ctr)
</del><ins>+                timestamp = jline[&quot;timestamp&quot;]
+                self.x.append(int(timestamp[14:16]) * 60 + int(timestamp[17:19]))
</ins><span class="cx">                 ctr += 1
</span><span class="cx"> 
</span><span class="cx">                 # Initialize the plot arrays when we know how many hosts there are
</span><span class="lines">@@ -651,7 +656,14 @@
</span><span class="cx">                 plt.subplot(len(self.y), 1, plotnum + 1)
</span><span class="cx">                 plotSeries(self.titles[measurement], self.x, self.y[measurement], 0, self.ymaxes[measurement], plotnum == plotmax - 1)
</span><span class="cx">         if self.save:
</span><del>-            plt.savefig(&quot;.&quot;.join((os.path.expanduser(self.logname), self.mode, &quot;png&quot;,)), orientation=&quot;landscape&quot;, format=&quot;png&quot;)
</del><ins>+            if self.savedir:
+                dirpath = self.savedir
+                if not os.path.exists(dirpath):
+                    os.makedirs(dirpath)
+            else:
+                dirpath = os.path.dirname(self.logname)
+            fname = &quot;.&quot;.join((os.path.basename(self.logname), self.mode, &quot;png&quot;),)
+            plt.savefig(os.path.join(dirpath, fname), orientation=&quot;landscape&quot;, format=&quot;png&quot;)
</ins><span class="cx">         if not self.noshow:
</span><span class="cx">             plt.show()
</span><span class="cx"> 
</span><span class="lines">@@ -790,6 +802,7 @@
</span><span class="cx"> &quot;&quot;&quot;,
</span><span class="cx">     )
</span><span class="cx">     parser.add_argument(&quot;-l&quot;, default=SUPPRESS, required=True, help=&quot;Log file to process&quot;)
</span><ins>+    parser.add_argument(&quot;-i&quot;, default=SUPPRESS, help=&quot;Directory to store image (default: log file directory)&quot;)
</ins><span class="cx">     parser.add_argument(&quot;-p&quot;, default=SUPPRESS, help=&quot;Name of pod to analyze&quot;)
</span><span class="cx">     parser.add_argument(&quot;-s&quot;, default=SUPPRESS, help=&quot;Name of server to analyze&quot;)
</span><span class="cx">     parser.add_argument(&quot;--save&quot;, action=&quot;store_true&quot;, help=&quot;Save plot PNG image&quot;)
</span><span class="lines">@@ -820,22 +833,26 @@
</span><span class="cx"> 
</span><span class="cx">     plt.plot(x, y)
</span><span class="cx"> 
</span><del>-    if last_subplot:
-        plt.xlabel(&quot;Time&quot;)
-    else:
-        frame = plt.gca()
-        frame.axes.xaxis.set_ticklabels([])
-    plt.ylabel(title, fontsize=&quot;small&quot;, horizontalalignment=&quot;right&quot;, rotation=&quot;horizontal&quot;)
</del><ins>+
</ins><span class="cx">     if ymin is not None:
</span><span class="cx">         plt.ylim(ymin=ymin)
</span><span class="cx">     if ymax is not None:
</span><span class="cx">         plt.ylim(ymax=ymax)
</span><del>-    plt.xlim(min(x), max(x))
-    plt.xticks(range(min(x), max(x) + 1, 60))
-    plt.grid(True, &quot;major&quot;, &quot;x&quot;, alpha=0.5, linewidth=0.5)
</del><ins>+    plt.xlim(0, 3600)
</ins><span class="cx"> 
</span><ins>+    frame = plt.gca()
+    if last_subplot:
+        plt.xlabel(&quot;Time (minutes)&quot;)
+    plt.ylabel(title, fontsize=&quot;small&quot;, horizontalalignment=&quot;right&quot;, rotation=&quot;horizontal&quot;)
</ins><span class="cx"> 
</span><ins>+    # Setup axes - want 0 - 60 minute scale for x-axis
+    plt.tick_params(labelsize=&quot;small&quot;)
+    plt.xticks(range(0, 3601, 300), range(0, 61, 5) if last_subplot else [])
+    frame.set_xticks(range(0, 3601, 60), minor=True)
+    plt.grid(True, &quot;minor&quot;, &quot;x&quot;, alpha=0.5, linewidth=0.5)
</ins><span class="cx"> 
</span><ins>+
+
</ins><span class="cx"> def plotScatter(title, x, y, xlim=None, ylim=None, last_subplot=True):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Plot the chosen dataset key for each scanned data file.
</span></span></pre></div>
<a id="CalendarServertrunkcalendarservertoolsdashviewpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tools/dashview.py (15702 => 15703)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tools/dashview.py        2016-06-24 02:17:34 UTC (rev 15702)
+++ CalendarServer/trunk/calendarserver/tools/dashview.py        2016-06-24 17:03:43 UTC (rev 15703)
</span><span class="lines">@@ -143,6 +143,9 @@
</span><span class="cx">     updates.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><ins>+    MODE_SERVER = 1
+    MODE_LOGREPLAY = 2
+
</ins><span class="cx">     screen = None
</span><span class="cx">     registered_windows = OrderedDict()
</span><span class="cx">     registered_window_sets = {
</span><span class="lines">@@ -163,8 +166,10 @@
</span><span class="cx"> 
</span><span class="cx">         if server:
</span><span class="cx">             self.client = DashboardClient(self, server)
</span><ins>+            self.mode = self.MODE_SERVER
</ins><span class="cx">         else:
</span><span class="cx">             self.client = DashboardLogfile(self, logfile)
</span><ins>+            self.mode = self.MODE_LOGREPLAY
</ins><span class="cx">         self.client_error = False
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -363,7 +368,13 @@
</span><span class="cx">                 self.selected_server.x = len(self.serversForPod(self.pods()[self.selected_server.y])) - 1
</span><span class="cx">             self.resetWindows()
</span><span class="cx"> 
</span><ins>+        elif c == &quot;1&quot; and self.mode == self.MODE_LOGREPLAY:
+            self.client.skipLines(60)
</ins><span class="cx"> 
</span><ins>+        elif c == &quot;5&quot; and self.mode == self.MODE_LOGREPLAY:
+            self.client.skipLines(300)
+
+
</ins><span class="cx">     def dataForItem(self, item):
</span><span class="cx">         return self.client.getOneItem(
</span><span class="cx">             self.selectedPod(),
</span><span class="lines">@@ -561,7 +572,15 @@
</span><span class="cx">         return data
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def skipLines(self, count):
+        try:
+            for _ignore in range(count):
+                self.logfile.readline()
+        except ValueError as e:
+            logging.debug(&quot;skipLines: failed: {}&quot;.format(e))
</ins><span class="cx"> 
</span><ins>+
+
</ins><span class="cx"> class Aggregator(object):
</span><span class="cx"> 
</span><span class="cx">     @staticmethod
</span><span class="lines">@@ -943,11 +962,29 @@
</span><span class="cx">         &quot;&quot;,
</span><span class="cx">         &quot; q - Quit&quot;,
</span><span class="cx">     )
</span><ins>+    helpItemsReplay = (
+        &quot; a - All Panels&quot;,
+        &quot; n - No Panels&quot;,
+        &quot;&quot;,
+        &quot;   - (space) Pause&quot;,
+        &quot; 1 - ahead one minute&quot;,
+        &quot; 5 - ahead five minutes&quot;,
+        &quot; t - Toggle Update Speed&quot;,
+        &quot; x - Toggle Aggregate Mode&quot;,
+        &quot;&quot;,
+        &quot; q - Quit&quot;,
+    )
</ins><span class="cx"> 
</span><span class="cx">     windowTitle = &quot;Help&quot;
</span><span class="cx">     formatWidth = 28
</span><span class="cx">     additionalRows = 3
</span><span class="cx"> 
</span><ins>+    def __init__(self, dashboard):
+        super(HelpWindow, self).__init__(dashboard)
+        if self.dashboard.mode == self.dashboard.MODE_LOGREPLAY:
+            self.helpItems = self.helpItemsReplay
+
+
</ins><span class="cx">     def makeWindow(self, top=0, left=0):
</span><span class="cx">         term_w, _ignore_term_h = terminal_size()
</span><span class="cx">         help_x_offset = term_w - self.formatWidth
</span></span></pre></div>
<a id="CalendarServertrunkdocAdminDashboardmd"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/doc/Admin/Dashboard.md (15702 => 15703)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/doc/Admin/Dashboard.md        2016-06-24 02:17:34 UTC (rev 15702)
+++ CalendarServer/trunk/doc/Admin/Dashboard.md        2016-06-24 17:03:43 UTC (rev 15703)
</span><span class="lines">@@ -141,6 +141,8 @@
</span><span class="cx"> * `a` display all panels
</span><span class="cx"> * `n` display no panels
</span><span class="cx"> * ` ` (space) toggle pause
</span><ins>+* `1` skip ahead 1 minute (only when replaying a log file)
+* `5` skip ahead 5 minutes (only when replaying a log file)
</ins><span class="cx"> * `t` toggle Update Speed between 0.1 secs and 1 sec.
</span><span class="cx"> * `x` toggle Aggregate Mode
</span><span class="cx"> * `q` Quit
</span><span class="lines">@@ -157,8 +159,8 @@
</span><span class="cx"> #### Help
</span><span class="cx"> 
</span><span class="cx">         dashtime.py --help
</span><del>-        usage: dashtime.py [-h] -l L [-p P] [-s S] [--save] [--noshow] [--start START]
-                           [--count COUNT]
</del><ins>+        usage: dashtime.py [-h] -l L [-i I] [-p P] [-s S] [--save] [--noshow]
+                           [--start START] [--count COUNT]
</ins><span class="cx">                            [--mode {basic,basicjob,basicmethod,basicschedule,hostcompleted,hostcpu,hostrequests,scatter}]
</span><span class="cx">                            [-v]
</span><span class="cx">         
</span><span class="lines">@@ -167,6 +169,7 @@
</span><span class="cx">         optional arguments:
</span><span class="cx">           -h, --help            show this help message and exit
</span><span class="cx">           -l L                  Log file to process
</span><ins>+          -i I                  Directory to store image (default: log file directory)
</ins><span class="cx">           -p P                  Name of pod to analyze
</span><span class="cx">           -s S                  Name of server to analyze
</span><span class="cx">           --save                Save plot PNG image (default: False)
</span><span class="lines">@@ -204,6 +207,7 @@
</span><span class="cx">         scatter - scatter plot of request count and response time vs CPU.
</span><span class="cx"> 
</span><span class="cx"> * The `-l` option must be present and point to a `dashcollect` log file.
</span><ins>+* The `-i` option defines the directory in which any images will be saved (if not present the directory of the log file is used).
</ins><span class="cx"> * The `-p` option defines the pod to view data for (if not present the first pod - alphabetically sorted - is used).
</span><span class="cx"> * The `-s` option defines a specific server to view data for (there are currently no modes that use this).
</span><span class="cx"> * The `--save` option, when present, will cause a PNG image of the plots to be saved to disk. The image file has the same name as the log file, but with the mode name and a `.png` suffix appended, and it will be created in the same directory as the log file.
</span></span></pre>
</div>
</div>

</body>
</html>