Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
cpython/Modules/_tracemalloc.c at main · python/cpython · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Uh oh!
There was an error while loading.
Please reload this page
.
python
/
cpython
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
35.4k
Star
77.2k
Code
Issues
5k+
Pull requests
2.6k
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
main
Breadcrumbs
cpython
/
Modules
/
_tracemalloc.c
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
236 lines (174 loc) · 5.65 KB
main
Breadcrumbs
cpython
/
Modules
/
_tracemalloc.c
Copy path
Top
File metadata and controls
Code
Blame
236 lines (174 loc) · 5.65 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#include
"Python.h"
#include
"pycore_tracemalloc.h"
// _PyTraceMalloc_IsTracing
#include
"clinic/_tracemalloc.c.h"
/*[clinic input]
module _tracemalloc
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=708a98302fc46e5f]*/
/*[clinic input]
@permit_long_summary
_tracemalloc.is_tracing
Return True if the tracemalloc module is tracing Python memory allocations.
[clinic start generated code]*/
static
PyObject
*
_tracemalloc_is_tracing_impl
(
PyObject
*
module
)
/*[clinic end generated code: output=2d763b42601cd3ef input=cac4fc9096babeac]*/
{
return
PyBool_FromLong
(
_PyTraceMalloc_IsTracing
());
}
/*[clinic input]
_tracemalloc.clear_traces
Clear traces of memory blocks allocated by Python.
[clinic start generated code]*/
static
PyObject
*
_tracemalloc_clear_traces_impl
(
PyObject
*
module
)
/*[clinic end generated code: output=a86080ee41b84197 input=0dab5b6c785183a5]*/
{
_PyTraceMalloc_ClearTraces
();
Py_RETURN_NONE
;
}
/*[clinic input]
_tracemalloc._get_traces
Get traces of all memory blocks allocated by Python.
Return a list of (size: int, traceback: tuple) tuples.
traceback is a tuple of (filename: str, lineno: int) tuples.
Return an empty list if the tracemalloc module is disabled.
[clinic start generated code]*/
static
PyObject
*
_tracemalloc__get_traces_impl
(
PyObject
*
module
)
/*[clinic end generated code: output=e9929876ced4b5cc input=6c7d2230b24255aa]*/
{
return
_PyTraceMalloc_GetTraces
();
}
/*[clinic input]
_tracemalloc._get_object_traceback
obj: object
/
Get the traceback where the Python object obj was allocated.
Return a tuple of (filename: str, lineno: int) tuples.
Return None if the tracemalloc module is disabled or did not
trace the allocation of the object.
[clinic start generated code]*/
static
PyObject
*
_tracemalloc__get_object_traceback
(
PyObject
*
module
,
PyObject
*
obj
)
/*[clinic end generated code: output=41ee0553a658b0aa input=29495f1b21c53212]*/
{
return
_PyTraceMalloc_GetObjectTraceback
(
obj
);
}
/*[clinic input]
_tracemalloc.start
nframe: int = 1
/
Start tracing Python memory allocations.
Also set the maximum number of frames stored in the traceback of a
trace to nframe.
[clinic start generated code]*/
static
PyObject
*
_tracemalloc_start_impl
(
PyObject
*
module
,
int
nframe
)
/*[clinic end generated code: output=caae05c23c159d3c input=40d849b5b29d1933]*/
{
if
(
_PyTraceMalloc_Start
(
nframe
)
<
0
) {
return
NULL
;
}
Py_RETURN_NONE
;
}
/*[clinic input]
_tracemalloc.stop
Stop tracing Python memory allocations.
Also clear traces of memory blocks allocated by Python.
[clinic start generated code]*/
static
PyObject
*
_tracemalloc_stop_impl
(
PyObject
*
module
)
/*[clinic end generated code: output=c3c42ae03e3955cd input=7478f075e51dae18]*/
{
_PyTraceMalloc_Stop
();
Py_RETURN_NONE
;
}
/*[clinic input]
_tracemalloc.get_traceback_limit
Get the maximum number of frames stored in the traceback of a trace.
By default, a trace of an allocated memory block only stores
the most recent frame: the limit is 1.
[clinic start generated code]*/
static
PyObject
*
_tracemalloc_get_traceback_limit_impl
(
PyObject
*
module
)
/*[clinic end generated code: output=d556d9306ba95567 input=da3cd977fc68ae3b]*/
{
return
PyLong_FromLong
(
_PyTraceMalloc_GetTracebackLimit
());
}
/*[clinic input]
_tracemalloc.get_tracemalloc_memory
Get the memory usage in bytes of the tracemalloc module.
This memory is used internally to trace memory allocations.
[clinic start generated code]*/
static
PyObject
*
_tracemalloc_get_tracemalloc_memory_impl
(
PyObject
*
module
)
/*[clinic end generated code: output=e3f14e280a55f5aa input=5d919c0f4d5132ad]*/
{
return
PyLong_FromSize_t
(
_PyTraceMalloc_GetMemory
());
}
/*[clinic input]
@permit_long_summary
_tracemalloc.get_traced_memory
Get the current size and peak size of memory blocks traced by tracemalloc.
Returns a tuple: (current: int, peak: int).
[clinic start generated code]*/
static
PyObject
*
_tracemalloc_get_traced_memory_impl
(
PyObject
*
module
)
/*[clinic end generated code: output=5b167189adb9e782 input=b06e7a1a4914fc21]*/
{
return
_PyTraceMalloc_GetTracedMemory
();
}
/*[clinic input]
@permit_long_summary
_tracemalloc.reset_peak
Set the peak size of memory blocks traced by tracemalloc to the current size.
Do nothing if the tracemalloc module is not tracing memory allocations.
[clinic start generated code]*/
static
PyObject
*
_tracemalloc_reset_peak_impl
(
PyObject
*
module
)
/*[clinic end generated code: output=140c2870f691dbb2 input=4103319210f46286]*/
{
_PyTraceMalloc_ResetPeak
();
Py_RETURN_NONE
;
}
static
PyMethodDef
module_methods
[]
=
{
_TRACEMALLOC_IS_TRACING_METHODDEF
_TRACEMALLOC_CLEAR_TRACES_METHODDEF
_TRACEMALLOC__GET_TRACES_METHODDEF
_TRACEMALLOC__GET_OBJECT_TRACEBACK_METHODDEF
_TRACEMALLOC_START_METHODDEF
_TRACEMALLOC_STOP_METHODDEF
_TRACEMALLOC_GET_TRACEBACK_LIMIT_METHODDEF
_TRACEMALLOC_GET_TRACEMALLOC_MEMORY_METHODDEF
_TRACEMALLOC_GET_TRACED_MEMORY_METHODDEF
_TRACEMALLOC_RESET_PEAK_METHODDEF
/* sentinel */
{
NULL
,
NULL
}
};
PyDoc_STRVAR
(
module_doc
,
"Debug module to trace memory blocks allocated by Python."
);
static
struct
PyModuleDef
module_def
=
{
PyModuleDef_HEAD_INIT
,
"_tracemalloc"
,
module_doc
,
0
,
/* non-negative size to be able to unload the module */
module_methods
,
NULL
,
};
PyMODINIT_FUNC
PyInit__tracemalloc
(
void
)
{
PyABIInfo_VAR
(
abi_info
);
if
(
PyABIInfo_Check
(
&
abi_info
,
"_tracemalloc"
)
<
0
) {
return
NULL
;
}
PyObject
*
mod
=
PyModule_Create
(
&
module_def
);
if
(
mod
==
NULL
) {
return
NULL
;
}
#ifdef
Py_GIL_DISABLED
PyUnstable_Module_SetGIL
(
mod
,
Py_MOD_GIL_NOT_USED
);
#endif
return
mod
;
}
You can’t perform that action at this time.