mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-04 18:06:22 +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:
parent
38da19bd28
commit
67a1064eb8
@ -664,6 +664,10 @@ static int dmeminfo (Draw_Interpretor& theDI,
|
||||
{
|
||||
theDI << Standard_Real (aMemInfo.Value (OSD_MemInfo::MemVirtual)) << " ";
|
||||
}
|
||||
else if (anArg == "heap" || anArg == "h")
|
||||
{
|
||||
theDI << Standard_Real (aMemInfo.Value (OSD_MemInfo::MemHeapUsage)) << " ";
|
||||
}
|
||||
else if (anArg == "wset" || anArg == "w")
|
||||
{
|
||||
theDI << Standard_Real (aMemInfo.Value (OSD_MemInfo::MemWorkingSet)) << " ";
|
||||
@ -719,7 +723,7 @@ void Draw::BasicCommands(Draw_Interpretor& theCommands)
|
||||
"debug memory allocation/deallocation, w/o args for help",
|
||||
__FILE__, mallochook, g);
|
||||
theCommands.Add ("meminfo",
|
||||
"meminfo [virt|v] [wset|w] [wsetpeak] [swap] [swappeak] [private]"
|
||||
"meminfo [virt|v] [heap|h] [wset|w] [wsetpeak] [swap] [swappeak] [private]"
|
||||
" : memory counters for this process",
|
||||
__FILE__, dmeminfo, g);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
};
|
||||
|
||||
|
@ -234,7 +234,7 @@ proc checktrend {listval delta tolerance message} {
|
||||
# check if deviation is definitely too big
|
||||
if { abs ($mean - $delta) > 2. * $sigma } {
|
||||
puts "Checking trend failed: mean delta per step = $mean, sigma = $sigma, expected delta = $delta"
|
||||
puts "Error : $message"
|
||||
error "$message"
|
||||
}
|
||||
|
||||
# check if deviation is clearly within a range
|
||||
|
@ -44,7 +44,7 @@ for {set i 1} {$i <= ${i_max}} {incr i} {
|
||||
Undo D
|
||||
|
||||
# check memory usage (with tolerance equal to half page size)
|
||||
lappend listmem [expr [meminfo w] / 1024]
|
||||
lappend listmem [meminfo h]
|
||||
if { [checktrend $listmem 0 512 "Memory leak detected"] } {
|
||||
puts "No memory leak, $i iterations"
|
||||
break
|
||||
|
@ -19,7 +19,7 @@ for {set i 1} {${i} <= ${i_max}} {incr i} {
|
||||
AbortCommand D
|
||||
|
||||
# check memory usage (with tolerance equal to half page size)
|
||||
lappend listmem [expr [meminfo w] / 1024]
|
||||
lappend listmem [meminfo h]
|
||||
if { [checktrend $listmem 0 1 "Memory leak detected"] } {
|
||||
puts "No memory leak, $i iterations"
|
||||
break
|
||||
|
@ -27,7 +27,7 @@ for {set i 1} {$i < 10} {incr i} {
|
||||
vertex a 0 0 0
|
||||
|
||||
# check memory usage (with tolerance equal to half page size)
|
||||
lappend listmem [expr [meminfo w] / 1024]
|
||||
lappend listmem [meminfo h]
|
||||
if { [checktrend $listmem 0 256 "Memory leak detected"] } {
|
||||
puts "No memory leak, $i iterations"
|
||||
break
|
||||
|
@ -16,7 +16,7 @@ set listmem {}
|
||||
set i_max 1000000
|
||||
OCC22611 "0.1214343" ${i_max}
|
||||
|
||||
lappend listmem [expr [meminfo w] / 1024]
|
||||
lappend listmem [meminfo h]
|
||||
if { [checktrend $listmem 0 1 "Memory leak detected"] } {
|
||||
puts "No memory leak"
|
||||
break
|
||||
|
@ -21,9 +21,9 @@ set listmem {}
|
||||
for {set i 1} {${i} <= ${NCycles}} {incr i } {
|
||||
bopcut r
|
||||
|
||||
lappend listmem [expr [meminfo w] / 1024]
|
||||
lappend listmem [meminfo h]
|
||||
if { [checktrend $listmem 0 1 "Memory leak detected"] } {
|
||||
puts "No memory leak, $i iterations"
|
||||
break
|
||||
puts "No memory leak, $i iterations"
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -20,9 +20,9 @@ bop b1 b2
|
||||
set listmem {}
|
||||
for {set i 1} {${i} <= ${NCycles}} {incr i } {
|
||||
bopcut r
|
||||
lappend listmem [expr [meminfo w] / 1024]
|
||||
lappend listmem [meminfo h]
|
||||
if { [checktrend $listmem 0 1 "Memory leak detected"] } {
|
||||
puts "No memory leak, $i iterations"
|
||||
break
|
||||
puts "No memory leak, $i iterations"
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -22,10 +22,10 @@ set listmem {}
|
||||
for {set i 1} {${i} <= ${NCycles}} {incr i } {
|
||||
boptuc r
|
||||
|
||||
lappend listmem [expr [meminfo w] / 1024]
|
||||
lappend listmem [meminfo h]
|
||||
if { [checktrend $listmem 0 1 "Memory leak detected"] } {
|
||||
puts "No memory leak, $i iterations"
|
||||
break
|
||||
puts "No memory leak, $i iterations"
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,9 +21,9 @@ set listmem {}
|
||||
for {set i 1} {${i} <= ${NCycles}} {incr i } {
|
||||
bopcommon r
|
||||
|
||||
lappend listmem [expr [meminfo w] / 1024]
|
||||
lappend listmem [meminfo h]
|
||||
if { [checktrend $listmem 0 1 "Memory leak detected"] } {
|
||||
puts "No memory leak, $i iterations"
|
||||
break
|
||||
puts "No memory leak, $i iterations"
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -20,9 +20,9 @@ bop b1 b2
|
||||
for {set i 1} {${i} <= ${NCycles}} {incr i } {
|
||||
bopfuse r
|
||||
|
||||
lappend listmem [expr [meminfo w] / 1024]
|
||||
lappend listmem [meminfo h]
|
||||
if { [checktrend $listmem 0 1 "Memory leak detected"] } {
|
||||
puts "No memory leak, $i iterations"
|
||||
break
|
||||
puts "No memory leak, $i iterations"
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -20,10 +20,10 @@ bop b1 b2
|
||||
for {set i 1} {${i} <= ${NCycles}} {incr i } {
|
||||
bopsection r
|
||||
|
||||
lappend listmem [expr [meminfo w] / 1024]
|
||||
lappend listmem [meminfo h]
|
||||
if { [checktrend $listmem 0 1 "Memory leak detected"] } {
|
||||
puts "No memory leak, $i iterations"
|
||||
break
|
||||
puts "No memory leak, $i iterations"
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ set listmem {}
|
||||
set i_max 10000
|
||||
OCC145 [locate_data_file OCC145.brep] ${i_max}
|
||||
|
||||
lappend listmem [expr [meminfo w] / 1024]
|
||||
lappend listmem [meminfo h]
|
||||
if { [checktrend $listmem 0 1 "Memory leak detected"] } {
|
||||
puts "No memory leak, $i iterations"
|
||||
break
|
||||
|
@ -16,7 +16,7 @@ set listmem {}
|
||||
set i_max 10000
|
||||
OCC20627 ${i_max}
|
||||
|
||||
lappend listmem [expr [meminfo w] / 1024]
|
||||
lappend listmem [meminfo h]
|
||||
if { [checktrend $listmem 0 1 "Memory leak detected"] } {
|
||||
puts "No memory leak"
|
||||
break
|
||||
|
@ -12,9 +12,9 @@ set i_max 10
|
||||
for {set i 1} {${i} <= ${i_max}} {incr i} {
|
||||
OCC277
|
||||
|
||||
lappend listmem [expr [meminfo w] / 1024]
|
||||
lappend listmem [meminfo h]
|
||||
if { [checktrend $listmem 0 1 "Memory leak detected"] } {
|
||||
puts "No memory leak, $i iterations"
|
||||
break
|
||||
puts "No memory leak, $i iterations"
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -11,11 +11,11 @@ OCC162 s
|
||||
|
||||
set i_max 5
|
||||
for {set i 1} {${i} <= ${i_max}} {incr i} {
|
||||
OCC162 s
|
||||
lappend listmem [expr [meminfo w] / 1024]
|
||||
if { [checktrend $listmem 0 1 "Memory leak detected"] } {
|
||||
puts "No memory leak, $i iterations"
|
||||
break
|
||||
}
|
||||
OCC162 s
|
||||
lappend listmem [meminfo h]
|
||||
if { [checktrend $listmem 0 1 "Memory leak detected"] } {
|
||||
puts "No memory leak, $i iterations"
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,10 +16,10 @@ for {set i 1} {${i} <= ${i_max}} {incr i} {
|
||||
# deselect shape
|
||||
OCC172
|
||||
|
||||
lappend listmem [expr [meminfo w] / 1024]
|
||||
lappend listmem [meminfo h]
|
||||
if { [checktrend $listmem 0 1 "Memory leak detected"] } {
|
||||
puts "No memory leak, $i iterations"
|
||||
break
|
||||
puts "No memory leak, $i iterations"
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,8 @@ vfit
|
||||
catch {vselmode 4 1}
|
||||
vclear
|
||||
|
||||
lappend listmem [expr [meminfo w] / 1024]
|
||||
lappend listmem [meminfo h]
|
||||
if { [checktrend $listmem 0 1 "Memory leak detected"] } {
|
||||
puts "No memory leak"
|
||||
break
|
||||
puts "No memory leak"
|
||||
break
|
||||
}
|
||||
|
@ -12,12 +12,12 @@ vdisplay s
|
||||
set listmem {}
|
||||
set i_max 10
|
||||
for {set i 1} {${i} <= ${i_max}} {incr i} {
|
||||
verase s
|
||||
vdisplay s
|
||||
verase s
|
||||
vdisplay s
|
||||
|
||||
lappend listmem [expr [meminfo w] / 1024]
|
||||
if { [checktrend $listmem 0 1 "Memory leak detected"] } {
|
||||
puts "No memory leak, $i iterations"
|
||||
break
|
||||
}
|
||||
lappend listmem [meminfo h]
|
||||
if { [checktrend $listmem 0 1 "Memory leak detected"] } {
|
||||
puts "No memory leak, $i iterations"
|
||||
break
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user