X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=HeapProfiler.h;fp=HeapProfiler.h;h=e1c03787b88925d2c20bbb095cc9e7d1e9baf0ec;hb=eb04a05de55af8957aea1353d21b5e5b98bd1006;hp=0000000000000000000000000000000000000000;hpb=56d77631b00f8622c211db6721cb087a5d29f0e2;p=SXSI%2FTextCollection.git diff --git a/HeapProfiler.h b/HeapProfiler.h new file mode 100644 index 0000000..e1c0378 --- /dev/null +++ b/HeapProfiler.h @@ -0,0 +1,56 @@ +/*************************************************************************** + * Installs handlers for malloc(), realloc() and free() * + * * + * Copyright (C) 2006 by Niko Välimäki * + * * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef _HEAPPROFILER_H_ +#define _HEAPPROFILER_H_ + +#include +#include +#include + +//#define DEBUG_HEAPPROFILER + +typedef std::map AllocatedBlocks; + +class HeapProfiler +{ +public: + static unsigned long GetMaxHeapConsumption(); + static unsigned long GetHeapConsumption(); + + // Prototypes for hooks + static void InitHooks(void); + static void *MallocHook(size_t, const void *); + static void FreeHook(void *, const void *); + static void *ReallocHook(void *, size_t, const void *); + +private: + static unsigned long consumption, maxConsumption; + // Variables to save original hooks. + static void *(*old_malloc_hook)(size_t, const void *); + static void (*old_free_hook)(void *, const void *); + static void *(*old_realloc_hook)(void *, size_t, const void *); + static AllocatedBlocks blocks; +}; + + +#endif