https://github.com/python/cpython/commit/02b49c51501f5eeef3ab5d74fb9eace1151a1359
commit: 02b49c51501f5eeef3ab5d74fb9eace1151a1359
branch: main
author: Pablo Galindo Salgado <[email protected]>
committer: ambv <[email protected]>
date: 2024-09-28T01:50:16+02:00
summary:

gh-107954: Fix configuration type for the perf profiler (#124636)

files:
M Doc/c-api/init_config.rst
M Lib/test/test_capi/test_config.py
M Lib/test/test_embed.py
M Programs/_testembed.c
M Python/initconfig.c

diff --git a/Doc/c-api/init_config.rst b/Doc/c-api/init_config.rst
index 0ef7d015be9b93..9dc9ba61e7a60f 100644
--- a/Doc/c-api/init_config.rst
+++ b/Doc/c-api/init_config.rst
@@ -1248,19 +1248,24 @@ PyConfig
 
    .. c:member:: int perf_profiling
 
-      Enable compatibility mode with the perf profiler?
+      Enable the Linux ``perf`` profiler support?
 
-      If non-zero, initialize the perf trampoline. See :ref:`perf_profiling`
-      for more information.
+      If equals to ``1``, enable support for the Linux ``perf`` profiler.
 
-      Set by :option:`-X perf <-X>` command-line option and by the
-      :envvar:`PYTHON_PERF_JIT_SUPPORT` environment variable for perf support
-      with stack pointers and :option:`-X perf_jit <-X>` command-line option
-      and by the :envvar:`PYTHON_PERF_JIT_SUPPORT` environment variable for 
perf
-      support with DWARF JIT information.
+      If equals to ``2``, enable support for the Linux ``perf`` profiler with
+      DWARF JIT support.
+
+      Set to ``1`` by :option:`-X perf <-X>` command-line option and the
+      :envvar:`PYTHONPERFSUPPORT` environment variable.
+
+      Set to ``2`` by the :option:`-X perf_jit <-X>` command-line option and
+      the :envvar:`PYTHON_PERF_JIT_SUPPORT` environment variable.
 
       Default: ``-1``.
 
+      .. seealso::
+         See :ref:`perf_profiling` for more information.
+
       .. versionadded:: 3.12
 
    .. c:member:: int use_environment
diff --git a/Lib/test/test_capi/test_config.py 
b/Lib/test/test_capi/test_config.py
index 01637e1cb7b6e5..71fb9ae45c7c30 100644
--- a/Lib/test/test_capi/test_config.py
+++ b/Lib/test/test_capi/test_config.py
@@ -68,7 +68,7 @@ def test_config_get(self):
             ("parser_debug", bool, None),
             ("parse_argv", bool, None),
             ("pathconfig_warnings", bool, None),
-            ("perf_profiling", bool, None),
+            ("perf_profiling", int, None),
             ("platlibdir", str, "platlibdir"),
             ("prefix", str | None, "prefix"),
             ("program_name", str, None),
diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py
index 7c5cb855a397ab..3edc19d8254754 100644
--- a/Lib/test/test_embed.py
+++ b/Lib/test/test_embed.py
@@ -560,7 +560,7 @@ class InitConfigTests(EmbeddingTestsMixin, 
unittest.TestCase):
         'cpu_count': -1,
         'faulthandler': False,
         'tracemalloc': 0,
-        'perf_profiling': False,
+        'perf_profiling': 0,
         'import_time': False,
         'code_debug_ranges': True,
         'show_ref_count': False,
@@ -652,7 +652,7 @@ class InitConfigTests(EmbeddingTestsMixin, 
unittest.TestCase):
         use_hash_seed=False,
         faulthandler=False,
         tracemalloc=False,
-        perf_profiling=False,
+        perf_profiling=0,
         pathconfig_warnings=False,
     )
     if MS_WINDOWS:
@@ -966,7 +966,7 @@ def test_init_from_config(self):
             'use_hash_seed': True,
             'hash_seed': 123,
             'tracemalloc': 2,
-            'perf_profiling': False,
+            'perf_profiling': 0,
             'import_time': True,
             'code_debug_ranges': False,
             'show_ref_count': True,
@@ -1031,7 +1031,7 @@ def test_init_compat_env(self):
             'use_hash_seed': True,
             'hash_seed': 42,
             'tracemalloc': 2,
-            'perf_profiling': False,
+            'perf_profiling': 0,
             'import_time': True,
             'code_debug_ranges': False,
             'malloc_stats': True,
@@ -1051,6 +1051,7 @@ def test_init_compat_env(self):
             'module_search_paths': self.IGNORE_CONFIG,
             'safe_path': True,
             'int_max_str_digits': 4567,
+            'perf_profiling': 1,
         }
         if Py_STATS:
             config['_pystats'] = 1
@@ -1066,7 +1067,7 @@ def test_init_python_env(self):
             'use_hash_seed': True,
             'hash_seed': 42,
             'tracemalloc': 2,
-            'perf_profiling': False,
+            'perf_profiling': 0,
             'import_time': True,
             'code_debug_ranges': False,
             'malloc_stats': True,
@@ -1086,6 +1087,7 @@ def test_init_python_env(self):
             'module_search_paths': self.IGNORE_CONFIG,
             'safe_path': True,
             'int_max_str_digits': 4567,
+            'perf_profiling': 1,
         }
         if Py_STATS:
             config['_pystats'] = True
@@ -1763,6 +1765,7 @@ def test_initconfig_api(self):
             'xoptions': {'faulthandler': True},
             'hash_seed': 10,
             'use_hash_seed': True,
+            'perf_profiling': 2,
         }
         config_dev_mode(preconfig, config)
         self.check_all_configs("test_initconfig_api", config, preconfig,
diff --git a/Programs/_testembed.c b/Programs/_testembed.c
index 10ee6b7be23e21..ab2b2d06cca15d 100644
--- a/Programs/_testembed.c
+++ b/Programs/_testembed.c
@@ -810,6 +810,7 @@ static void set_most_env_vars(void)
 #ifdef Py_STATS
     putenv("PYTHONSTATS=1");
 #endif
+    putenv("PYTHONPERFSUPPORT=1");
 }
 
 
@@ -1844,6 +1845,10 @@ static int test_initconfig_api(void)
         goto error;
     }
 
+    if (PyInitConfig_SetInt(config, "perf_profiling", 2) < 0) {
+        goto error;
+    }
+
     // Set a UTF-8 string (program_name)
     if (PyInitConfig_SetStr(config, "program_name", PROGRAM_NAME_UTF8) < 0) {
         goto error;
diff --git a/Python/initconfig.c b/Python/initconfig.c
index d93244f7f41084..58ac5e7d7eaeff 100644
--- a/Python/initconfig.c
+++ b/Python/initconfig.c
@@ -150,7 +150,7 @@ static const PyConfigSpec PYCONFIG_SPEC[] = {
     SPEC(orig_argv, WSTR_LIST, READ_ONLY, SYS_ATTR("orig_argv")),
     SPEC(parse_argv, BOOL, READ_ONLY, NO_SYS),
     SPEC(pathconfig_warnings, BOOL, READ_ONLY, NO_SYS),
-    SPEC(perf_profiling, BOOL, READ_ONLY, NO_SYS),
+    SPEC(perf_profiling, UINT, READ_ONLY, NO_SYS),
     SPEC(program_name, WSTR, READ_ONLY, NO_SYS),
     SPEC(run_command, WSTR_OPT, READ_ONLY, NO_SYS),
     SPEC(run_filename, WSTR_OPT, READ_ONLY, NO_SYS),

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to