removed tracemalloc for speedup

can be enabled via MODE=dbg if necessary.
This commit is contained in:
ahgamut 2021-09-03 20:32:48 +05:30
parent 50937be752
commit 712ead6ee8
9 changed files with 49 additions and 18 deletions

View file

@ -319,7 +319,6 @@ void _PyErr_BadInternalCall(const char *filename, int lineno);
/* Mask the old API with a call to the new API for code compiled under
Python 2.0: */
#define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__)
/* Function to create a new exception */
PyObject * PyErr_NewException(
const char *name, PyObject *base, PyObject *dict);

View file

@ -29,6 +29,7 @@ int _PyMem_SetupAllocators(const char *opt);
int _PyMem_PymallocEnabled(void);
#endif
#ifdef USE_TRACEMALLOC
/* Identifier of an address space (domain) in tracemalloc */
typedef unsigned int _PyTraceMalloc_domain_t;
@ -63,6 +64,11 @@ int _PyTraceMalloc_Untrack(
PyObject* _PyTraceMalloc_GetTraceback(
_PyTraceMalloc_domain_t domain,
uintptr_t ptr);
#else
#define PyTraceMalloc_Track(domain, ptr, size) (-2)
#define PyTraceMalloc_Untrack(domain, ptr) (-2)
#define _PyTraceMalloc_GetTraceback(domain, ptr) (&_Py_NoneStruct)
#endif
int _PyMem_IsFreed(void *ptr, size_t size);
#endif /* !defined(Py_LIMITED_API) */

View file

@ -593,7 +593,7 @@ build_time_vars = {'ABIFLAGS': 'm',
'MODNAMES': '_decimal posix errno pwd _sre '
'_codecs _functools _operator _collections itertools atexit '
'_signal _stat time _locale _io zipimport faulthandler '
'_tracemalloc _symtable array cmath math _struct _weakref '
'_symtable array cmath math _struct _weakref '
'_testcapi _random _elementtree _pickle _datetime _bisect _heapq '
'unicodedata fcntl grp select mmap _csv _socket resource '
'_posixsubprocess _md5 _sha1 _sha256 _sha512 _sha3 syslog '
@ -614,7 +614,7 @@ build_time_vars = {'ABIFLAGS': 'm',
'Modules/_iomodule.o Modules/iobase.o Modules/fileio.o '
'Modules/bytesio.o Modules/bufferedio.o Modules/textio.o '
'Modules/stringio.o Modules/zipimport.o Modules/faulthandler.o '
'Modules/_tracemalloc.o Modules/hashtable.o '
'Modules/hashtable.o '
'Modules/symtablemodule.o Modules/arraymodule.o '
'Modules/cmathmodule.o Modules/mathmodule.o Modules/_math.o '
'Modules/_struct.o Modules/_weakref.o Modules/_testcapimodule.o '

View file

@ -263,8 +263,8 @@ def _args_from_interpreter_flags():
# -X options
xoptions = getattr(sys, '_xoptions', {})
for opt in ('faulthandler', 'tracemalloc',
'showalloccount', 'showrefcount', 'utf8'):
for opt in ('faulthandler', 'showalloccount',
'showrefcount', 'utf8'):
if opt in xoptions:
value = xoptions[opt]
if value is True:

View file

@ -4112,7 +4112,7 @@ pyobject_malloc_without_gil(PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
#ifdef USE_TRACEMALLOC
static PyObject *
tracemalloc_track(PyObject *self, PyObject *args)
{
@ -4184,7 +4184,7 @@ tracemalloc_get_traceback(PyObject *self, PyObject *args)
return _PyTraceMalloc_GetTraceback(domain, (uintptr_t)ptr);
}
#endif
static PyObject *
dict_get_version(PyObject *self, PyObject *args)
{
@ -4539,9 +4539,11 @@ static PyMethodDef TestMethods[] = {
{"pymem_api_misuse", pymem_api_misuse, METH_NOARGS},
{"pymem_malloc_without_gil", pymem_malloc_without_gil, METH_NOARGS},
{"pyobject_malloc_without_gil", pyobject_malloc_without_gil, METH_NOARGS},
#ifdef USE_TRACEMALLOC
{"tracemalloc_track", tracemalloc_track, METH_VARARGS},
{"tracemalloc_untrack", tracemalloc_untrack, METH_VARARGS},
{"tracemalloc_get_traceback", tracemalloc_get_traceback, METH_VARARGS},
#endif
{"dict_get_version", dict_get_version, METH_VARARGS},
{"pyobject_fastcall", test_pyobject_fastcall, METH_VARARGS},
{"pyobject_fastcalldict", test_pyobject_fastcalldict, METH_VARARGS},

View file

@ -47,7 +47,9 @@ PyObject* PyInit__locale(void);
PyObject* PyInit__io(void);
PyObject* PyInit_zipimport(void);
PyObject* PyInit_faulthandler(void);
#ifdef USE_TRACEMALLOC
PyObject* PyInit__tracemalloc(void);
#endif
PyObject* PyInit__symtable(void);
PyObject* PyInit_array(void);
PyObject* PyInit_cmath(void);
@ -123,7 +125,9 @@ struct _inittab _PyImport_Inittab[] = {
{"_locale", PyInit__locale},
{"_io", PyInit__io},
{"faulthandler", PyInit_faulthandler},
#ifdef USE_TRACEMALLOC
{"_tracemalloc", PyInit__tracemalloc},
#endif
{"_symtable", PyInit__symtable},
{"array", PyInit_array},
{"cmath", PyInit_cmath},

View file

@ -16,9 +16,10 @@
#include "third_party/python/Include/pymem.h"
/* clang-format off */
#ifdef USE_TRACEMALLOC
/* Defined in tracemalloc.c */
extern void _PyMem_DumpTraceback(int fd, const void *ptr);
#endif
/* Python's malloc wrappers (see pymem.h) */
@ -2196,7 +2197,9 @@ _PyObject_DebugDumpAddress(const void *p)
fputc('\n', stderr);
fflush(stderr);
#ifdef USE_TRACEMALLOC
_PyMem_DumpTraceback(fileno(stderr), p);
#endif
}

View file

@ -75,9 +75,10 @@ extern void PyLong_Fini(void);
extern int _PyFaulthandler_Init(void);
extern void _PyFaulthandler_Fini(void);
extern void _PyHash_Fini(void);
#ifdef USE_TRACEMALLOC
extern int _PyTraceMalloc_Init(void);
extern int _PyTraceMalloc_Fini(void);
#endif
#ifdef WITH_THREAD
extern void _PyGILState_Init(PyInterpreterState *, PyThreadState *);
extern void _PyGILState_Fini(void);
@ -462,8 +463,10 @@ _Py_InitializeEx_Private(int install_sigs, int install_importlib)
if (install_sigs)
initsigs(); /* Signal handling stuff, including initintr() */
#ifdef USE_TRACEMALLOC
if (_PyTraceMalloc_Init() < 0)
Py_FatalError("Py_Initialize: can't initialize tracemalloc");
#endif
initmain(interp); /* Module __main__ */
if (initstdio() < 0) {
@ -652,10 +655,11 @@ Py_FinalizeEx(void)
_PyGC_CollectIfEnabled();
#endif
#ifdef USE_TRACEMALLOC
/* Disable tracemalloc after all Python objects have been destroyed,
so it is possible to use tracemalloc in objects destructor. */
_PyTraceMalloc_Fini();
#endif
/* Destroy the database used by _PyImport_{Fixup,Find}Extension */
_PyImport_Fini();

View file

@ -49,6 +49,13 @@ THIRD_PARTY_PYTHON_STDLIB_DIRS_OBJS = $(THIRD_PARTY_PYTHON_STDLIB_DIRS:%=o/$(MOD
THIRD_PARTY_PYTHON_STDLIB_DATA_OBJS = $(THIRD_PARTY_PYTHON_STDLIB_DATA:%=o/$(MODE)/%.zip.o)
THIRD_PARTY_PYTHON_STDLIB_PYCS = $(THIRD_PARTY_PYTHON_STDLIB_PYS:%=o/$(MODE)/%c)
THIRD_PARTY_PYTHON_FLAGS = \
-DNDEBUG \
-DPy_BUILD_CORE \
-DPLATFORM='"cosmo"' \
-DMULTIARCH='"x86_64-cosmo"'
THIRD_PARTY_PYTHON_HDRS = \
third_party/python/Include/yoink.h \
third_party/python/Include/object.h \
@ -307,7 +314,6 @@ THIRD_PARTY_PYTHON_INCS = \
third_party/python/Modules/unicodedata_db.inc
THIRD_PARTY_PYTHON_STAGE1_A_SRCS = \
third_party/python/Modules/_tracemalloc.c \
third_party/python/Modules/faulthandler.c \
third_party/python/Objects/abstract.c \
third_party/python/Modules/fspath.c \
@ -463,7 +469,6 @@ THIRD_PARTY_PYTHON_STAGE2_A_SRCS = \
third_party/python/Modules/_stat.c \
third_party/python/Modules/_struct.c \
third_party/python/Modules/_testcapimodule.c \
third_party/python/Modules/_tracemalloc.c \
third_party/python/Modules/_weakref.c \
third_party/python/Modules/arraymodule.c \
third_party/python/Modules/atexitmodule.c \
@ -1465,7 +1470,6 @@ THIRD_PARTY_PYTHON_STDLIB_PYS = \
third_party/python/Lib/tokenize.py \
third_party/python/Lib/trace.py \
third_party/python/Lib/traceback.py \
third_party/python/Lib/tracemalloc.py \
third_party/python/Lib/tty.py \
third_party/python/Lib/types.py \
third_party/python/Lib/typing.py \
@ -1816,7 +1820,6 @@ THIRD_PARTY_PYTHON_STDLIB_PYS = \
third_party/python/Lib/test/test_cmd_line.py \
third_party/python/Lib/test/test_bool.py \
third_party/python/Lib/test/test_urllib2_localnet.py \
third_party/python/Lib/test/test_tracemalloc.py \
third_party/python/Lib/test/mapping_tests.py \
third_party/python/Lib/test/test_tempfile.py \
third_party/python/Lib/test/test_socketserver.py \
@ -2161,6 +2164,19 @@ THIRD_PARTY_PYTHON_STDLIB_PYS = \
third_party/python/Lib/test/test_nntplib.py \
third_party/python/Lib/test/test_uu.py
ifeq ($(MODE), dbg)
THIRD_PARTY_PYTHON_FLAGS += \
-DUSE_TRACEMALLOC
THIRD_PARTY_PYTHON_STAGE1_A_SRCS += \
third_party/python/Modules/_tracemalloc.c
THIRD_PARTY_PYTHON_STAGE2_A_SRCS += \
third_party/python/Modules/_tracemalloc.c
THIRD_PARTY_PYTHON_STDLIB_PYS += \
third_party/python/Lib/tracemalloc.py \
third_party/python/Lib/test/test_tracemalloc.py
endif
THIRD_PARTY_PYTHON_STAGE1_A_DIRECTDEPS = \
LIBC_CALLS \
LIBC_FMT \
@ -2308,10 +2324,7 @@ o/$(MODE)/third_party/python/Python/sysmodule.o: \
$(THIRD_PARTY_PYTHON_STAGE1_A_OBJS) \
$(THIRD_PARTY_PYTHON_STAGE2_A_OBJS): \
OVERRIDE_CPPFLAGS += \
-DNDEBUG \
-DPy_BUILD_CORE \
-DPLATFORM='"cosmo"' \
-DMULTIARCH='"x86_64-cosmo"'
$(THIRD_PARTY_PYTHON_FLAGS)
o/$(MODE)/third_party/python/Modules/getbuildinfo.o: \
OVERRIDE_CFLAGS += \