Skip to content

Commit ed63ba5

Browse files
authored
Merge pull request #153 from faster-cpython/fixed-colors
Used fixed colors in profiling plot
2 parents d05ce43 + 942c3a8 commit ed63ba5

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

Diff for: bench_runner/scripts/profiling_plot.py

+22-5
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,18 @@
191191
],
192192
}
193193

194+
COLOR_ORDER = ["jit", "kernel", "libc", "library"] + list(CATEGORIES.keys())
195+
196+
197+
def get_color_and_hatch(category: str) -> tuple[str, str]:
198+
hatches = ["", "//", "\\\\"]
199+
try:
200+
index = COLOR_ORDER.index(category)
201+
except ValueError:
202+
return "#ddd", ""
203+
204+
return f"C{index % 10}", hatches[index // 10]
205+
194206

195207
@functools.cache
196208
def category_for_obj_sym(obj: str, sym: str) -> str:
@@ -227,6 +239,9 @@ def _main(input_dir: Path, output_prefix: Path):
227239
for csv_path in sorted(input_dir.glob("*.csv")):
228240
stem = csv_path.stem.split(".", 1)[0]
229241

242+
if stem.startswith("sqlalchemy"):
243+
continue
244+
230245
md.write(f"\n## {stem}\n\n")
231246
md.write("| percentage | object | symbol | category |\n")
232247
md.write("| ---: | :--- | :--- | :--- |\n")
@@ -242,6 +257,8 @@ def _main(input_dir: Path, output_prefix: Path):
242257
for row in csvreader:
243258
self_time, _, obj, sym = row
244259
self_time = float(self_time)
260+
if self_time > 100.0:
261+
print(f"{stem} Invalid data")
245262
if obj == "[JIT]":
246263
jit_time += self_time
247264
else:
@@ -295,21 +312,21 @@ def _main(input_dir: Path, output_prefix: Path):
295312
bottom = np.zeros(len(results))
296313
names = list(results.keys())[::-1]
297314

298-
hatches = ["", "//", "\\\\"]
299315
for i, (val, category) in enumerate(sorted_categories):
300316
if category == "unknown":
301317
continue
302318
values = np.array(
303319
[results[name].get(category, 0.0) for name in names], np.float64
304320
)
321+
color, hatch = get_color_and_hatch(category)
305322
ax.barh(
306323
names,
307324
values,
308325
0.5,
309326
label=f"{category} {val:.2%}",
310327
left=bottom,
311-
hatch=hatches[i // 10],
312-
color=f"C{i % 10}",
328+
hatch=hatch,
329+
color=color,
313330
)
314331
bottom += values
315332

@@ -327,8 +344,8 @@ def _main(input_dir: Path, output_prefix: Path):
327344
labels = [
328345
i < 10 and f"{x[1]} {x[0]:.2%}" or "" for i, x in enumerate(sorted_categories)
329346
]
330-
colors = [f"C{i % 10}" for i in range(len(values))]
331-
hatches = [hatches[i // 10] for i in range(len(values))]
347+
colors = [get_color_and_hatch(cat[1])[0] for cat in sorted_categories]
348+
hatches = [get_color_and_hatch(cat[1])[1] for cat in sorted_categories]
332349

333350
if sum(values) < 1.0:
334351
other = 1.0 - sum(values)

0 commit comments

Comments
 (0)