commit 232d40c058156d838e1e4578cda63bbff7de8295
Author: Marcos Assuncao <assuncao@acm.org>
Date:   Sun Aug 31 20:44:30 2014 +0200

    kadeploy scripts

diff --git a/papers/2014/reservation/experiments/kadeploy_graph b/papers/2014/reservation/experiments/kadeploy_graph
new file mode 100755
index 0000000..b128dd9
--- /dev/null
+++ b/papers/2014/reservation/experiments/kadeploy_graph
@@ -0,0 +1,9 @@
+#!/usr/bin/env python
+
+from os.path import join
+
+import sys; sys.path.insert(0, join('src', 'python'))
+
+from lib.kadeploy import plot_graphs
+
+plot_graphs()
diff --git a/papers/2014/reservation/experiments/src/python/lib/kadeploy.py b/papers/2014/reservation/experiments/src/python/lib/kadeploy.py
new file mode 100644
index 0000000..e41c399
--- /dev/null
+++ b/papers/2014/reservation/experiments/src/python/lib/kadeploy.py
@@ -0,0 +1,174 @@
+__author__ = 'Marcos Assuncao'
+
+import pytz
+import sys
+from argparse import ArgumentParser
+import matplotlib.pyplot as plt; plt.rcdefaults()
+import numpy as np
+from matplotlib import rc
+from pylab import *
+from scipy.stats import gaussian_kde
+rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
+rc('text', usetex=True)
+plt.rcParams.update({'font.size': 14})
+from datetime import datetime
+
+TZINFO = pytz.timezone("Europe/Paris")
+
+class DeploymentStat:
+
+    def __init__(self, host, start, step1_dur, step2_dur, step3_dur, success):
+        self._host = host
+        self._start = start
+        self._step1_dur = step1_dur
+        self._step2_dur = step2_dur
+        self._step3_dur = step3_dur
+        self._success = success
+        self._retry_1 = 0
+        self._retry_2 = 0
+        self._retry_3 = 0
+
+    @property
+    def hostname(self):
+        return self._host
+
+    @property
+    def start(self):
+        return self._start
+
+    @property
+    def step_1_duration(self):
+        return self._step1_dur
+
+    @property
+    def step_2_duration(self):
+        return self._step2_dur
+
+    @property
+    def step_3_duration(self):
+        return self._step3_dur
+
+    @property
+    def success(self):
+        return self._success
+
+    @property
+    def num_retries_step_1(self):
+        return self._retry_1
+
+    @num_retries_step_1.setter
+    def num_retries_step_1(self, r):
+        self._retry_1 = r
+
+    @property
+    def num_retries_step_2(self):
+        return self._retry_2
+
+    @num_retries_step_2.setter
+    def num_retries_step_2(self, r):
+        self._retry_2 = r
+
+    @property
+    def num_retries_step_3(self):
+        return self._retry_3
+
+    @num_retries_step_3.setter
+    def num_retries_step_3(self, r):
+        self._retry_3 = r
+
+    @property
+    def has_retries(self):
+        return (self.num_retries_step_1 > 0 or
+                self.num_retries_step_3 > 0 or
+                self.num_retries_step_3 > 0)
+
+def parse_date(str_date):
+    d = datetime.strptime(str_date, "%Y-%m-%d %H:%M:%S")
+    d = TZINFO.localize(d)
+    return d
+
+def parse_kdeploy_opt():
+    parser = ArgumentParser(description='Plot Kadeploy deployment graphs.')
+    parser.add_argument('--input', dest='input', type=str, required=True,
+                        help='the input request trace file')
+    parser.add_argument('--output', dest='output', type=str, required=True,
+                        help='the output directory')
+    parser.add_argument('--start-date', dest='start_date', type=parse_date, required=True,
+                        help='the start date of the log (i.e. YYYY-MM-DD HH:mm:ss)')
+    parser.add_argument('--cluster', dest='cluster', type=str, required=True,
+                        help='the name of the cluster')
+
+    args = parser.parse_args()
+    return args
+
+def parse_log(log, cluster):
+    f = open(log, 'r')
+
+    deployments = []
+    for line in f:
+        fields = line.split(',')
+        hostname = fields[2]
+
+        if cluster in hostname:
+            hostname = hostname.split('.')[0]
+            start = datetime.fromtimestamp(int(fields[3]), TZINFO)
+            step1_dur = int(fields[4])
+            step2_dur = int(fields[5])
+            step3_dur = int(fields[6])
+            success = "true" in fields[10]
+            dep = DeploymentStat(hostname, start, step1_dur, step2_dur, step3_dur, success)
+            retry_1 = int(fields[7])
+            retry_2 = int(fields[8])
+            retry_3 = int(fields[9])
+            dep.num_retries_step_1 = retry_1
+            dep.num_retries_step_2 = retry_2
+            dep.num_retries_step_3 = retry_3
+            deployments.append(dep)
+
+    f.close()
+    return deployments
+
+
+def plot_deployment_time(deployments, cluster, year, out_dir):
+    values = []
+    for d in deployments:
+        if d.success and not d.has_retries:
+            values.append(int(d.step_1_duration + d.step_2_duration + d.step_3_duration))
+            # values.append(int(d.step_3_duration))
+            # values.append(int(d.step_1_duration))
+
+    title = 'Deployment on Cluster %s (%d)' % (cluster, year)
+    out_file = out_dir + ("/deployment_%s_%d.pdf" % (cluster, year))
+    hist_graph(values, title, 'Deployment Time (seconds)', '', out_file)
+
+
+def hist_graph(values, title, x_label, y_label, out_file):
+    ar1 = np.array(values)
+    fig, ax = plt.subplots()
+
+    num_bins = 20
+    n, bins, patches = plt.hist(ar1, bins=num_bins, histtype='bar',
+                                normed=True, facecolor='#708090', alpha=0.5, rwidth=0.8)
+    plt.subplots_adjust(left=0.15)
+
+    max = round(bins[len(bins) - 1])
+    density = gaussian_kde(ar1)
+    xs = np.linspace(0,max,300)
+    density.covariance_factor = lambda : .25
+    density._compute_covariance()
+    plt.plot(xs,density(xs), 'r--')
+
+    ax.set_xlabel(x_label)
+    ax.set_ylabel(y_label)
+    ax.set_title(title)
+
+    ax.get_xaxis().tick_bottom()
+    ax.get_yaxis().tick_left()
+
+    plt.show()
+    # plt.savefig(out_file)
+
+def plot_graphs():
+    opts = parse_kdeploy_opt()
+    deployments = parse_log(opts.input, opts.cluster)
+    plot_deployment_time(deployments, opts.cluster, opts.start_date.year, opts.output)
