You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by db...@apache.org on 2005/04/25 20:35:57 UTC
cvs commit: xml-xalan/c/src/xalanc/Harness XalanDiagnosticMemoryManager.cpp XalanDiagnosticMemoryManager.hpp
dbertoni 2005/04/25 11:35:57
Modified: c/src/xalanc/Harness XalanDiagnosticMemoryManager.cpp
XalanDiagnosticMemoryManager.hpp
Log:
Added dump of statistics, including currently allocated memory blocks.
Revision Changes Path
1.2 +153 -9 xml-xalan/c/src/xalanc/Harness/XalanDiagnosticMemoryManager.cpp
Index: XalanDiagnosticMemoryManager.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/Harness/XalanDiagnosticMemoryManager.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XalanDiagnosticMemoryManager.cpp 22 Apr 2005 20:52:41 -0000 1.1
+++ XalanDiagnosticMemoryManager.cpp 25 Apr 2005 18:35:57 -0000 1.2
@@ -17,20 +17,36 @@
+#if !defined(XALAN_CLASSIC_IOSTREAMS)
+#include <iostream>
+#endif
+
+
+
+#include <ctype.h>
+
+
+
+#include "xercesc/util/PlatformUtils.hpp"
+
+
+
XALAN_CPP_NAMESPACE_BEGIN
XalanDiagnosticMemoryManager::XalanDiagnosticMemoryManager(
MemoryManager& theMemoryManager,
- bool fAssertErrors) :
+ bool fAssertErrors,
+ StreamType* theStream) :
m_memoryManager(theMemoryManager),
m_assertErrors(fAssertErrors),
m_locked(false),
m_sequence(0),
m_highWaterMark(0),
m_currentAllocated(0),
- m_allocations(theMemoryManager)
+ m_allocations(theMemoryManager),
+ m_stream(theStream)
{
}
@@ -38,11 +54,11 @@
XalanDiagnosticMemoryManager::~XalanDiagnosticMemoryManager()
{
- if (m_allocations.size() > 0)
+ if (m_allocations.size() > 0 && m_stream != 0)
{
-// std::cerr << "Detected memory leaks. "
-// << m_allocations.size()
-// << " blocks are still allocated.";
+ *m_stream << "Detected memory leaks. "
+ << m_allocations.size()
+ << " blocks are still allocated.\n";
}
}
@@ -55,6 +71,17 @@
if (m_locked == true)
{
+ if (m_stream != 0)
+ {
+ *m_stream << "Attempt to allocate "
+ << size
+ << " bytes from locked instance "
+ << this
+ << ".\n";
+
+ dumpStatistics(m_stream);
+ }
+
throw LockException();
}
else
@@ -85,6 +112,15 @@
{
if (m_locked == true)
{
+ if (m_stream != 0)
+ {
+ *m_stream << "Attempt to deallocate address "
+ << pointer
+ << " with locked instance "
+ << this
+ << ".\n";
+ }
+
throw LockException();
}
else
@@ -106,9 +142,14 @@
}
else
{
- //std::cerr << "Attempt to free unallocated pointer "
- // << pointer
- // << ".\n";
+ if (m_stream != 0)
+ {
+ *m_stream << "Attempt to free unallocated address "
+ << pointer
+ << " with instance "
+ << this
+ << ".\n";
+ }
assert(!m_assertErrors);
}
@@ -117,4 +158,107 @@
}
+
+void
+XalanDiagnosticMemoryManager::dumpStatistics(
+ StreamType* theStream,
+ size_type theBytesToDump)
+{
+ StreamType* const diagStream = theStream != 0 ? theStream : m_stream;
+
+ if (diagStream != 0)
+ {
+ *diagStream << "Total number of allocations: "
+ << m_sequence
+ << ".\n"
+ << "Total current allocations: "
+ << m_allocations.size()
+ << ".\n"
+ << "Total bytes currently allocated: "
+ << m_currentAllocated
+ << ".\n"
+ << "Peak bytes allocated: "
+ << m_highWaterMark
+ << ".\n";
+
+ for(const_iterator i = m_allocations.begin();
+ i != m_allocations.end();
+ ++i)
+ {
+ const void* const thePointer = i->first;
+ const Data& theData = i->second;
+
+ XALAN_USING_STD(dec);
+
+ *diagStream << "Block at address "
+ << thePointer
+ << " with sequence "
+ << dec
+ << theData.m_sequence
+ << " is "
+ << theData.m_size
+ << " bytes long.\n";
+
+ XALAN_USING_XERCES(XMLPlatformUtils);
+
+ const size_type theHeaderSize =
+ XMLPlatformUtils::alignPointerForNewBlockAllocation(sizeof(MemoryManager*));
+
+ const char* const theChars =
+ reinterpret_cast<const char*>(thePointer) +
+ theHeaderSize;
+
+ const unsigned char* const theUChars =
+ reinterpret_cast<const unsigned char*>(theChars);
+
+ if (theBytesToDump != 0)
+ {
+ XALAN_USING_STD(hex);
+
+ const size_type theCount =
+ theBytesToDump > theData.m_size ?
+ theData.m_size :
+ theBytesToDump;
+
+ {
+ *diagStream << "(";
+
+ for (size_t j = 0; j < theCount; ++j)
+ {
+ const char ch = isprint(theChars[j]) ?
+ theChars[j] :
+ ' ';
+
+ *diagStream << ch;
+ }
+
+ *diagStream << ") ";
+ }
+
+ if (theCount < theBytesToDump)
+ {
+ for (size_t j = theCount; j < theBytesToDump; ++j)
+ {
+ *diagStream << ' ';
+ }
+ }
+
+ {
+ *diagStream << hex;
+
+ for (size_t j = 0; j < theCount; ++j)
+ {
+ *diagStream << unsigned(theUChars[j])
+ << " ";
+ }
+ }
+
+ *diagStream << "\n";
+ }
+ }
+ }
+}
+
+
+
XALAN_CPP_NAMESPACE_END
1.2 +31 -3 xml-xalan/c/src/xalanc/Harness/XalanDiagnosticMemoryManager.hpp
Index: XalanDiagnosticMemoryManager.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/Harness/XalanDiagnosticMemoryManager.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XalanDiagnosticMemoryManager.hpp 22 Apr 2005 20:52:41 -0000 1.1
+++ XalanDiagnosticMemoryManager.hpp 25 Apr 2005 18:35:57 -0000 1.2
@@ -26,6 +26,15 @@
+#if defined(XALAN_CLASSIC_IOSTREAMS)
+#include <iostream.h>
+#else
+#include <iosfwd>
+#include <ios>
+#endif
+
+
+
#include "xercesc/framework/MemoryManager.hpp"
@@ -46,6 +55,12 @@
{
public:
+#if defined(XALAN_NO_STD_NAMESPACE)
+ typedef ostream StreamType;
+#else
+ typedef std::ostream StreamType;
+#endif
+
#if defined(XALAN_STRICT_ANSI_HEADERS)
typedef std::size_t size_type;
#else
@@ -67,7 +82,8 @@
XalanDiagnosticMemoryManager(
MemoryManager& theMemoryManager,
- bool fAssertErrors = false);
+ bool fAssertErrors = false,
+ StreamType* theStream = 0);
virtual
~XalanDiagnosticMemoryManager();
@@ -85,9 +101,9 @@
}
void
- setAssertErrors(bool fAssertErrors)
+ setAssertErrors(bool fFlag)
{
- m_assertErrors = fAssertErrors;
+ m_assertErrors = fFlag;
}
// Get the high-water mark (the highest amount
@@ -155,6 +171,16 @@
m_locked = false;
}
+ enum
+ {
+ defaultBytesToDump = 20u
+ };
+
+ void
+ dumpStatistics(
+ StreamType* theStream = 0,
+ size_type theBytesToDump = defaultBytesToDump);
+
private:
XalanDiagnosticMemoryManager(const XalanDiagnosticMemoryManager&);
@@ -175,6 +201,8 @@
size_type m_currentAllocated;
MapType m_allocations;
+
+ StreamType* m_stream;
};
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org