File tree Expand file tree Collapse file tree 4 files changed +17
-1
lines changed
Filter options
Expand file tree Collapse file tree 4 files changed +17
-1
lines changed
Original file line number Diff line number Diff line change @@ -155,6 +155,9 @@ active since the start of the Python interpreter, you can use the `-Xperf` optio
155
155
156
156
$ python -Xperf my_script.py
157
157
158
+ You can also set the :envvar: `PYTHONPERFSUPPORT ` to a nonzero value to actiavate perf
159
+ profiling mode globally.
160
+
158
161
There is also support for dynamically activating and deactivating the perf
159
162
profiling mode by using the APIs in the :mod: `sys ` module:
160
163
Original file line number Diff line number Diff line change @@ -582,6 +582,8 @@ Miscellaneous options
582
582
.. versionadded :: 3.11
583
583
The ``-X frozen_modules `` option.
584
584
585
+ .. versionadded :: 3.12
586
+ The ``-X perf `` option.
585
587
586
588
587
589
Options you shouldn't use
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ def baz():
58
58
script = make_script (script_dir , "perftest" , code )
59
59
with subprocess .Popen (
60
60
[sys .executable , "-Xperf" , script ],
61
- universal_newlines = True ,
61
+ text = True ,
62
62
stderr = subprocess .PIPE ,
63
63
stdout = subprocess .PIPE ,
64
64
) as process :
Original file line number Diff line number Diff line change @@ -284,12 +284,23 @@ new_code_arena(void)
284
284
void * start = & _Py_trampoline_func_start ;
285
285
void * end = & _Py_trampoline_func_end ;
286
286
size_t code_size = end - start ;
287
+ // TODO: Check the effect of alignment of the code chunks. Initial investigation
288
+ // showed that this has no effect on performance in x86-64 or aarch64 and the current
289
+ // version has the advantage that the unwinder in GDB can unwind across JIT-ed code.
290
+ //
291
+ // We should check the values in the future and see if there is a
292
+ // measurable performance improvement by rounding trampolines up to 32-bit
293
+ // or 64-bit alignment.
287
294
288
295
size_t n_copies = mem_size / code_size ;
289
296
for (size_t i = 0 ; i < n_copies ; i ++ ) {
290
297
memcpy (memory + i * code_size , start , code_size * sizeof (char ));
291
298
}
292
299
// Some systems may prevent us from creating executable code on the fly.
300
+ // TODO: Call icache invalidation intrinsics if available:
301
+ // __builtin___clear_cache/__clear_cache (depending if clang/gcc). This is
302
+ // technically not necessary but we could be missing something so better be
303
+ // safe.
293
304
int res = mprotect (memory , mem_size , PROT_READ | PROT_EXEC );
294
305
if (res == -1 ) {
295
306
PyErr_SetFromErrno (PyExc_OSError );
You can’t perform that action at this time.
0 commit comments