From b3a8bf53961b92999f42eb960b5fff0669e037b9 Mon Sep 17 00:00:00 2001
From: Peter Cai <peter.cai@uwaterloo.ca>
Date: Thu, 2 Mar 2023 15:33:59 -0500
Subject: [PATCH] Separate different plot types under memcached_conn_scan

Just to make the script cleaner
---
 analyze/memcached_conn_scan.py          | 75 +------------------------
 analyze/memcached_conn_vs_llc_misses.py | 34 +++++++++++
 analyze/memcached_ipr.py                | 26 +++++++++
 analyze/memcached_qps_vs_conn.py        | 34 +++++++++++
 4 files changed, 96 insertions(+), 73 deletions(-)
 create mode 100644 analyze/memcached_conn_vs_llc_misses.py
 create mode 100644 analyze/memcached_ipr.py
 create mode 100644 analyze/memcached_qps_vs_conn.py

diff --git a/analyze/memcached_conn_scan.py b/analyze/memcached_conn_scan.py
index fbd046f..9f98613 100644
--- a/analyze/memcached_conn_scan.py
+++ b/analyze/memcached_conn_scan.py
@@ -1,6 +1,4 @@
 import os
-import matplotlib.pyplot as plt
-from config import markers, colors
 import util
 
 experiments = [f for f in os.listdir('../data')
@@ -55,13 +53,7 @@ def extract_conn_qps(threads, include_caladan = False):
 
     return ret
 
-def show_plot(threads, include_caladan = False):
-    plt.cla()
-    if include_caladan:
-        plt.title('Memcached connections vs QPS, %d threads, with Caladan' % (threads,), y = 1.05)
-    else:
-        plt.title('Memcached connections vs QPS, %d threads' % (threads,), y = 1.05)
-
+def collect_data(threads, include_caladan = False):
     data = extract_conn_qps(threads, include_caladan)
 
     if include_caladan and threads == 1:
@@ -71,67 +63,4 @@ def show_plot(threads, include_caladan = False):
         data[name] = extract_conn_qps_exp('memcached_conn_scan.5.4.0-136-generic.caladan.t2')
         data[name] = (data[name][0], [qps / 2 for qps in data[name][1]], [qps / 2 for qps in data[name][2]], data[name][3], data[name][4], data[name][5], data[name][6])
 
-    for k in data:
-       plt.errorbar(data[k][0], data[k][1], yerr = data[k][2], capsize = 4, label = k, marker = markers[k], color = colors[k])
-
-    plt.ticklabel_format(axis = 'both', style = 'sci', scilimits = (0, 4))
-    plt.xlabel('Connections (per client w/ 7 * 8 clients)')
-    plt.ylabel('QPS')
-
-    plt.legend()
-    if os.getenv('SAVE_FIGURE') != 'true':
-        plt.rcParams.update({'font.size': 16})
-        plt.show()
-    else:
-        if include_caladan:
-            plt.savefig('../data/figs/memcached_conn_scan.t%d.caladan.png' % (threads,), dpi = 192)
-        else:
-            plt.savefig('../data/figs/memcached_conn_scan.t%d.png' % (threads,), dpi = 192)
-
-    plt.cla()
-    if include_caladan:
-        plt.title('Memcached connections vs LLC misses, %d threads, with Caladan' % (threads,))
-    else:
-        plt.title('Memcached connections vs LLC misses, %d threads' % (threads,))
-
-    for k in data:
-        plt.errorbar(data[k][0], data[k][3], yerr=data[k][4], capsize = 4, label = k, marker = markers[k], color = colors[k])
-
-    plt.xlabel('Connections (per client w/ 7 * 8 clients)')
-    plt.ylabel('LLC misses per request')
-
-    plt.legend()
-    if os.getenv('SAVE_FIGURE') != 'true':
-        plt.rcParams.update({'font.size': 16})
-        plt.show()
-    else:
-        if include_caladan:
-            plt.savefig('../data/figs/memcached_conn_scan.llc_misses.t%d.caladan.png' % (threads,), dpi = 192)
-        else:
-            plt.savefig('../data/figs/memcached_conn_scan.llc_misses.t%d.png' % (threads,), dpi = 192)
-
-    if not include_caladan or threads == 1:
-        return
-
-    plt.cla()
-    plt.title('Memcached Instructions per Request, c160, %d threads' % (threads,))
-
-    plt.bar(range(len(data)), [data[k][5][4] for k in data], yerr = [data[k][6][4] for k in data], capsize=4)
-    plt.xticks(range(len(data)), data.keys())
-
-    plt.ylabel('Instructions per Request')
-
-    plt.legend()
-    if os.getenv('SAVE_FIGURE') != 'true':
-        plt.rcParams.update({'font.size': 16})
-        plt.show()
-    else:
-        if include_caladan:
-            plt.savefig('../data/figs/memcached_conn_scan.ipr.t%d.caladan.png' % (threads,), dpi = 192)
-        else:
-            plt.savefig('../data/figs/memcached_conn_scan.ipr.t%d.png' % (threads,), dpi = 192)
-
-show_plot(1)
-show_plot(1, True)
-show_plot(8)
-show_plot(8, True)
+    return data
diff --git a/analyze/memcached_conn_vs_llc_misses.py b/analyze/memcached_conn_vs_llc_misses.py
new file mode 100644
index 0000000..3b21cf6
--- /dev/null
+++ b/analyze/memcached_conn_vs_llc_misses.py
@@ -0,0 +1,34 @@
+import matplotlib.pyplot as plt
+from memcached_conn_scan import collect_data
+import os
+from config import markers, colors
+
+def plot(threads, include_caladan = False):
+    data = collect_data(threads, include_caladan)
+
+    plt.cla()
+    if include_caladan:
+        plt.title('Memcached connections vs LLC misses, %d threads, with Caladan' % (threads,))
+    else:
+        plt.title('Memcached connections vs LLC misses, %d threads' % (threads,))
+
+    for k in data:
+        plt.errorbar(data[k][0], data[k][3], yerr=data[k][4], capsize = 4, label = k, marker = markers[k], color = colors[k])
+
+    plt.xlabel('Connections (per client w/ 7 * 8 clients)')
+    plt.ylabel('LLC misses per request')
+
+    plt.legend()
+    if os.getenv('SAVE_FIGURE') != 'true':
+        plt.rcParams.update({'font.size': 16})
+        plt.show()
+    else:
+        if include_caladan:
+            plt.savefig('../data/figs/memcached_conn_scan.llc_misses.t%d.caladan.png' % (threads,), dpi = 192)
+        else:
+            plt.savefig('../data/figs/memcached_conn_scan.llc_misses.t%d.png' % (threads,), dpi = 192)
+
+plot(1)
+plot(1, True)
+plot(8)
+plot(8, True)
diff --git a/analyze/memcached_ipr.py b/analyze/memcached_ipr.py
new file mode 100644
index 0000000..6af9c5c
--- /dev/null
+++ b/analyze/memcached_ipr.py
@@ -0,0 +1,26 @@
+import matplotlib.pyplot as plt
+from memcached_conn_scan import collect_data
+import os
+
+def plot(threads):
+    data = collect_data(threads, True)
+    plt.cla()
+    plt.title('Memcached Instructions per Request, c160, %d threads' % (threads,))
+
+    plt.bar(range(len(data)), [data[k][5][4] for k in data], yerr = [data[k][6][4] for k in data], capsize=4)
+    plt.xticks(range(len(data)), data.keys())
+
+    plt.ylabel('Instructions per Request')
+
+    plt.legend()
+    if os.getenv('SAVE_FIGURE') != 'true':
+        plt.rcParams.update({'font.size': 16})
+        plt.show()
+    else:
+        if include_caladan:
+            plt.savefig('../data/figs/memcached_conn_scan.ipr.t%d.caladan.png' % (threads,), dpi = 192)
+        else:
+            plt.savefig('../data/figs/memcached_conn_scan.ipr.t%d.png' % (threads,), dpi = 192)
+
+plot(1)
+plot(8)
diff --git a/analyze/memcached_qps_vs_conn.py b/analyze/memcached_qps_vs_conn.py
new file mode 100644
index 0000000..626d230
--- /dev/null
+++ b/analyze/memcached_qps_vs_conn.py
@@ -0,0 +1,34 @@
+import matplotlib.pyplot as plt
+from memcached_conn_scan import collect_data
+from config import markers, colors
+import os
+
+def plot(threads, include_caladan = False):
+    data = collect_data(threads, include_caladan)
+    plt.cla()
+    if include_caladan:
+        plt.title('Memcached connections vs QPS, %d threads, with Caladan' % (threads,), y = 1.05)
+    else:
+        plt.title('Memcached connections vs QPS, %d threads' % (threads,), y = 1.05)
+
+    for k in data:
+       plt.errorbar(data[k][0], data[k][1], yerr = data[k][2], capsize = 4, label = k, marker = markers[k], color = colors[k])
+
+    plt.ticklabel_format(axis = 'both', style = 'sci', scilimits = (0, 4))
+    plt.xlabel('Connections (per client w/ 7 * 8 clients)')
+    plt.ylabel('QPS')
+
+    plt.legend()
+    if os.getenv('SAVE_FIGURE') != 'true':
+        plt.rcParams.update({'font.size': 16})
+        plt.show()
+    else:
+        if include_caladan:
+            plt.savefig('../data/figs/memcached_conn_scan.t%d.caladan.png' % (threads,), dpi = 192)
+        else:
+            plt.savefig('../data/figs/memcached_conn_scan.t%d.png' % (threads,), dpi = 192)
+
+plot(1)
+plot(1, True)
+plot(8)
+plot(8, True)
-- 
GitLab