00001
00002 #ifndef ALLOC_TRACKER_H
00003 #define ALLOC_TRACKER_H
00004 #include "ace/pre.h"
00005
00006 #include "orbsvcs/Notify/notify_export.h"
00007
00008 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00009 # pragma once
00010 #endif
00011
00012
00013 #if defined(_MSC_VER) && defined (_DEBUG) && defined (DEBUG_MEMORY_USE)
00014 namespace CRT{
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 class CrtHeapDumper
00030 {
00031 public:
00032 CrtHeapDumper(const char * name, bool verbose = false)
00033 : name_ (name)
00034 , verbose_ (verbose)
00035 {
00036 _CrtMemCheckpoint (&before_);
00037 }
00038
00039 ~CrtHeapDumper()
00040 {
00041 dump();
00042 }
00043 void dump()
00044 {
00045 _CrtMemState after;
00046 _CrtMemCheckpoint (&after);
00047 _CrtMemState diff;
00048 _CrtMemDifference (&diff, &before_, &after);
00049
00050 ACE_DEBUG ((LM_DEBUG,
00051 ACE_TEXT ("(%P|%t) %s: New heap blocks: %d; bytes: %d\n"),
00052 name_.c_str (),
00053 static_cast<int> (diff.lCounts[_NORMAL_BLOCK]),
00054 static_cast<int> (diff.lSizes[_NORMAL_BLOCK])
00055 ));
00056 if (this->verbose_)
00057 {
00058 _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
00059 _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
00060 _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
00061 _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT );
00062 _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
00063 _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT );
00064 _CrtMemDumpAllObjectsSince (&this->before_);
00065 }
00066 }
00067
00068 private:
00069 ACE_CString name_;
00070 bool verbose_;
00071 _CrtMemState before_;
00072 };
00073 }
00074 #define ACE_WIN32_HEAP_MONITOR(name) \
00075 CRT::CrtHeapDumper heap_check___(name); \
00076 ACE_UNUSED_ARG (heap_check___)
00077 #else // _MSC_VER etc
00078 #define ACE_WIN32_HEAP_MONITOR(name)
00079 #endif // _MSC_VER etc
00080 #include "ace/post.h"
00081 #endif // ALLOC_TRACKER_H