Skip to content

Commit 02b49c5

Browse files
authored
pythongh-107954: Fix configuration type for the perf profiler (python#124636)
1 parent 425587a commit 02b49c5

File tree

5 files changed

+28
-15
lines changed

5 files changed

+28
-15
lines changed

Doc/c-api/init_config.rst

+13-8
Original file line numberDiff line numberDiff line change
@@ -1248,19 +1248,24 @@ PyConfig
12481248
12491249
.. c:member:: int perf_profiling
12501250
1251-
Enable compatibility mode with the perf profiler?
1251+
Enable the Linux ``perf`` profiler support?
12521252
1253-
If non-zero, initialize the perf trampoline. See :ref:`perf_profiling`
1254-
for more information.
1253+
If equals to ``1``, enable support for the Linux ``perf`` profiler.
12551254
1256-
Set by :option:`-X perf <-X>` command-line option and by the
1257-
:envvar:`PYTHON_PERF_JIT_SUPPORT` environment variable for perf support
1258-
with stack pointers and :option:`-X perf_jit <-X>` command-line option
1259-
and by the :envvar:`PYTHON_PERF_JIT_SUPPORT` environment variable for perf
1260-
support with DWARF JIT information.
1255+
If equals to ``2``, enable support for the Linux ``perf`` profiler with
1256+
DWARF JIT support.
1257+
1258+
Set to ``1`` by :option:`-X perf <-X>` command-line option and the
1259+
:envvar:`PYTHONPERFSUPPORT` environment variable.
1260+
1261+
Set to ``2`` by the :option:`-X perf_jit <-X>` command-line option and
1262+
the :envvar:`PYTHON_PERF_JIT_SUPPORT` environment variable.
12611263
12621264
Default: ``-1``.
12631265
1266+
.. seealso::
1267+
See :ref:`perf_profiling` for more information.
1268+
12641269
.. versionadded:: 3.12
12651270
12661271
.. c:member:: int use_environment

Lib/test/test_capi/test_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def test_config_get(self):
6868
("parser_debug", bool, None),
6969
("parse_argv", bool, None),
7070
("pathconfig_warnings", bool, None),
71-
("perf_profiling", bool, None),
71+
("perf_profiling", int, None),
7272
("platlibdir", str, "platlibdir"),
7373
("prefix", str | None, "prefix"),
7474
("program_name", str, None),

Lib/test/test_embed.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
560560
'cpu_count': -1,
561561
'faulthandler': False,
562562
'tracemalloc': 0,
563-
'perf_profiling': False,
563+
'perf_profiling': 0,
564564
'import_time': False,
565565
'code_debug_ranges': True,
566566
'show_ref_count': False,
@@ -652,7 +652,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
652652
use_hash_seed=False,
653653
faulthandler=False,
654654
tracemalloc=False,
655-
perf_profiling=False,
655+
perf_profiling=0,
656656
pathconfig_warnings=False,
657657
)
658658
if MS_WINDOWS:
@@ -966,7 +966,7 @@ def test_init_from_config(self):
966966
'use_hash_seed': True,
967967
'hash_seed': 123,
968968
'tracemalloc': 2,
969-
'perf_profiling': False,
969+
'perf_profiling': 0,
970970
'import_time': True,
971971
'code_debug_ranges': False,
972972
'show_ref_count': True,
@@ -1031,7 +1031,7 @@ def test_init_compat_env(self):
10311031
'use_hash_seed': True,
10321032
'hash_seed': 42,
10331033
'tracemalloc': 2,
1034-
'perf_profiling': False,
1034+
'perf_profiling': 0,
10351035
'import_time': True,
10361036
'code_debug_ranges': False,
10371037
'malloc_stats': True,
@@ -1051,6 +1051,7 @@ def test_init_compat_env(self):
10511051
'module_search_paths': self.IGNORE_CONFIG,
10521052
'safe_path': True,
10531053
'int_max_str_digits': 4567,
1054+
'perf_profiling': 1,
10541055
}
10551056
if Py_STATS:
10561057
config['_pystats'] = 1
@@ -1066,7 +1067,7 @@ def test_init_python_env(self):
10661067
'use_hash_seed': True,
10671068
'hash_seed': 42,
10681069
'tracemalloc': 2,
1069-
'perf_profiling': False,
1070+
'perf_profiling': 0,
10701071
'import_time': True,
10711072
'code_debug_ranges': False,
10721073
'malloc_stats': True,
@@ -1086,6 +1087,7 @@ def test_init_python_env(self):
10861087
'module_search_paths': self.IGNORE_CONFIG,
10871088
'safe_path': True,
10881089
'int_max_str_digits': 4567,
1090+
'perf_profiling': 1,
10891091
}
10901092
if Py_STATS:
10911093
config['_pystats'] = True
@@ -1763,6 +1765,7 @@ def test_initconfig_api(self):
17631765
'xoptions': {'faulthandler': True},
17641766
'hash_seed': 10,
17651767
'use_hash_seed': True,
1768+
'perf_profiling': 2,
17661769
}
17671770
config_dev_mode(preconfig, config)
17681771
self.check_all_configs("test_initconfig_api", config, preconfig,

Programs/_testembed.c

+5
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ static void set_most_env_vars(void)
810810
#ifdef Py_STATS
811811
putenv("PYTHONSTATS=1");
812812
#endif
813+
putenv("PYTHONPERFSUPPORT=1");
813814
}
814815

815816

@@ -1844,6 +1845,10 @@ static int test_initconfig_api(void)
18441845
goto error;
18451846
}
18461847

1848+
if (PyInitConfig_SetInt(config, "perf_profiling", 2) < 0) {
1849+
goto error;
1850+
}
1851+
18471852
// Set a UTF-8 string (program_name)
18481853
if (PyInitConfig_SetStr(config, "program_name", PROGRAM_NAME_UTF8) < 0) {
18491854
goto error;

Python/initconfig.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ static const PyConfigSpec PYCONFIG_SPEC[] = {
150150
SPEC(orig_argv, WSTR_LIST, READ_ONLY, SYS_ATTR("orig_argv")),
151151
SPEC(parse_argv, BOOL, READ_ONLY, NO_SYS),
152152
SPEC(pathconfig_warnings, BOOL, READ_ONLY, NO_SYS),
153-
SPEC(perf_profiling, BOOL, READ_ONLY, NO_SYS),
153+
SPEC(perf_profiling, UINT, READ_ONLY, NO_SYS),
154154
SPEC(program_name, WSTR, READ_ONLY, NO_SYS),
155155
SPEC(run_command, WSTR_OPT, READ_ONLY, NO_SYS),
156156
SPEC(run_filename, WSTR_OPT, READ_ONLY, NO_SYS),

0 commit comments

Comments
 (0)