-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make cycle.sh and resources.sh generate JSONs
- Loading branch information
1 parent
5406ab6
commit 5eff826
Showing
3 changed files
with
124 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,122 +1,119 @@ | ||
import os | ||
import sys | ||
import json | ||
import numpy as np | ||
from enum import Enum | ||
import matplotlib.pyplot as plt | ||
|
||
stat = sys.argv[1] | ||
|
||
class Logic(Enum): | ||
RR = 1 | ||
STRICT = 2 | ||
|
||
def append_path_prefix(file): | ||
path_to_script = os.path.dirname(__file__) | ||
path_to_file = os.path.join(path_to_script, file) | ||
return path_to_file | ||
|
||
def parse(stat, file): | ||
binheap_rr = [] | ||
specialized_rr = [] | ||
binheap_strict = [] | ||
specialized_strict = [] | ||
out = { | ||
"binheap" : { | ||
"round_robin" : {}, | ||
"strict" : {} | ||
}, | ||
"specialized" : { | ||
"round_robin" : {}, | ||
"strict" : {} | ||
} | ||
} | ||
|
||
with open(file) as file: | ||
if stat == "cycles": | ||
for line in file: | ||
split = line.strip().split(":") | ||
tup = (split[0].split("flow")[0][-1], int(split[1])) | ||
if "round_robin" in line: | ||
if "binheap" in line: | ||
binheap_rr.append(tup) | ||
else: | ||
specialized_rr.append(tup) | ||
if "strict" in line: | ||
if "binheap" in line: | ||
binheap_strict.append(tup) | ||
else: | ||
specialized_strict.append(tup) | ||
else: | ||
data = file.read().strip() | ||
for d in data.split("\n\n"): | ||
split = d.split("\n") | ||
name = split[0] | ||
stats = json.loads("\n".join(split[1:])) | ||
tup = (name.split("flow")[0][-1], stats[stat]) | ||
if "round_robin" in name: | ||
if "binheap" in name: | ||
binheap_rr.append(tup) | ||
else: | ||
specialized_rr.append(tup) | ||
if "strict" in name: | ||
if "binheap" in name: | ||
binheap_strict.append(tup) | ||
else: | ||
specialized_strict.append(tup) | ||
|
||
return (specialized_rr, | ||
binheap_rr, | ||
specialized_strict, | ||
binheap_strict) | ||
|
||
def draw(specialized, binheap, name, filename, details=None): | ||
data = json.load(file) | ||
for file, data in data.items(): | ||
if isinstance(data, dict): | ||
data = data[stat] | ||
|
||
flow_no = file.split('flow')[0][-1] | ||
|
||
if "round_robin" in file: | ||
if "binheap" in file: | ||
out["binheap"]["round_robin"][flow_no] = data | ||
else: | ||
out["specialized"]["round_robin"][flow_no] = data | ||
if "strict" in file: | ||
if "binheap" in file: | ||
out["binheap"]["strict"][flow_no] = data | ||
else: | ||
out["specialized"]["strict"][flow_no] = data | ||
|
||
return out | ||
|
||
def draw(data, stat, logic, unit): | ||
fig, ax = plt.subplots(1, 1) | ||
fig.set_size_inches(20, 10, forward=True) | ||
ax.set_title(name, | ||
fontweight='bold', | ||
fontsize=20) | ||
ax.set_xlabel("number of flows", | ||
fontsize=20) | ||
if details is None: | ||
ax.set_ylabel(stat, | ||
fontsize=20) | ||
ax.set_xlabel("number of flows", fontsize=20) | ||
if unit is None: | ||
ax.set_ylabel(stat, fontsize=20) | ||
else: | ||
ax.set_ylabel(f"{stat} ({details})", | ||
fontsize=20) | ||
specialized = ax.scatter( | ||
list(map(lambda x: x[0], specialized)), | ||
list(map(lambda x: x[1], specialized)), | ||
c='b') | ||
binheap = ax.scatter( | ||
list(map(lambda x: x[0], binheap)), | ||
list(map(lambda x: x[1], binheap)), | ||
c='g') | ||
ax.set_ylabel(f"{stat} ({unit})", fontsize=20) | ||
|
||
file = "" | ||
|
||
if logic == Logic.RR: | ||
specialized = ax.scatter( | ||
data["specialized"]["round_robin"].keys(), | ||
data["specialized"]["round_robin"].values(), | ||
c='b') | ||
binheap = ax.scatter( | ||
data["binheap"]["round_robin"].keys(), | ||
data["binheap"]["round_robin"].values(), | ||
c='g') | ||
|
||
ax.set_title("Round Robin Queues", fontweight='bold', fontsize=20) | ||
file = append_path_prefix(f"{stat}_round_robin") | ||
|
||
elif logic == Logic.STRICT: | ||
specialized = ax.scatter( | ||
data["specialized"]["strict"].keys(), | ||
data["specialized"]["strict"].values(), | ||
c='b') | ||
binheap = ax.scatter( | ||
data["binheap"]["strict"].keys(), | ||
data["binheap"]["strict"].values(), | ||
c='g') | ||
|
||
ax.set_title("Strict Queues", fontweight='bold', fontsize=20) | ||
file = append_path_prefix(f"{stat}_strict") | ||
|
||
plt.legend((specialized, binheap), | ||
("Specialized (i.e. Cassandra style PIFO)", "Binary Heap"), | ||
("Specialized (i.e. Cassandra style)", "Binary Heap"), | ||
fontsize=12) | ||
file = append_path_prefix(f"{stat}_{filename}") | ||
|
||
plt.savefig(file) | ||
|
||
print(f"Generated {file}.png") | ||
|
||
# Parse data for round_robin and strict queues | ||
(specialized_rr, binheap_rr, specialized_strict, binheap_strict) = ([], [], [], []) | ||
stat = sys.argv[1] | ||
data = {} | ||
if stat == "total_time": | ||
file1 = sys.argv[2] | ||
file2 = sys.argv[3] | ||
|
||
(specialized_cycles_rr, | ||
binheap_cycles_rr, | ||
specialized_cycles_strict, | ||
binheap_cycles_strict) = parse("cycles", file1) | ||
(specialized_slacks_rr, | ||
binheap_slacks_rr, | ||
specialized_slacks_strict, | ||
binheap_slacks_strict) = parse("worst_slack", file2) | ||
|
||
def map2(cycles, slacks): | ||
cycles.sort(key=lambda c: c[0]) | ||
slacks.sort(key=lambda s: s[0]) | ||
|
||
def f(c,s): | ||
return (c[0], (1000*c[1])/(7 - s[1])) | ||
|
||
return list(map(f, cycles, slacks)) | ||
cycle_data = parse("cycles", file1) | ||
slack_data = parse("worst_slack", file2) | ||
|
||
specialized_rr = map2(specialized_cycles_rr, specialized_slacks_rr) | ||
binheap_rr = map2(binheap_cycles_rr, binheap_slacks_rr) | ||
specialized_strict = map2(specialized_cycles_strict, specialized_slacks_strict) | ||
binheap_strict = map2(binheap_cycles_strict, binheap_slacks_strict) | ||
data = cycle_data.copy() | ||
for impl in data.keys(): | ||
for logic in data[impl].keys(): | ||
for flow_no in data[impl][logic].keys(): | ||
cycles = cycle_data[impl][logic][flow_no] | ||
slack = slack_data[impl][logic][flow_no] | ||
data[impl][logic][flow_no] = (1000 * cycles) / (7 - slack) | ||
else: | ||
file = sys.argv[2] | ||
(specialized_rr, binheap_rr, specialized_strict, binheap_strict) = parse(stat, file) | ||
data = parse(stat, file) | ||
|
||
# Draw results | ||
details = "μs" if stat == "total_time" else None | ||
draw(specialized_rr, binheap_rr, "Round Robin Queues", "round_robin", details) | ||
draw(specialized_strict, binheap_strict, "Strict Queues", "strict", details) | ||
unit = "μs" if stat == "total_time" else None | ||
draw(data, stat, Logic.RR, unit) | ||
draw(data, stat, Logic.STRICT, unit) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters