mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-10 18:51:21 +03:00
0030904: Visualization - OSD_MemInfo provide Update with parameter of computation kind
Added method OSD_MemInfo::SetActive() for disabling specific counter.
This commit is contained in:
parent
7860770232
commit
1939cfd9cb
@ -778,50 +778,64 @@ static int dmeminfo (Draw_Interpretor& theDI,
|
|||||||
Standard_Integer theArgNb,
|
Standard_Integer theArgNb,
|
||||||
const char** theArgVec)
|
const char** theArgVec)
|
||||||
{
|
{
|
||||||
OSD_MemInfo aMemInfo;
|
|
||||||
if (theArgNb <= 1)
|
if (theArgNb <= 1)
|
||||||
{
|
{
|
||||||
|
OSD_MemInfo aMemInfo;
|
||||||
theDI << aMemInfo.ToString();
|
theDI << aMemInfo.ToString();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NCollection_Map<OSD_MemInfo::Counter> aCounters;
|
||||||
for (Standard_Integer anIter = 1; anIter < theArgNb; ++anIter)
|
for (Standard_Integer anIter = 1; anIter < theArgNb; ++anIter)
|
||||||
{
|
{
|
||||||
TCollection_AsciiString anArg (theArgVec[anIter]);
|
TCollection_AsciiString anArg (theArgVec[anIter]);
|
||||||
anArg.LowerCase();
|
anArg.LowerCase();
|
||||||
if (anArg == "virt" || anArg == "v")
|
if (anArg == "virt" || anArg == "v")
|
||||||
{
|
{
|
||||||
theDI << Standard_Real (aMemInfo.Value (OSD_MemInfo::MemVirtual)) << " ";
|
aCounters.Add (OSD_MemInfo::MemVirtual);
|
||||||
}
|
}
|
||||||
else if (anArg == "heap" || anArg == "h")
|
else if (anArg == "heap" || anArg == "h")
|
||||||
{
|
{
|
||||||
theDI << Standard_Real (aMemInfo.Value (OSD_MemInfo::MemHeapUsage)) << " ";
|
aCounters.Add (OSD_MemInfo::MemHeapUsage);
|
||||||
}
|
}
|
||||||
else if (anArg == "wset" || anArg == "w")
|
else if (anArg == "wset" || anArg == "w")
|
||||||
{
|
{
|
||||||
theDI << Standard_Real (aMemInfo.Value (OSD_MemInfo::MemWorkingSet)) << " ";
|
aCounters.Add (OSD_MemInfo::MemWorkingSet);
|
||||||
}
|
}
|
||||||
else if (anArg == "wsetpeak")
|
else if (anArg == "wsetpeak")
|
||||||
{
|
{
|
||||||
theDI << Standard_Real (aMemInfo.Value (OSD_MemInfo::MemWorkingSetPeak)) << " ";
|
aCounters.Add (OSD_MemInfo::MemWorkingSetPeak);
|
||||||
}
|
}
|
||||||
else if (anArg == "swap")
|
else if (anArg == "swap")
|
||||||
{
|
{
|
||||||
theDI << Standard_Real (aMemInfo.Value (OSD_MemInfo::MemSwapUsage)) << " ";
|
aCounters.Add (OSD_MemInfo::MemSwapUsage);
|
||||||
}
|
}
|
||||||
else if (anArg == "swappeak")
|
else if (anArg == "swappeak")
|
||||||
{
|
{
|
||||||
theDI << Standard_Real (aMemInfo.Value (OSD_MemInfo::MemSwapUsagePeak)) << " ";
|
aCounters.Add (OSD_MemInfo::MemSwapUsagePeak);
|
||||||
}
|
}
|
||||||
else if (anArg == "private")
|
else if (anArg == "private")
|
||||||
{
|
{
|
||||||
theDI << Standard_Real (aMemInfo.Value (OSD_MemInfo::MemPrivate)) << " ";
|
aCounters.Add (OSD_MemInfo::MemPrivate);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cerr << "Unknown argument '" << theArgVec[anIter] << "'!\n";
|
std::cerr << "Unknown argument '" << theArgVec[anIter] << "'!\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OSD_MemInfo aMemInfo (Standard_False);
|
||||||
|
aMemInfo.SetActive (Standard_False);
|
||||||
|
for (NCollection_Map<OSD_MemInfo::Counter>::Iterator aCountersIt (aCounters); aCountersIt.More(); aCountersIt.Next())
|
||||||
|
{
|
||||||
|
aMemInfo.SetActive (aCountersIt.Value(), Standard_True);
|
||||||
|
}
|
||||||
|
aMemInfo.Update();
|
||||||
|
|
||||||
|
for (NCollection_Map<OSD_MemInfo::Counter>::Iterator aCountersIt (aCounters); aCountersIt.More(); aCountersIt.Next())
|
||||||
|
{
|
||||||
|
theDI << Standard_Real (aMemInfo.Value (aCountersIt.Value())) << " ";
|
||||||
|
}
|
||||||
theDI << "\n";
|
theDI << "\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
// =======================================================================
|
// =======================================================================
|
||||||
OSD_MemInfo::OSD_MemInfo (const Standard_Boolean theImmediateUpdate)
|
OSD_MemInfo::OSD_MemInfo (const Standard_Boolean theImmediateUpdate)
|
||||||
{
|
{
|
||||||
|
SetActive (Standard_True);
|
||||||
if (theImmediateUpdate)
|
if (theImmediateUpdate)
|
||||||
{
|
{
|
||||||
Update();
|
Update();
|
||||||
@ -53,6 +54,17 @@ OSD_MemInfo::OSD_MemInfo (const Standard_Boolean theImmediateUpdate)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
// function : SetActive
|
||||||
|
// purpose :
|
||||||
|
// =======================================================================
|
||||||
|
void OSD_MemInfo::SetActive (const Standard_Boolean theActive)
|
||||||
|
{
|
||||||
|
for (Standard_Integer anIter = 0; anIter < MemCounter_NB; ++anIter)
|
||||||
|
{
|
||||||
|
SetActive ((Counter)anIter, theActive);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
// function : Clear
|
// function : Clear
|
||||||
@ -76,53 +88,80 @@ void OSD_MemInfo::Update()
|
|||||||
#ifndef OCCT_UWP
|
#ifndef OCCT_UWP
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#if (_WIN32_WINNT >= 0x0500)
|
#if (_WIN32_WINNT >= 0x0500)
|
||||||
MEMORYSTATUSEX aStatEx;
|
if (IsActive (MemVirtual))
|
||||||
aStatEx.dwLength = sizeof(aStatEx);
|
{
|
||||||
GlobalMemoryStatusEx (&aStatEx);
|
MEMORYSTATUSEX aStatEx;
|
||||||
myCounters[MemVirtual] = Standard_Size(aStatEx.ullTotalVirtual - aStatEx.ullAvailVirtual);
|
aStatEx.dwLength = sizeof(aStatEx);
|
||||||
|
GlobalMemoryStatusEx (&aStatEx);
|
||||||
|
myCounters[MemVirtual] = Standard_Size(aStatEx.ullTotalVirtual - aStatEx.ullAvailVirtual);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
MEMORYSTATUS aStat;
|
if (IsActive (MemVirtual))
|
||||||
aStat.dwLength = sizeof(aStat);
|
{
|
||||||
GlobalMemoryStatus (&aStat);
|
MEMORYSTATUS aStat;
|
||||||
myCounters[MemVirtual] = Standard_Size(aStat.dwTotalVirtual - aStat.dwAvailVirtual);
|
aStat.dwLength = sizeof(aStat);
|
||||||
|
GlobalMemoryStatus (&aStat);
|
||||||
|
myCounters[MemVirtual] = Standard_Size(aStat.dwTotalVirtual - aStat.dwAvailVirtual);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// use Psapi library
|
if (IsActive (MemPrivate)
|
||||||
HANDLE aProcess = GetCurrentProcess();
|
|| IsActive (MemWorkingSet)
|
||||||
#if (_WIN32_WINNT >= 0x0501)
|
|| IsActive (MemWorkingSetPeak)
|
||||||
PROCESS_MEMORY_COUNTERS_EX aProcMemCnts;
|
|| IsActive (MemSwapUsage)
|
||||||
#else
|
|| IsActive (MemSwapUsagePeak))
|
||||||
PROCESS_MEMORY_COUNTERS aProcMemCnts;
|
|
||||||
#endif
|
|
||||||
if (GetProcessMemoryInfo (aProcess, (PROCESS_MEMORY_COUNTERS* )&aProcMemCnts, sizeof(aProcMemCnts)))
|
|
||||||
{
|
{
|
||||||
|
// use Psapi library
|
||||||
|
HANDLE aProcess = GetCurrentProcess();
|
||||||
#if (_WIN32_WINNT >= 0x0501)
|
#if (_WIN32_WINNT >= 0x0501)
|
||||||
myCounters[MemPrivate] = aProcMemCnts.PrivateUsage;
|
PROCESS_MEMORY_COUNTERS_EX aProcMemCnts;
|
||||||
|
#else
|
||||||
|
PROCESS_MEMORY_COUNTERS aProcMemCnts;
|
||||||
#endif
|
#endif
|
||||||
myCounters[MemWorkingSet] = aProcMemCnts.WorkingSetSize;
|
if (GetProcessMemoryInfo (aProcess, (PROCESS_MEMORY_COUNTERS* )&aProcMemCnts, sizeof(aProcMemCnts)))
|
||||||
myCounters[MemWorkingSetPeak] = aProcMemCnts.PeakWorkingSetSize;
|
{
|
||||||
myCounters[MemSwapUsage] = aProcMemCnts.PagefileUsage;
|
#if (_WIN32_WINNT >= 0x0501)
|
||||||
myCounters[MemSwapUsagePeak] = aProcMemCnts.PeakPagefileUsage;
|
myCounters[MemPrivate] = aProcMemCnts.PrivateUsage;
|
||||||
|
#endif
|
||||||
|
myCounters[MemWorkingSet] = aProcMemCnts.WorkingSetSize;
|
||||||
|
myCounters[MemWorkingSetPeak] = aProcMemCnts.PeakWorkingSetSize;
|
||||||
|
myCounters[MemSwapUsage] = aProcMemCnts.PagefileUsage;
|
||||||
|
myCounters[MemSwapUsagePeak] = aProcMemCnts.PeakPagefileUsage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_HEAPINFO hinfo;
|
if (IsActive (MemHeapUsage))
|
||||||
int heapstatus;
|
|
||||||
hinfo._pentry = NULL;
|
|
||||||
|
|
||||||
myCounters[MemHeapUsage] = 0;
|
|
||||||
while((heapstatus = _heapwalk(&hinfo)) == _HEAPOK)
|
|
||||||
{
|
{
|
||||||
if(hinfo._useflag == _USEDENTRY)
|
_HEAPINFO hinfo;
|
||||||
myCounters[MemHeapUsage] += hinfo._size;
|
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) || defined(__EMSCRIPTEN__))
|
#elif (defined(__linux__) || defined(__linux) || defined(__EMSCRIPTEN__))
|
||||||
const struct mallinfo aMI = mallinfo();
|
const struct mallinfo aMI = mallinfo();
|
||||||
myCounters[MemHeapUsage] = aMI.uordblks;
|
if (IsActive (MemHeapUsage))
|
||||||
|
{
|
||||||
|
myCounters[MemHeapUsage] = aMI.uordblks;
|
||||||
|
}
|
||||||
#if defined(__EMSCRIPTEN__)
|
#if defined(__EMSCRIPTEN__)
|
||||||
// /proc/%d/status is not emulated - get more info from mallinfo()
|
// /proc/%d/status is not emulated - get more info from mallinfo()
|
||||||
myCounters[MemWorkingSet] = aMI.uordblks;
|
if (IsActive (MemWorkingSet))
|
||||||
myCounters[MemWorkingSetPeak] = aMI.usmblks;
|
{
|
||||||
|
myCounters[MemWorkingSet] = aMI.uordblks;
|
||||||
|
}
|
||||||
|
if (IsActive (MemWorkingSetPeak))
|
||||||
|
{
|
||||||
|
myCounters[MemWorkingSetPeak] = aMI.usmblks;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// use procfs on Linux
|
// use procfs on Linux
|
||||||
@ -144,26 +183,31 @@ void OSD_MemInfo::Update()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncmp (aBuff, "VmSize:", strlen ("VmSize:")) == 0)
|
if (IsActive (MemVirtual)
|
||||||
|
&& strncmp (aBuff, "VmSize:", strlen ("VmSize:")) == 0)
|
||||||
{
|
{
|
||||||
myCounters[MemVirtual] = atol (aBuff + strlen ("VmSize:")) * 1024;
|
myCounters[MemVirtual] = atol (aBuff + strlen ("VmSize:")) * 1024;
|
||||||
}
|
}
|
||||||
//else if (strncmp (aBuff, "VmPeak:", strlen ("VmPeak:")) == 0)
|
//else if (strncmp (aBuff, "VmPeak:", strlen ("VmPeak:")) == 0)
|
||||||
// myVirtualPeak = atol (aBuff + strlen ("VmPeak:")) * 1024;
|
// myVirtualPeak = atol (aBuff + strlen ("VmPeak:")) * 1024;
|
||||||
else if (strncmp (aBuff, "VmRSS:", strlen ("VmRSS:")) == 0)
|
else if (IsActive (MemWorkingSet)
|
||||||
|
&& strncmp (aBuff, "VmRSS:", strlen ("VmRSS:")) == 0)
|
||||||
{
|
{
|
||||||
myCounters[MemWorkingSet] = atol (aBuff + strlen ("VmRSS:")) * 1024; // RSS - resident set size
|
myCounters[MemWorkingSet] = atol (aBuff + strlen ("VmRSS:")) * 1024; // RSS - resident set size
|
||||||
}
|
}
|
||||||
else if (strncmp (aBuff, "VmHWM:", strlen ("VmHWM:")) == 0)
|
else if (IsActive (MemWorkingSetPeak)
|
||||||
|
&& strncmp (aBuff, "VmHWM:", strlen ("VmHWM:")) == 0)
|
||||||
{
|
{
|
||||||
myCounters[MemWorkingSetPeak] = atol (aBuff + strlen ("VmHWM:")) * 1024; // HWM - high water mark
|
myCounters[MemWorkingSetPeak] = atol (aBuff + strlen ("VmHWM:")) * 1024; // HWM - high water mark
|
||||||
}
|
}
|
||||||
else if (strncmp (aBuff, "VmData:", strlen ("VmData:")) == 0)
|
else if (IsActive (MemPrivate)
|
||||||
|
&& strncmp (aBuff, "VmData:", strlen ("VmData:")) == 0)
|
||||||
{
|
{
|
||||||
if (myCounters[MemPrivate] == Standard_Size(-1)) ++myCounters[MemPrivate];
|
if (myCounters[MemPrivate] == Standard_Size(-1)) ++myCounters[MemPrivate];
|
||||||
myCounters[MemPrivate] += atol (aBuff + strlen ("VmData:")) * 1024;
|
myCounters[MemPrivate] += atol (aBuff + strlen ("VmData:")) * 1024;
|
||||||
}
|
}
|
||||||
else if (strncmp (aBuff, "VmStk:", strlen ("VmStk:")) == 0)
|
else if (IsActive (MemPrivate)
|
||||||
|
&& strncmp (aBuff, "VmStk:", strlen ("VmStk:")) == 0)
|
||||||
{
|
{
|
||||||
if (myCounters[MemPrivate] == Standard_Size(-1)) ++myCounters[MemPrivate];
|
if (myCounters[MemPrivate] == Standard_Size(-1)) ++myCounters[MemPrivate];
|
||||||
myCounters[MemPrivate] += atol (aBuff + strlen ("VmStk:")) * 1024;
|
myCounters[MemPrivate] += atol (aBuff + strlen ("VmStk:")) * 1024;
|
||||||
@ -171,20 +215,25 @@ void OSD_MemInfo::Update()
|
|||||||
}
|
}
|
||||||
aFile.close();
|
aFile.close();
|
||||||
#elif (defined(__APPLE__))
|
#elif (defined(__APPLE__))
|
||||||
struct task_basic_info aTaskInfo;
|
if (IsActive (MemVirtual)
|
||||||
mach_msg_type_number_t aTaskInfoCount = TASK_BASIC_INFO_COUNT;
|
|| IsActive (MemWorkingSet)
|
||||||
if (task_info (mach_task_self(), TASK_BASIC_INFO,
|
|| IsActive (MemHeapUsage))
|
||||||
(task_info_t )&aTaskInfo, &aTaskInfoCount) == KERN_SUCCESS)
|
|
||||||
{
|
{
|
||||||
// On Mac OS X, these values in bytes, not pages!
|
struct task_basic_info aTaskInfo;
|
||||||
myCounters[MemVirtual] = aTaskInfo.virtual_size;
|
mach_msg_type_number_t aTaskInfoCount = TASK_BASIC_INFO_COUNT;
|
||||||
myCounters[MemWorkingSet] = aTaskInfo.resident_size;
|
if (task_info (mach_task_self(), TASK_BASIC_INFO,
|
||||||
|
(task_info_t )&aTaskInfo, &aTaskInfoCount) == KERN_SUCCESS)
|
||||||
|
{
|
||||||
|
// On Mac OS X, these values in bytes, not pages!
|
||||||
|
myCounters[MemVirtual] = aTaskInfo.virtual_size;
|
||||||
|
myCounters[MemWorkingSet] = aTaskInfo.resident_size;
|
||||||
|
|
||||||
//Getting malloc statistics
|
//Getting malloc statistics
|
||||||
malloc_statistics_t aStats;
|
malloc_statistics_t aStats;
|
||||||
malloc_zone_statistics (NULL, &aStats);
|
malloc_zone_statistics (NULL, &aStats);
|
||||||
|
|
||||||
myCounters[MemHeapUsage] = aStats.size_in_use;
|
myCounters[MemHeapUsage] = aStats.size_in_use;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
@ -197,33 +246,33 @@ void OSD_MemInfo::Update()
|
|||||||
TCollection_AsciiString OSD_MemInfo::ToString() const
|
TCollection_AsciiString OSD_MemInfo::ToString() const
|
||||||
{
|
{
|
||||||
TCollection_AsciiString anInfo;
|
TCollection_AsciiString anInfo;
|
||||||
if (myCounters[MemPrivate] != Standard_Size(-1))
|
if (hasValue (MemPrivate))
|
||||||
{
|
{
|
||||||
anInfo += TCollection_AsciiString(" Private memory: ") + Standard_Integer (ValueMiB (MemPrivate)) + " MiB\n";
|
anInfo += TCollection_AsciiString(" Private memory: ") + Standard_Integer (ValueMiB (MemPrivate)) + " MiB\n";
|
||||||
}
|
}
|
||||||
if (myCounters[MemWorkingSet] != Standard_Size(-1))
|
if (hasValue (MemWorkingSet))
|
||||||
{
|
{
|
||||||
anInfo += TCollection_AsciiString(" Working Set: ") + Standard_Integer (ValueMiB (MemWorkingSet)) + " MiB";
|
anInfo += TCollection_AsciiString(" Working Set: ") + Standard_Integer (ValueMiB (MemWorkingSet)) + " MiB";
|
||||||
if (myCounters[MemWorkingSetPeak] != Standard_Size(-1))
|
if (hasValue (MemWorkingSetPeak))
|
||||||
{
|
{
|
||||||
anInfo += TCollection_AsciiString(" (peak: ") + Standard_Integer (ValueMiB (MemWorkingSetPeak)) + " MiB)";
|
anInfo += TCollection_AsciiString(" (peak: ") + Standard_Integer (ValueMiB (MemWorkingSetPeak)) + " MiB)";
|
||||||
}
|
}
|
||||||
anInfo += "\n";
|
anInfo += "\n";
|
||||||
}
|
}
|
||||||
if (myCounters[MemSwapUsage] != Standard_Size(-1))
|
if (hasValue (MemSwapUsage))
|
||||||
{
|
{
|
||||||
anInfo += TCollection_AsciiString(" Pagefile usage: ") + Standard_Integer (ValueMiB (MemSwapUsage)) + " MiB";
|
anInfo += TCollection_AsciiString(" Pagefile usage: ") + Standard_Integer (ValueMiB (MemSwapUsage)) + " MiB";
|
||||||
if (myCounters[MemSwapUsagePeak] != Standard_Size(-1))
|
if (hasValue (MemSwapUsagePeak))
|
||||||
{
|
{
|
||||||
anInfo += TCollection_AsciiString(" (peak: ") + Standard_Integer (ValueMiB (MemSwapUsagePeak)) + " MiB)";
|
anInfo += TCollection_AsciiString(" (peak: ") + Standard_Integer (ValueMiB (MemSwapUsagePeak)) + " MiB)";
|
||||||
}
|
}
|
||||||
anInfo += "\n";
|
anInfo += "\n";
|
||||||
}
|
}
|
||||||
if (myCounters[MemVirtual] != Standard_Size(-1))
|
if (hasValue (MemVirtual))
|
||||||
{
|
{
|
||||||
anInfo += TCollection_AsciiString(" Virtual memory: ") + Standard_Integer (ValueMiB (MemVirtual)) + " MiB\n";
|
anInfo += TCollection_AsciiString(" Virtual memory: ") + Standard_Integer (ValueMiB (MemVirtual)) + " MiB\n";
|
||||||
}
|
}
|
||||||
if (myCounters[MemHeapUsage] != Standard_Size(-1))
|
if (hasValue (MemHeapUsage))
|
||||||
{
|
{
|
||||||
anInfo += TCollection_AsciiString(" Heap memory: ") + Standard_Integer (ValueMiB (MemHeapUsage)) + " MiB\n";
|
anInfo += TCollection_AsciiString(" Heap memory: ") + Standard_Integer (ValueMiB (MemHeapUsage)) + " MiB\n";
|
||||||
}
|
}
|
||||||
@ -236,7 +285,7 @@ TCollection_AsciiString OSD_MemInfo::ToString() const
|
|||||||
// =======================================================================
|
// =======================================================================
|
||||||
Standard_Size OSD_MemInfo::Value (const OSD_MemInfo::Counter theCounter) const
|
Standard_Size OSD_MemInfo::Value (const OSD_MemInfo::Counter theCounter) const
|
||||||
{
|
{
|
||||||
if (theCounter < 0 || theCounter >= MemCounter_NB)
|
if (theCounter < 0 || theCounter >= MemCounter_NB || !IsActive (theCounter))
|
||||||
{
|
{
|
||||||
return Standard_Size(-1);
|
return Standard_Size(-1);
|
||||||
}
|
}
|
||||||
@ -249,7 +298,7 @@ Standard_Size OSD_MemInfo::Value (const OSD_MemInfo::Counter theCounter) const
|
|||||||
// =======================================================================
|
// =======================================================================
|
||||||
Standard_Size OSD_MemInfo::ValueMiB (const OSD_MemInfo::Counter theCounter) const
|
Standard_Size OSD_MemInfo::ValueMiB (const OSD_MemInfo::Counter theCounter) const
|
||||||
{
|
{
|
||||||
if (theCounter < 0 || theCounter >= MemCounter_NB)
|
if (theCounter < 0 || theCounter >= MemCounter_NB || !IsActive (theCounter))
|
||||||
{
|
{
|
||||||
return Standard_Size(-1);
|
return Standard_Size(-1);
|
||||||
}
|
}
|
||||||
@ -263,7 +312,7 @@ Standard_Size OSD_MemInfo::ValueMiB (const OSD_MemInfo::Counter theCounter) cons
|
|||||||
// =======================================================================
|
// =======================================================================
|
||||||
Standard_Real OSD_MemInfo::ValuePreciseMiB (const OSD_MemInfo::Counter theCounter) const
|
Standard_Real OSD_MemInfo::ValuePreciseMiB (const OSD_MemInfo::Counter theCounter) const
|
||||||
{
|
{
|
||||||
if (theCounter < 0 || theCounter >= MemCounter_NB)
|
if (theCounter < 0 || theCounter >= MemCounter_NB || !IsActive (theCounter))
|
||||||
{
|
{
|
||||||
return -1.0;
|
return -1.0;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#ifndef _OSD_MemInfo_H__
|
#ifndef _OSD_MemInfo_H__
|
||||||
#define _OSD_MemInfo_H__
|
#define _OSD_MemInfo_H__
|
||||||
|
|
||||||
|
#include <NCollection_Map.hxx>
|
||||||
#include <TCollection_AsciiString.hxx>
|
#include <TCollection_AsciiString.hxx>
|
||||||
|
|
||||||
//! This class provide information about memory utilized by current process.
|
//! This class provide information about memory utilized by current process.
|
||||||
@ -65,9 +66,21 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! Create and initialize
|
//! Create and initialize. By default all countes are active
|
||||||
Standard_EXPORT OSD_MemInfo (const Standard_Boolean theImmediateUpdate = Standard_True);
|
Standard_EXPORT OSD_MemInfo (const Standard_Boolean theImmediateUpdate = Standard_True);
|
||||||
|
|
||||||
|
//! Return true if the counter is active
|
||||||
|
Standard_Boolean IsActive (const OSD_MemInfo::Counter theCounter) const { return myActiveCounters[theCounter]; }
|
||||||
|
|
||||||
|
//! Set all counters active. The information is collected for active counters.
|
||||||
|
//! @param theActive state for counters
|
||||||
|
Standard_EXPORT void SetActive (const Standard_Boolean theActive);
|
||||||
|
|
||||||
|
//! Set the counter active. The information is collected for active counters.
|
||||||
|
//! @param theCounter type of counter
|
||||||
|
//! @param theActive state for the counter
|
||||||
|
void SetActive (const OSD_MemInfo::Counter theCounter, const Standard_Boolean theActive) { myActiveCounters[theCounter] = theActive; }
|
||||||
|
|
||||||
//! Clear counters
|
//! Clear counters
|
||||||
Standard_EXPORT void Clear();
|
Standard_EXPORT void Clear();
|
||||||
|
|
||||||
@ -97,9 +110,16 @@ public:
|
|||||||
//! Return the string representation for all available counter.
|
//! Return the string representation for all available counter.
|
||||||
Standard_EXPORT static TCollection_AsciiString PrintInfo();
|
Standard_EXPORT static TCollection_AsciiString PrintInfo();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
//! Return true if the counter is active and the value is valid
|
||||||
|
Standard_Boolean hasValue (const OSD_MemInfo::Counter theCounter) const
|
||||||
|
{ return IsActive (theCounter) && myCounters[theCounter] != Standard_Size(-1); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Standard_Size myCounters[MemCounter_NB]; //!< Counters' values, in bytes
|
Standard_Size myCounters[MemCounter_NB]; //!< Counters' values, in bytes
|
||||||
|
Standard_Boolean myActiveCounters[MemCounter_NB]; //!< container of active state for a counter
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user