Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
48 changes: 48 additions & 0 deletions Doc/c-api/perfmaps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,51 @@ Note that holding an :term:`attached thread state` is not required for these API
This is called by the runtime itself during interpreter shut-down. In
general, there shouldn't be a reason to explicitly call this, except to
handle specific scenarios such as forking.

These unstable functions let you access and set perf map information
about the current frame from C code.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't make sense to me. What is the connection to the current frame?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, that text was completely out of place (and wrong). I'm deleting those lines entirely.


Note: Appends the content of the parent frame to the current one in perf maps.
Just like in frameobject.h.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What function(s) is this note for? What is the connection to frameobject.h?


.. c:function:: int PyUnstable_CopyPerfMapFile(const char *parent_filename)

Open the ``/tmp/perf-$pid.map`` file and append the content of *parent_filename*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should note what happens on Windows where this obviously won't work.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the case for all of these functions; the info should be in the beginning of the section.

This doesn't open the perf map file directly; it should use the same wording as PyUnstable_WritePerfMapEntry: “Will call :c:func:PyUnstable_PerfMapState_Init…”

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@encukou Would this wording be suitable then as a replacement for line 56 as:

"Calls :c:func:PyUnstable_PerfMapState_Init if the perf map is not yet
initialized, then append the content of parent_filename to the perf map."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@encukou or @StanFromIreland Could you verify this one too?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say only “Append contents of the file named parent_filename to the perf map.” in the opening paragraph, and add the note about _Init later (like in WritePerfMapEntry docs).

to it.

This function is only available on platforms that support perf maps (currently
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not accurate, the function is "available" on all platforms. But it should only be used on Linux. On Windows, it does nothing (it's not implemented).

Linux). Return ``0`` on success, ``-1`` on failure.

.. versionadded:: 3.13


.. c:function:: int PyUnstable_PerfTrampoline_CompileCode(PyCodeObject *code)

Compile the given code object using the current perf trampoline.
Comment thread
encukou marked this conversation as resolved.

The "current" trampoline is the one set by the runtime or the most recent
:c:func:`PyUnstable_PerfTrampoline_SetPersistAfterFork` call.

If no trampoline is set, falls back to normal compilation (no perf map entry).

:param code: The code object to compile.
:return: 0 on success, -1 on failure.

.. versionadded:: 3.13


.. c:function:: int PyUnstable_PerfTrampoline_SetPersistAfterFork(int enable)

Set whether the perf trampoline should persist after a fork.
Comment thread
encukou marked this conversation as resolved.

* If ``enable`` is true (non-zero): perf map file remains open/valid post-fork.
Child process inherits all existing perf map entries.
* If ``enable`` is false (zero): perf map closes post-fork.
Child process gets empty perf map.

Default: false (clears on fork).

:param enable: 1 to enable, 0 to disable.
:return: 0 on success, -1 on failure.

.. versionadded:: 3.13
4 changes: 0 additions & 4 deletions Tools/check-c-api-docs/ignored_c_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ PyStdPrinter_Type
Py_UniversalNewlineFgets
# cpython/setobject.h
PySet_MINSIZE
# cpython/ceval.h
PyUnstable_CopyPerfMapFile
PyUnstable_PerfTrampoline_CompileCode
PyUnstable_PerfTrampoline_SetPersistAfterFork
# cpython/genobject.h
PyAsyncGenASend_CheckExact
# cpython/longintrepr.h
Expand Down
Loading