Commit b332f703 authored by Travis Hance's avatar Travis Hance

Add stat counters for allocations to DEFAULT_CLASS_VAR_SIMPLE

parent 191218f2
...@@ -495,8 +495,27 @@ extern "C" PyObject* PystonType_GenericAlloc(BoxedClass* cls, Py_ssize_t nitems) ...@@ -495,8 +495,27 @@ extern "C" PyObject* PystonType_GenericAlloc(BoxedClass* cls, Py_ssize_t nitems)
std::string per_name_allocsize_name = "allocsize." + std::string(cls->tp_name); \ std::string per_name_allocsize_name = "allocsize." + std::string(cls->tp_name); \
Stats::log(Stats::getStatId(per_name_alloc_name)); \ Stats::log(Stats::getStatId(per_name_alloc_name)); \
Stats::log(Stats::getStatId(per_name_allocsize_name), size); Stats::log(Stats::getStatId(per_name_allocsize_name), size);
#define ALLOC_STATS_VAR(cls) \
if (cls->tp_name) { \
std::string per_name_alloc_name = "alloc." + std::string(cls->tp_name); \
std::string per_name_alloc_name0 = "alloc." + std::string(cls->tp_name) + "(0)"; \
std::string per_name_allocsize_name = "allocsize." + std::string(cls->tp_name); \
std::string per_name_allocsize_name0 = "allocsize." + std::string(cls->tp_name) + "(0)"; \
static StatCounter alloc_name(per_name_alloc_name); \
static StatCounter alloc_name0(per_name_alloc_name0); \
static StatCounter allocsize_name(per_name_allocsize_name); \
static StatCounter allocsize_name0(per_name_allocsize_name0); \
if (nitems == 0) { \
alloc_name0.log(); \
allocsize_name0.log(_PyObject_VAR_SIZE(cls, nitems)); \
} else { \
alloc_name.log(); \
allocsize_name.log(_PyObject_VAR_SIZE(cls, nitems)); \
} \
}
#else #else
#define ALLOC_STATS(cls) #define ALLOC_STATS(cls)
#define ALLOC_STATS_VAR(cls)
#endif #endif
...@@ -555,10 +574,12 @@ extern "C" PyObject* PystonType_GenericAlloc(BoxedClass* cls, Py_ssize_t nitems) ...@@ -555,10 +574,12 @@ extern "C" PyObject* PystonType_GenericAlloc(BoxedClass* cls, Py_ssize_t nitems)
} \ } \
\ \
void* operator new(size_t size, BoxedClass * cls, size_t nitems) __attribute__((visibility("default"))) { \ void* operator new(size_t size, BoxedClass * cls, size_t nitems) __attribute__((visibility("default"))) { \
ALLOC_STATS_VAR(default_cls) \
assert(cls->tp_itemsize == itemsize); \ assert(cls->tp_itemsize == itemsize); \
return BoxVar::operator new(size, cls, nitems); \ return BoxVar::operator new(size, cls, nitems); \
} \ } \
void* operator new(size_t size, size_t nitems) __attribute__((visibility("default"))) { \ void* operator new(size_t size, size_t nitems) __attribute__((visibility("default"))) { \
ALLOC_STATS_VAR(default_cls) \
assert(default_cls->tp_alloc == PystonType_GenericAlloc); \ assert(default_cls->tp_alloc == PystonType_GenericAlloc); \
assert(default_cls->tp_itemsize == itemsize); \ assert(default_cls->tp_itemsize == itemsize); \
assert(default_cls->tp_basicsize == size); \ assert(default_cls->tp_basicsize == size); \
......
...@@ -418,36 +418,13 @@ public: ...@@ -418,36 +418,13 @@ public:
// DEFAULT_CLASS_VAR_SIMPLE doesn't work because of the +1 for the null byte // DEFAULT_CLASS_VAR_SIMPLE doesn't work because of the +1 for the null byte
void* operator new(size_t size, BoxedClass* cls, size_t nitems) __attribute__((visibility("default"))) { void* operator new(size_t size, BoxedClass* cls, size_t nitems) __attribute__((visibility("default"))) {
#if STAT_ALLOCATIONS ALLOC_STATS_VAR(str_cls)
static StatCounter alloc_str("alloc.str");
static StatCounter alloc_str1("alloc.str(1)");
static StatCounter allocsize_str("allocsize.str");
if (ssize == 1)
alloc_str1.log();
else
alloc_str.log();
allocsize_str.log(str_cls->tp_basicsize + ssize + 1);
#endif
assert(cls->tp_itemsize == sizeof(char)); assert(cls->tp_itemsize == sizeof(char));
return BoxVar::operator new(size, cls, nitems); return BoxVar::operator new(size, cls, nitems);
} }
void* operator new(size_t size, size_t nitems) __attribute__((visibility("default"))) { void* operator new(size_t size, size_t nitems) __attribute__((visibility("default"))) {
#if STAT_ALLOCATIONS ALLOC_STATS_VAR(str_cls)
static StatCounter alloc_str("alloc.str");
static StatCounter alloc_str1("alloc.str(1)");
static StatCounter allocsize_str("allocsize.str");
if (ssize == 1)
alloc_str1.log();
else
alloc_str.log();
allocsize_str.log(cls->tp_basicsize + ssize + 1);
#endif
assert(str_cls->tp_alloc == PystonType_GenericAlloc); assert(str_cls->tp_alloc == PystonType_GenericAlloc);
assert(str_cls->tp_itemsize == 1); assert(str_cls->tp_itemsize == 1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment