Skip to content

Commit 6db5b65

Browse files
authored
Merge pull request #347 from faster-cpython/nogil-profiling-categories
Add new profiling categories, mainly for free-threading
2 parents 204029f + 8853a4b commit 6db5b65

File tree

2 files changed

+45
-14
lines changed

2 files changed

+45
-14
lines changed

bench_runner/scripts/profiling_plot.py

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,38 @@
3030
# These are matched in-order.
3131
CATEGORIES: dict[str, list[str]] = {
3232
"interpreter": [
33-
"_Py_GetBaseOpcode",
3433
"_Py_call_instrumentation_line",
34+
"_Py_GetBaseOpcode",
3535
"_PyCode_.+",
3636
"_PyEval.+",
3737
"_PyFrame_ClearExceptCode",
3838
"_PyFrame_New_NoTrack",
3939
"_PyFrame_Traverse",
4040
"_PyPegen_.+",
41-
"_PyThreadState_.+",
41+
"_PyStack_.+",
42+
"_PyVectorcall_.+",
4243
"advance",
4344
"call_instrumentation_vector.*",
4445
"initialize_locals",
4546
"PyAST_.+",
4647
"PyEval_.+",
48+
"PyInterpreterState.*",
4749
],
4850
"lookup": [
49-
"_Py_dict_lookup",
51+
"_Py_dict_lookup.*",
5052
"_Py_hashtable_.+",
5153
"_Py_type_getattro",
5254
"_PyType_Lookup",
53-
"_PyType_LookupRef",
55+
"_PyType_LookupRef.*",
5456
"builtin_getattr",
5557
"find_name_in_mro",
5658
"lookdict_split",
5759
"lookdict_unicode_nodummy",
5860
"lookdict_unicode",
61+
"lookup_maybe_method",
62+
"member_get",
5963
"PyMember_.*",
60-
"unicodekeys_lookup_unicode",
64+
"unicodekeys_lookup_unicode.*",
6165
"update_one_slot",
6266
],
6367
"gc": [
@@ -68,26 +72,36 @@
6872
".+_traverse",
6973
".+MaybeUntrack",
7074
"deduce_unreachable",
71-
"gc_collect_main",
72-
"gc_collect_region.*",
75+
"gc_collect.*",
76+
"mark_heap_visitor",
7377
"PyObject_IS_GC",
78+
"scan_heap.+",
7479
"type_is_gc",
80+
"update_refs.*",
7581
"visit_.+",
7682
],
7783
"memory": [
84+
"_?mi_.+",
7885
"_?PyMem_.+",
86+
"_Py_DecRefShared",
87+
"_Py_MergeZeroLocalRefcount",
7988
"_Py_NewReference",
89+
"_py_qsbr_.+",
90+
"_Py_TryIncrefCompare",
8091
"_PyObject_Free",
8192
"_PyObject_Malloc",
93+
"_PyType_AllocNoTrack",
8294
".+_alloc",
8395
".+[Nn]ew.*",
8496
".+Alloc",
8597
".+Calloc",
8698
".+dealloc",
8799
".+Dealloc",
100+
".+MiMalloc",
88101
".+Realloc",
89-
"memset.+",
90102
"memcpy.+",
103+
"memset.+",
104+
"Py_DECREF",
91105
],
92106
"dynamic": [
93107
"_?PyMapping_.+",
@@ -124,16 +138,20 @@
124138
"tuple.+",
125139
],
126140
"dict": [
127-
"_?PyDict_.+",
141+
"_?PyDict.+",
142+
"acquire_key_value",
128143
"build_indices_unicode",
129144
"clone_combined_dict_keys.+",
130145
"dict_.+",
131146
"dictiter_.+",
147+
"dictkeys_.+",
132148
"dictresize",
133149
"find_empty_slot",
134150
"free_keys_object",
151+
"insert_combined_dict",
135152
"insert_to_emptydict",
136153
"insertdict",
154+
"new_dict",
137155
"new_keys_object",
138156
"OrderedDict_.+",
139157
],
@@ -148,10 +166,11 @@
148166
],
149167
"str": [
150168
"_?PyUnicode.+",
151-
"_copy_characters.+",
169+
"_copy_characters.*",
152170
"ascii_decode",
153171
"bytes_.+",
154-
"intern_common.+",
172+
"find_first_nonascii",
173+
"intern_common.*",
155174
"intern_constants",
156175
"intern_string_constants",
157176
"PyBytes_.+",
@@ -163,22 +182,25 @@
163182
"unicode_.+",
164183
],
165184
"miscobj": [
185+
"_?PyGen_.+",
186+
"_?PySet_.+",
166187
"_?PySlice_.+",
167188
"_PyBuildSlice_ConsumeRefs",
168189
"_PyEval_SliceIndex",
190+
"_PyMake_Coro",
169191
"bytearray_.+",
170192
"deque_.+",
171193
"dequeiter_.+",
172194
"enum_.+",
173195
"gen_iternext",
196+
"get_or_create_weakref",
174197
"make_gen",
175198
"PyBool_.+",
176199
"PyBuffer_.+",
177-
"_?PyGen_.+",
178-
"_?PySet_.+",
179200
"range_.+",
180201
"set_.+",
181202
"setiter_.+",
203+
"weakref_.+",
182204
],
183205
"exceptions": [
184206
"_?PyErr_.*",
@@ -217,6 +239,13 @@
217239
"tok_.+",
218240
],
219241
"async": ["async_.+"],
242+
"threading": [
243+
"_?PyThreadState_.+",
244+
"_PyCriticalSection.+",
245+
"_PySeqLock_.+",
246+
"disable_deferred_refcounting",
247+
"PyThread.*",
248+
],
220249
}
221250

222251
COLOR_ORDER = ["jit", "kernel", "libc", "library"] + list(CATEGORIES.keys())
@@ -249,7 +278,7 @@ def category_for_obj_sym(obj: str, sym: str) -> str:
249278
if obj == "python":
250279
for category, patterns in CATEGORIES.items():
251280
for pattern in patterns:
252-
if re.match(f"^{pattern}$", sym.split()[0]):
281+
if re.match(f"^{pattern}$", sym.split()[0].split(".")[0]):
253282
return category
254283

255284
return "unknown"

bench_runner/scripts/run_benchmarks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ def collect_perf(python: PathLike, benchmarks: str):
248248
perf_to_csv(
249249
output.splitlines(), PROFILING_RESULTS / f"{benchmark}.perf.csv"
250250
)
251+
else:
252+
print(f"No perf.data file generated for {benchmark}", file=sys.stderr)
251253

252254

253255
def update_metadata(

0 commit comments

Comments
 (0)