Skip to content

Commit 9eb8c05

Browse files
authored
Merge pull request #148 from faster-cpython/precise-perf-timing
More precise perf timings
2 parents b92fb4d + c312205 commit 9eb8c05

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

Diff for: bench_runner/scripts/profiling_plot.py

+22-5
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ def category_for_obj_sym(obj: str, sym: str) -> str:
200200
if obj.startswith("libc"):
201201
return "libc"
202202

203+
if obj == "[JIT]":
204+
return "jit"
205+
203206
if re.match(r".+\.so(\..+)?$", obj):
204207
return "library"
205208

@@ -233,14 +236,25 @@ def _main(input_dir: Path, output_prefix: Path):
233236
for row in csvreader:
234237
break
235238

239+
# Add up all the JIT entries into a single row
240+
rows = []
241+
jit_time = 0.0
236242
for row in csvreader:
237243
self_time, _, obj, sym = row
238-
244+
self_time = float(self_time)
245+
if obj == "[JIT]":
246+
jit_time += self_time
247+
else:
248+
rows.append((self_time, obj, sym))
249+
if jit_time != 0.0:
250+
rows.append((jit_time, "[JIT]", "jit"))
251+
rows.sort(reverse=True)
252+
253+
for self_time, obj, sym in rows:
239254
# python3.8 is the "parent" python orchestrating pyperformance
240255
if obj == "python3.8":
241256
continue
242257

243-
self_time = float(self_time) / 100.0
244258
if self_time <= 0.0:
245259
break
246260

@@ -295,7 +309,7 @@ def _main(input_dir: Path, output_prefix: Path):
295309
label=f"{category} {val:.2%}",
296310
left=bottom,
297311
hatch=hatches[i // 10],
298-
color=f"C{i%10}",
312+
color=f"C{i % 10}",
299313
)
300314
bottom += values
301315

@@ -313,10 +327,13 @@ def _main(input_dir: Path, output_prefix: Path):
313327
labels = [
314328
i < 10 and f"{x[1]} {x[0]:.2%}" or "" for i, x in enumerate(sorted_categories)
315329
]
316-
colors = [f"C{i%10}" for i in range(len(values))]
330+
colors = [f"C{i % 10}" for i in range(len(values))]
317331
hatches = [hatches[i // 10] for i in range(len(values))]
318332

319-
other = 1.0 - sum(values)
333+
if sum(values) < 1.0:
334+
other = 1.0 - sum(values)
335+
else:
336+
other = 0.0
320337
values.append(other)
321338
labels.append("")
322339
colors.append("#ddd")

Diff for: bench_runner/scripts/run_benchmarks.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,23 @@ def collect_pystats(
157157

158158

159159
def perf_to_csv(lines: Iterable[str], output: Path):
160+
event_count_prefix = "# Event count (approx.): "
161+
total = None
162+
160163
rows = []
161164
for line in lines:
162165
line = line.strip()
166+
if line.startswith(event_count_prefix):
167+
total = int(line[len(event_count_prefix) :].strip())
168+
continue
163169
if line.startswith("#") or line == "":
164170
continue
165-
children, self_time, _, shared, _, symbol = line.split(maxsplit=5)
166-
children = float(children[:-1])
167-
self = float(self_time[:-1])
168-
if children > 0.0 or self > 0.0:
169-
rows.append([self, children, shared, symbol])
171+
if total is None:
172+
raise ValueError("Could not find total sample count")
173+
_, period, _, shared, _, symbol = line.split(maxsplit=5)
174+
self_time = float(int(period)) / total
175+
if self_time > 0.0:
176+
rows.append([self_time, 0.0, shared, symbol])
170177

171178
rows.sort(key=itemgetter(0), reverse=True)
172179

@@ -192,7 +199,6 @@ def collect_perf(python: Path, benchmarks: str):
192199
command_prefix=[
193200
"perf",
194201
"record",
195-
"--call-graph=dwarf",
196202
"-o",
197203
"perf.data",
198204
"--",
@@ -209,6 +215,7 @@ def collect_perf(python: Path, benchmarks: str):
209215
"--stdio",
210216
"-g",
211217
"none",
218+
"--show-total-period",
212219
"-i",
213220
"perf.data",
214221
],

0 commit comments

Comments
 (0)