1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0023818: Extend OSD_MemInfo to report C heap statistics

A new counter MemHeapUsage was added to OSD_MemInfo class to examine program heap size
DRAW command meminfo got new option -h (--heap ) to use new counter data
The following testcases were changed to use new option -h of DRAW command meminfo
myCounters[MemHeapUsage] now will always be refilled every time the OSD_MemInfo::Update() function is called.
Fixed testcases to use meminfo -h instead of meminfo -w to detect memory leaks more properly.
This commit is contained in:
omy
2013-04-12 13:21:13 +04:00
parent 38da19bd28
commit 67a1064eb8
21 changed files with 81 additions and 48 deletions

View File

@@ -21,6 +21,7 @@
#include <windows.h>
#include <winbase.h>
#include <process.h>
#include <malloc.h>
#include <Psapi.h>
#ifdef _MSC_VER
#pragma comment(lib, "Psapi.lib")
@@ -28,8 +29,10 @@
#elif (defined(__APPLE__))
#include <mach/task.h>
#include <mach/mach.h>
#include <malloc/malloc.h>
#else
#include <unistd.h>
#include <malloc.h>
#endif
#include <string>
@@ -83,6 +86,17 @@ void OSD_MemInfo::Update()
myCounters[MemSwapUsagePeak] = aProcMemCnts.PeakPagefileUsage;
}
_HEAPINFO hinfo;
int heapstatus;
hinfo._pentry = NULL;
myCounters[MemHeapUsage] = 0;
while((heapstatus = _heapwalk(&hinfo)) == _HEAPOK)
{
if(hinfo._useflag == _USEDENTRY)
myCounters[MemHeapUsage] += hinfo._size;
}
#elif (defined(__linux__) || defined(__linux))
// use procfs on Linux
char aBuff[4096];
@@ -129,6 +143,10 @@ void OSD_MemInfo::Update()
}
}
aFile.close();
struct mallinfo aMI = mallinfo();
myCounters[MemHeapUsage] = aMI.uordblks;
#elif (defined(__APPLE__))
struct task_basic_info aTaskInfo;
mach_msg_type_number_t aTaskInfoCount = TASK_BASIC_INFO_COUNT;
@@ -138,6 +156,12 @@ void OSD_MemInfo::Update()
// On Mac OS X, these values in bytes, not pages!
myCounters[MemVirtual] = aTaskInfo.virtual_size;
myCounters[MemWorkingSet] = aTaskInfo.resident_size;
//Getting malloc statistics
malloc_statistics_t aStats;
malloc_zone_statistics (NULL, &aStats);
myCounters[MemHeapUsage] = aStats.size_in_use;
}
#endif
}
@@ -175,6 +199,10 @@ TCollection_AsciiString OSD_MemInfo::ToString() const
{
anInfo += TCollection_AsciiString(" Virtual memory: ") + Standard_Integer (ValueMiB (MemVirtual)) + " MiB\n";
}
if (myCounters[MemHeapUsage] != Standard_Size(-1))
{
anInfo += TCollection_AsciiString(" Heap memory: ") + Standard_Integer (ValueMiB (MemHeapUsage)) + " MiB\n";
}
return anInfo;
}

View File

@@ -64,6 +64,7 @@ public:
MemWorkingSetPeak, //!< Peak working set size
MemSwapUsage, //!< Space allocated for the pagefile
MemSwapUsagePeak, //!< Peak space allocated for the pagefile
MemHeapUsage, //!< Total space allocated from the heap
MemCounter_NB //!< Indicates total counters number
};