Skip to content

Commit 95cc134

Browse files
Add a graph to get a sense of execution overhead by language
1 parent 6a3a08a commit 95cc134

File tree

3 files changed

+85
-38
lines changed

3 files changed

+85
-38
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ a-run \
151151
<summary>Process Runtime Output</summary>
152152

153153
```bash
154-
cat all.json | jq -r '.[]|[.year, .day, .language, .runtime]|@tsv'
154+
cat all.json | jq -r '.[]|[.year, .day, .language, .runtime, .execution]|@tsv'
155155
cat all.json | jq -r '.[]|[.year, .day, .language, .runtime]|@tsv' | sort -nk4
156156
cat all.json | jq -r '.[]|[.year, .day, .language, .runtime]|@tsv' | sort -nk4 | awk '{ if ($4 > 100) { print $0 } }'
157157
cat all.json | jq -r '.[]|select(.year == 2015 and .day == 24)'

scripts/command/graph.py

+67-22
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import plotly.express as px
99

1010
from command.command import Command
11-
from component.figure_saver import FigType, FigureSaver
11+
from component.figure_saver import FigType, FigureProps, FigureSaver
1212

1313

1414
class Grapher(Command):
@@ -45,22 +45,19 @@ def run(self) -> None:
4545
self.create_graphs(runtimes)
4646

4747
def create_graphs(self, runtimes: pd.DataFrame) -> None:
48-
self.saver.save(
49-
name="runtime_language",
50-
fig=runtimes.boxplot(column="runtime", by="language", figsize=(8, 8)),
51-
fig_type=FigType.MATPLOTLIB,
52-
)
53-
self.saver.save(
54-
name="runtime_year",
55-
fig=runtimes.boxplot(column="runtime", by="year", figsize=(10, 8)),
56-
fig_type=FigType.MATPLOTLIB,
57-
)
48+
self.saver.save(self.year_percentage(runtimes.copy()))
49+
self.saver.save(self.runtime_language(runtimes.copy()))
50+
self.saver.save(self.runtime_year(runtimes.copy()))
51+
self.saver.save(self.cumulative_sum(runtimes.copy()))
52+
self.saver.save(self.usage_langauage(runtimes.copy()))
53+
self.saver.save(self.usage_langauage_yearly(runtimes.copy()))
54+
self.saver.save(self.overhead(runtimes.copy()))
5855

59-
with_all: pd.DataFrame = runtimes.copy()
60-
with_all["all"] = "Time in milliseconds"
61-
with_all["runtime"] = runtimes["runtime"].round(0)
56+
def year_percentage(self, runtimes: pd.DataFrame) -> FigureProps:
57+
runtimes["all"] = "Time in milliseconds"
58+
runtimes["runtime"] = runtimes["runtime"].round(0)
6259
yearly_runtimes = px.sunburst(
63-
with_all,
60+
runtimes,
6461
path=["all", "year", "day"],
6562
values="runtime",
6663
width=1000,
@@ -70,27 +67,59 @@ def create_graphs(self, runtimes: pd.DataFrame) -> None:
7067
textinfo="label+percent parent+value",
7168
sort=False,
7269
)
73-
self.saver.save(
70+
return FigureProps(
7471
name="year_percentage",
7572
fig=yearly_runtimes,
7673
fig_type=FigType.PLOTLY,
7774
)
7875

76+
def runtime_language(self, runtimes: pd.DataFrame) -> FigureProps:
77+
return FigureProps(
78+
name="runtime_language",
79+
fig=runtimes.boxplot(
80+
column="runtime",
81+
by="language",
82+
figsize=(8, 8),
83+
),
84+
fig_type=FigType.MATPLOTLIB,
85+
)
86+
87+
def runtime_year(self, runtimes: pd.DataFrame) -> FigureProps:
88+
return FigureProps(
89+
name="runtime_year",
90+
fig=runtimes.boxplot(
91+
column="runtime",
92+
by="year",
93+
figsize=(10, 8),
94+
),
95+
fig_type=FigType.MATPLOTLIB,
96+
)
97+
98+
def cumulative_sum(self, runtimes: pd.DataFrame) -> FigureProps:
7999
runtimes_only: pd.DataFrame = runtimes[["runtime"]]
80100
sorted_runtimes = runtimes_only.sort_values("runtime").reset_index(drop=True)
81-
self.saver.save(
101+
return FigureProps(
82102
name="cumulative_sum",
83-
fig=sorted_runtimes.cumsum().plot.line(legend=False, figsize=(8, 6)),
103+
fig=sorted_runtimes.cumsum().plot.line(
104+
legend=False,
105+
figsize=(8, 6),
106+
),
84107
fig_type=FigType.MATPLOTLIB,
85108
)
86109

110+
def usage_langauage(self, runtimes: pd.DataFrame) -> FigureProps:
87111
language_counts = runtimes["language"].value_counts()
88-
self.saver.save(
112+
return FigureProps(
89113
name="usage_langauage",
90-
fig=language_counts.plot.pie(y=1, autopct="%.2f", figsize=(8, 6)),
114+
fig=language_counts.plot.pie(
115+
y=1,
116+
autopct="%.2f",
117+
figsize=(8, 6),
118+
),
91119
fig_type=FigType.MATPLOTLIB,
92120
)
93121

122+
def usage_langauage_yearly(self, runtimes: pd.DataFrame) -> FigureProps:
94123
yearly_usage = pd.pivot_table(
95124
runtimes,
96125
index="year",
@@ -99,9 +128,25 @@ def create_graphs(self, runtimes: pd.DataFrame) -> None:
99128
aggfunc="count",
100129
fill_value=0,
101130
)
102-
self.saver.save(
131+
return FigureProps(
103132
name="usage_langauage_yearly",
104-
fig=yearly_usage.plot.bar(stacked=True, legend=False, figsize=(10, 6)),
133+
fig=yearly_usage.plot.bar(
134+
stacked=True,
135+
legend=False,
136+
figsize=(10, 6),
137+
),
105138
fig_type=FigType.MATPLOTLIB,
106139
legend=dict(loc="upper center", ncol=5),
107140
)
141+
142+
def overhead(self, runtimes: pd.DataFrame) -> FigureProps:
143+
runtimes["overhead"] = runtimes["execution"] - runtimes["runtime"]
144+
return FigureProps(
145+
name="overhead_language",
146+
fig=runtimes.boxplot(
147+
column="overhead",
148+
by="language",
149+
figsize=(8, 8),
150+
),
151+
fig_type=FigType.MATPLOTLIB,
152+
)

scripts/component/figure_saver.py

+17-15
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,36 @@ class FigType(StrEnum):
1111
PLOTLY = auto()
1212

1313

14+
@dataclass(frozen=True)
15+
class FigureProps:
16+
name: str
17+
fig: Any
18+
fig_type: FigType
19+
legend: Optional[dict] = None
20+
21+
1422
@dataclass(frozen=True)
1523
class FigureSaver:
1624
archive: bool
1725
archive_directory: Optional[Path]
1826

19-
def save(
20-
self,
21-
name: str,
22-
fig: Any,
23-
fig_type: FigType,
24-
legend: Optional[dict] = None,
25-
) -> None:
26-
fig_path = Path(f"images/{name}.png")
27+
def save(self, props: FigureProps) -> None:
28+
fig_path = Path(f"images/{props.name}.png")
2729
self.archive_figure(fig_path)
2830

2931
if fig_path.exists():
3032
print(f"Skipping {fig_path} as it already exists")
3133
else:
3234
print(f"Creating {fig_path}")
33-
if fig_type == FigType.MATPLOTLIB:
34-
self.save_matplotlib(fig, legend, fig_path)
35-
elif fig_type == FigType.PLOTLY:
36-
self.save_plotly(fig, fig_path)
35+
if props.fig_type == FigType.MATPLOTLIB:
36+
self.save_matplotlib(props.fig, props.legend, fig_path)
37+
elif props.fig_type == FigType.PLOTLY:
38+
self.save_plotly(props.fig, fig_path)
3739
else:
38-
raise Exception(f"Unhandled figure type: {fig_type}")
40+
raise Exception(f"Unhandled figure type: {props.fig_type}")
3941

40-
if fig_type == FigType.MATPLOTLIB:
41-
fig.get_figure().clear()
42+
if props.fig_type == FigType.MATPLOTLIB:
43+
props.fig.get_figure().clear()
4244

4345
def archive_figure(self, fig_path: Path) -> None:
4446
if not fig_path.exists() or not self.archive:

0 commit comments

Comments
 (0)