From a5e3371b8030920fd9108976fac218660d59bb40 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 12 Sep 2015 00:29:02 +0200 Subject: Event Pool usage debugging, see also 6ade16b38 --- libs/pbd/pbd/pool.h | 3 +++ libs/pbd/pool.cc | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/libs/pbd/pbd/pool.h b/libs/pbd/pbd/pool.h index aff3f7ea21..37ca1adf00 100644 --- a/libs/pbd/pbd/pool.h +++ b/libs/pbd/pbd/pool.h @@ -51,6 +51,9 @@ class LIBPBD_API Pool private: void *block; ///< data storage area +#ifndef NDEBUG + unsigned long max_usage; +#endif }; class LIBPBD_API SingleAllocMultiReleasePool : public Pool diff --git a/libs/pbd/pool.cc b/libs/pbd/pool.cc index ccdb85b6c6..1fc0949eba 100644 --- a/libs/pbd/pool.cc +++ b/libs/pbd/pool.cc @@ -35,6 +35,9 @@ using namespace PBD; Pool::Pool (string n, unsigned long item_size, unsigned long nitems) : free_list (nitems) , _name (n) +#ifndef NDEBUG + , max_usage (0) +#endif { _name = n; @@ -57,6 +60,10 @@ Pool::Pool (string n, unsigned long item_size, unsigned long nitems) Pool::~Pool () { +#ifndef NDEBUG + // TODO: after collecting some stats, use DEBUG::PoolStats here + cerr << "Pool: '" << _name << "' max: " << max_usage << " / " << total() << endmsg; +#endif free (block); } @@ -68,6 +75,12 @@ Pool::alloc () { void *ptr; +#ifndef NDEBUG + if (used () > max_usage) { + max_usage = used () + 1; + } +#endif + if (free_list.read (&ptr, 1) < 1) { fatal << "CRITICAL: " << _name << " POOL OUT OF MEMORY - RECOMPILE WITH LARGER SIZE!!" << endmsg; abort(); /*NOTREACHED*/ -- cgit v1.2.3