Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-96143: Allow Linux perf profiler to see Python calls #96123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 50 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
2a918e4
Allow Linux perf profiler to see Python calls
pablogsal Aug 7, 2022
cea1420
Add test
pablogsal Aug 20, 2022
4107c53
Update PCbuild/_freeze_module.vcxproj.filters
pablogsal Aug 20, 2022
5e34e66
munmap pages on shutdown, keep FILE open
tiran Aug 21, 2022
a26a850
Fix tests
pablogsal Aug 21, 2022
8170b24
Skip tests if sanitizer is active
pablogsal Aug 21, 2022
9df1c93
Add ARM64 code generated by aarch64-linux-gnu-gcc
tiran Aug 21, 2022
d8f396d
Address review comments
pablogsal Aug 21, 2022
d35c5d7
Secure fopen, use unraisable, continue on error
tiran Aug 22, 2022
2664b12
cleanup resources, set to uninit
tiran Aug 22, 2022
e6c365a
Allow to set custom callbacks
pablogsal Aug 22, 2022
5513fb1
Add comment to asm file
pablogsal Aug 22, 2022
76c7dc0
fixup! Merge pull request #36 from tiran/perf-file
pablogsal Aug 22, 2022
a545b3c
Add comments to the perf_trampoline file and format file
pablogsal Aug 22, 2022
5130c8d
Correct News entry
pablogsal Aug 22, 2022
991366b
Update Lib/test/test_perf_profiler.py
pablogsal Aug 22, 2022
0a0e53d
Rename perf macro
pablogsal Aug 22, 2022
7ea3371
Fix some typos
pablogsal Aug 22, 2022
680db66
Improve perf profiler tests
tiran Aug 22, 2022
1263a29
Add guard for initialization
pablogsal Aug 22, 2022
a42bde5
Add acks
pablogsal Aug 22, 2022
b780d2a
Initialize perf file lazily
pablogsal Aug 22, 2022
04bf416
Address review comments
pablogsal Aug 22, 2022
7558df2
Complain if there is already a evaluator frame when deactivating/acti…
pablogsal Aug 22, 2022
d1ebc88
Fix some errors on CI
pablogsal Aug 22, 2022
a83a31b
Reorder arguments to speed up trampoline
tiran Aug 22, 2022
0febd84
Preserve frame pointer
pablogsal Aug 22, 2022
dc5a6a5
Support perf backend and better handle forks
pablogsal Aug 22, 2022
be72b92
Fix more fork problems
pablogsal Aug 22, 2022
b5739f4
Update Lib/test/test_perf_profiler.py
pablogsal Aug 22, 2022
04c0c14
Handle missing backends
pablogsal Aug 22, 2022
e810ce6
Update Lib/test/test_perf_profiler.py
pablogsal Aug 22, 2022
bc8bf4e
clean up perf files
pablogsal Aug 22, 2022
0252845
Update Misc/NEWS.d/next/Core and Builtins/2022-08-20-18-36-40.gh-issu…
pablogsal Aug 22, 2022
264bed7
Test fork support, fix some fork problems and improve test file
pablogsal Aug 23, 2022
a31a498
Add more tests
pablogsal Aug 23, 2022
f591e8d
Update Objects/perf_trampoline.c
pablogsal Aug 23, 2022
0af2a08
make argument mandatory
pablogsal Aug 23, 2022
861ae09
Use struct for perf callbacks
tiran Aug 23, 2022
3058cf0
Rename macro to PY_HAVE_PERF_TRAMPOLINE
tiran Aug 23, 2022
07ee991
Merge pull request #39 from tiran/perf_callback_struct
pablogsal Aug 23, 2022
be612a9
Allow gdb to unwind
pablogsal Aug 23, 2022
f4e3fff
Merge remote-tracking branch 'upstream/main' into perf
pablogsal Aug 25, 2022
c27f8b1
Add docs
pablogsal Aug 25, 2022
e27a2c4
fixup! Add docs
pablogsal Aug 25, 2022
81c7f4b
fixup! fixup! Add docs
pablogsal Aug 25, 2022
ef0650b
Update sys API names in the NEWS entry.
gpshead Aug 29, 2022
d8932d2
Add environment variable
pablogsal Aug 29, 2022
0f303ff
Merge branch 'main' into perf
pablogsal Aug 29, 2022
e3f846e
Document the env var and the -X option
pablogsal Aug 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename macro to PY_HAVE_PERF_TRAMPOLINE
  • Loading branch information
tiran committed Aug 23, 2022
commit 3058cf0ce6d7f709683d734d65f9f7c37b542bff
2 changes: 1 addition & 1 deletion Include/internal/pycore_ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ extern int _PyPerfTrampoline_Init(int activate);
extern int _PyPerfTrampoline_Fini(void);
extern int _PyIsPerfTrampolineActive(void);
extern PyStatus _PyPerfTrampoline_AfterFork_Child(void);
#ifdef _PY_HAVE_PERF_TRAMPOLINE
#ifdef PY_HAVE_PERF_TRAMPOLINE
extern _PyPerf_Callbacks _Py_perfmap_callbacks;
#endif

Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_perf_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


def supports_trampoline_profiling():
perf_trampoline = sysconfig.get_config_var("PERF_TRAMPOLINE_SUPPORT")
perf_trampoline = sysconfig.get_config_var("PY_HAVE_PERF_TRAMPOLINE")
if not perf_trampoline:
return False
return int(perf_trampoline) == 1
Expand Down
1 change: 0 additions & 1 deletion Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ DTRACE= @DTRACE@
DFLAGS= @DFLAGS@
DTRACE_HEADERS= @DTRACE_HEADERS@
DTRACE_OBJS= @DTRACE_OBJS@
PERF_TRAMPOLINE_SUPPORT= @PERF_TRAMPOLINE_SUPPORT@

GNULD= @GNULD@

Expand Down
16 changes: 8 additions & 8 deletions Objects/perf_trampoline.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ typedef enum {
PERF_STATUS_OK = 1, // Perf trampoline is ready to be executed
} perf_status_t;

#ifdef _PY_HAVE_PERF_TRAMPOLINE
#ifdef PY_HAVE_PERF_TRAMPOLINE

#include <fcntl.h>
#include <stdio.h>
Expand Down Expand Up @@ -386,12 +386,12 @@ py_trampoline_evaluator(PyThreadState *ts, _PyInterpreterFrame *frame,
// Something failed, fall back to the default evaluator.
return _PyEval_EvalFrameDefault(ts, frame, throw);
}
#endif // _PY_HAVE_PERF_TRAMPOLINE
#endif // PY_HAVE_PERF_TRAMPOLINE

int
_PyIsPerfTrampolineActive(void)
{
#ifdef _PY_HAVE_PERF_TRAMPOLINE
#ifdef PY_HAVE_PERF_TRAMPOLINE
PyThreadState *tstate = _PyThreadState_GET();
return tstate->interp->eval_frame == py_trampoline_evaluator;
#endif
Expand All @@ -404,7 +404,7 @@ _PyPerfTrampoline_GetCallbacks(_PyPerf_Callbacks *callbacks)
if (callbacks == NULL) {
return;
}
#ifdef _PY_HAVE_PERF_TRAMPOLINE
#ifdef PY_HAVE_PERF_TRAMPOLINE
callbacks->init_state = trampoline_api.init_state;
callbacks->write_state = trampoline_api.write_state;
callbacks->free_state = trampoline_api.free_state;
Expand All @@ -418,7 +418,7 @@ _PyPerfTrampoline_SetCallbacks(_PyPerf_Callbacks *callbacks)
if (callbacks == NULL) {
return -1;
}
#ifdef _PY_HAVE_PERF_TRAMPOLINE
#ifdef PY_HAVE_PERF_TRAMPOLINE
if (trampoline_api.state) {
_PyPerfTrampoline_Fini();
}
Expand All @@ -434,7 +434,7 @@ _PyPerfTrampoline_SetCallbacks(_PyPerf_Callbacks *callbacks)
int
_PyPerfTrampoline_Init(int activate)
{
#ifdef _PY_HAVE_PERF_TRAMPOLINE
#ifdef PY_HAVE_PERF_TRAMPOLINE
PyThreadState *tstate = _PyThreadState_GET();
if (tstate->interp->eval_frame &&
tstate->interp->eval_frame != py_trampoline_evaluator) {
Expand Down Expand Up @@ -471,7 +471,7 @@ _PyPerfTrampoline_Init(int activate)
int
_PyPerfTrampoline_Fini(void)
{
#ifdef _PY_HAVE_PERF_TRAMPOLINE
#ifdef PY_HAVE_PERF_TRAMPOLINE
PyThreadState *tstate = _PyThreadState_GET();
if (tstate->interp->eval_frame == py_trampoline_evaluator) {
tstate->interp->eval_frame = NULL;
Expand All @@ -489,7 +489,7 @@ _PyPerfTrampoline_Fini(void)
PyStatus
_PyPerfTrampoline_AfterFork_Child(void)
{
#ifdef _PY_HAVE_PERF_TRAMPOLINE
#ifdef PY_HAVE_PERF_TRAMPOLINE
// Restart trampoline in file in child.
int was_active = _PyIsPerfTrampolineActive();
_PyPerfTrampoline_Fini();
Expand Down
2 changes: 1 addition & 1 deletion Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ init_interp_main(PyThreadState *tstate)
}


#ifdef _PY_HAVE_PERF_TRAMPOLINE
#ifdef PY_HAVE_PERF_TRAMPOLINE
if (config->perf_profiling) {
if (_PyPerfTrampoline_SetCallbacks(&_Py_perfmap_callbacks) < 0 ||
_PyPerfTrampoline_Init(config->perf_profiling) < 0) {
Expand Down
4 changes: 2 additions & 2 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2008,7 +2008,7 @@ sys_activate_stack_trampoline_impl(PyObject *module, const char *backend)
/*[clinic end generated code: output=5783cdeb51874b43 input=58d7244062b933a8]*/
{
if (strcmp(backend, "perf") == 0) {
#ifdef _PY_HAVE_PERF_TRAMPOLINE
#ifdef PY_HAVE_PERF_TRAMPOLINE
_PyPerf_Callbacks cur_cb;
_PyPerfTrampoline_GetCallbacks(&cur_cb);
if (cur_cb.init_state != _Py_perfmap_callbacks.init_state) {
Expand Down Expand Up @@ -2059,7 +2059,7 @@ static PyObject *
sys_is_stack_trampoline_active_impl(PyObject *module)
/*[clinic end generated code: output=ab2746de0ad9d293 input=061fa5776ac9dd59]*/
{
#ifdef _PY_HAVE_PERF_TRAMPOLINE
#ifdef PY_HAVE_PERF_TRAMPOLINE
if (_PyIsPerfTrampolineActive()) {
Py_RETURN_TRUE;
}
Expand Down
6 changes: 1 addition & 5 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3435,12 +3435,9 @@ AS_CASE([$PLATFORM_TRIPLET],
)
AC_MSG_RESULT([$perf_trampoline])

AC_SUBST(PERF_TRAMPOLINE_SUPPORT)
PERF_TRAMPOLINE_SUPPORT=
AS_VAR_IF([perf_trampoline], [yes], [
AC_DEFINE([_PY_HAVE_PERF_TRAMPOLINE], [1], [Define to 1 if you have the perf trampoline.])
AC_DEFINE([PY_HAVE_PERF_TRAMPOLINE], [1], [Define to 1 if you have the perf trampoline.])
PERF_TRAMPOLINE_OBJ=Objects/asm_trampoline.o
PERF_TRAMPOLINE_SUPPORT=1

dnl perf needs frame pointers for unwinding, include compiler option in debug builds
AS_VAR_IF([Py_DEBUG], [true], [
Expand Down
6 changes: 3 additions & 3 deletions pyconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,9 @@
/* Define if you want to coerce the C locale to a UTF-8 based locale */
#undef PY_COERCE_C_LOCALE

/* Define to 1 if you have the perf trampoline. */
#undef PY_HAVE_PERF_TRAMPOLINE

/* Define to 1 to build the sqlite module with loadable extensions support. */
#undef PY_SQLITE_ENABLE_LOAD_EXTENSION

Expand Down Expand Up @@ -1799,9 +1802,6 @@
/* framework name */
#undef _PYTHONFRAMEWORK

/* Define to 1 if you have the perf trampoline. */
#undef _PY_HAVE_PERF_TRAMPOLINE

/* Define to force use of thread-safe errno, h_errno, and other functions */
#undef _REENTRANT

Expand Down