From 73ae98c9f05bb53cc5db08e72d2b980a4bbc4dd6 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 9 Feb 2001 20:02:32 +0000 Subject: [PATCH] Implementation of memory monitoring. git-svn-id: https://svn.dealii.org/trunk@3898 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/object_monitor.h | 48 ++++++++++++ .../include/base/object_monitor_activator.h | 33 ++++++++ deal.II/base/source/object_monitor.cc | 76 +++++++++++++++++++ .../base/source/object_monitor_activator.cc | 31 ++++++++ 4 files changed, 188 insertions(+) create mode 100644 deal.II/base/include/base/object_monitor.h create mode 100644 deal.II/base/include/base/object_monitor_activator.h create mode 100644 deal.II/base/source/object_monitor.cc create mode 100644 deal.II/base/source/object_monitor_activator.cc diff --git a/deal.II/base/include/base/object_monitor.h b/deal.II/base/include/base/object_monitor.h new file mode 100644 index 0000000000..d64d9bc4ec --- /dev/null +++ b/deal.II/base/include/base/object_monitor.h @@ -0,0 +1,48 @@ +//---------------------------- object_monitor.h --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 1998, 1999, 2000, 2001 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------- object_monitor.h --------------------------- +#ifndef __deal2__object_monitor_h +#define __deal2__object_monitor_h + + + +#include + +class Subscriptor; + + + +class ObjectMonitor +{ + public: + ObjectMonitor (); + ~ObjectMonitor (); + + void activate (); + void deactivate (); + + void register_object (const Subscriptor *p); + void deregister_object (const Subscriptor *p); + private: + std::set registered_objects; + bool activated; +}; + + +extern ObjectMonitor *object_monitor; + + + +#endif + + + diff --git a/deal.II/base/include/base/object_monitor_activator.h b/deal.II/base/include/base/object_monitor_activator.h new file mode 100644 index 0000000000..ea05c02ad9 --- /dev/null +++ b/deal.II/base/include/base/object_monitor_activator.h @@ -0,0 +1,33 @@ +//---------------------------- object_monitor_activator.h --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 1998, 1999, 2000, 2001 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------- object_monitor_activator.h --------------------------- +#ifndef __deal2__object_monitor_activator_h +#define __deal2__object_monitor_activator_h + + + + +class ObjectMonitorActivator +{ + public: + ObjectMonitorActivator (); + ~ObjectMonitorActivator (); +}; + + + + + +#endif + + + diff --git a/deal.II/base/source/object_monitor.cc b/deal.II/base/source/object_monitor.cc new file mode 100644 index 0000000000..832211469c --- /dev/null +++ b/deal.II/base/source/object_monitor.cc @@ -0,0 +1,76 @@ +//---------------------------- object_monitor.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 1998, 1999, 2000, 2001 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------- object_monitor.cc --------------------------- + + +#include +#include + + +ObjectMonitor *object_monitor; + + + +ObjectMonitor::ObjectMonitor (): + activated (false) +{}; + + +ObjectMonitor::~ObjectMonitor () +{}; + + + +void ObjectMonitor::activate () +{ + activated=true; +}; + + + +void ObjectMonitor::deactivate () +{ + activated = false; + if (registered_objects.size() > 0) + { + for (std::set::const_iterator i=registered_objects.begin(); + i!=registered_objects.end(); ++i) + std::cout << "Object still exists of type " + << typeid(**i).name() + << std::endl; + abort (); + }; +}; + + +void ObjectMonitor::register_object (const Subscriptor *p) +{ + if (activated) + { + cout << typeid(*p).name() << endl; + if (registered_objects.find(p) != registered_objects.end()) + abort(); + registered_objects.insert (p); + }; +}; + + +void +ObjectMonitor::deregister_object (const Subscriptor *p) +{ + if (activated) + { + if (registered_objects.find(p) == registered_objects.end()) + abort(); + registered_objects.erase (registered_objects.find(p)); + }; +}; diff --git a/deal.II/base/source/object_monitor_activator.cc b/deal.II/base/source/object_monitor_activator.cc new file mode 100644 index 0000000000..1d05167fb9 --- /dev/null +++ b/deal.II/base/source/object_monitor_activator.cc @@ -0,0 +1,31 @@ +//---------------------------- object_monitor_activator.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 1998, 1999, 2000, 2001 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------- object_monitor_activator.cc --------------------------- + + +#include +#include +#include + + +ObjectMonitorActivator::ObjectMonitorActivator () +{ + if (true) + Subscriptor b; + object_monitor->activate(); +}; + + +ObjectMonitorActivator::~ObjectMonitorActivator () +{ + object_monitor->deactivate(); +}; -- 2.39.5