Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GH-93841: Turn stats on and off, clear and dump them at runtime.#93843

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
markshannon merged 8 commits intopython:mainfromfaster-cpython:on-off-stats
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from1 commit
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
PrevPrevious commit
NextNext commit
Allow stats to be turned on and off, and be cleared.
  • Loading branch information
@markshannon
markshannon committedJun 15, 2022
commitdaa5487a4dee22ed372c238b42c12fd279e36e1f
1 change: 1 addition & 0 deletionsInclude/pystats.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -77,6 +77,7 @@ typedef struct _stats {
PyAPI_DATA(PyStats) _py_stats_struct;
PyAPI_DATA(PyStats *) _py_stats;

extern void _Py_StatsClear(void);
extern void _Py_PrintSpecializationStats(int to_file);

#ifdef _PY_INTERPRETER
Expand Down
80 changes: 79 additions & 1 deletionPython/clinic/sysmodule.c.h
View file
Open in desktop

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

6 changes: 6 additions & 0 deletionsPython/specialize.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -210,6 +210,12 @@ print_stats(FILE *out, PyStats *stats) {
print_object_stats(out, &stats->object_stats);
}

void
_Py_StatsClear(void)
{
_Py_stat_struct = { 0 };
}

void
_Py_PrintSpecializationStats(int to_file)
{
Expand Down
62 changes: 62 additions & 0 deletionsPython/sysmodule.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1909,6 +1909,63 @@ sys_is_finalizing_impl(PyObject *module)
return PyBool_FromLong(_Py_IsFinalizing());
}

#ifdef Py_STATS
/*[clinic input]
sys._stats_on

Turns on stats gathering (stats gathering is on by default)
[clinic start generated code]*/

static PyObject *
sys__stats_on_impl(PyObject *module)
/*[clinic end generated code: output=aca53eafcbb4d9fe input=f4bef5763c4387b8]*/

static PyObject *
sys__stats_on(PyObject *module)
/*[clinic end generated code]*/
{
_py_stats = &_py_stats_struct;
Py_RETURN_NONE;
}

/*[clinic input]
sys._stats_off

Turns off stats gathering (stats gathering is on by default)
[clinic start generated code]*/

static PyObject *
sys__stats_off_impl(PyObject *module)
/*[clinic end generated code: output=1534c1ee63812214 input=ec6e593e39b12b4a]*/

static PyObject *
sys__stats_off(PyObject *module)
/*[clinic end generated code]*/
{
_py_stats = NULL;
Copy link
Member

Choose a reason for hiding this comment

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

Can we use a hidden, dummy brother of_py_stats_struct here instead ofNULL? It'll allow to omitif (_py_stats) checks.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I did consider it, but the stats object is about 600k and is likely to get larger. So I think the extra NULL checks are less inefficient than wasting the memory.

Py_RETURN_NONE;
}

/*[clinic input]
sys._stats_clear

Clears stats
[clinic start generated code]*/

static PyObject *
sys__stats_clear_impl(PyObject *module)
/*[clinic end generated code: output=fb65a2525ee50604 input=0bd23b30a48f67ab]*/

static PyObject *
sys__stats_clear(PyObject *module)
/*[clinic end generated code]*/
{
_Py_StatsClear();
Py_RETURN_NONE;
}

#endif

#ifdef ANDROID_API_LEVEL
/*[clinic input]
sys.getandroidapilevel
Expand DownExpand Up@@ -1978,6 +2035,11 @@ static PyMethodDef sys_methods[] = {
SYS_GET_ASYNCGEN_HOOKS_METHODDEF
SYS_GETANDROIDAPILEVEL_METHODDEF
SYS_UNRAISABLEHOOK_METHODDEF
#ifdef Py_STATS
SYS__STATS_ON_METHODDEF
SYS__STATS_OFF_METHODDEF
SYS__STATS_CLEAR_METHODDEF
#endif
{NULL, NULL} // sentinel
};

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp