Minor optimizations for memory measures

This commit is contained in:
Birunthan Mohanathas 2012-08-12 17:31:10 +03:00
parent adeb73478b
commit cbee39e5d5
3 changed files with 45 additions and 40 deletions

View File

@ -27,6 +27,10 @@
CMeasureMemory::CMeasureMemory(CMeterWindow* meterWindow, const WCHAR* name) : CMeasure(meterWindow, name),
m_Total(false)
{
MEMORYSTATUSEX stat;
stat.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&stat);
m_MaxValue = (double)(__int64)(stat.ullTotalPageFile + stat.ullTotalPhys);
}
/*
@ -43,15 +47,12 @@ CMeasureMemory::~CMeasureMemory()
*/
void CMeasureMemory::UpdateValue()
{
MEMORYSTATUSEX stat;
stat.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&stat);
if (m_Total)
{
m_Value = (double)(__int64)(stat.ullTotalPageFile + stat.ullTotalPhys);
}
else
if (!m_Total)
{
MEMORYSTATUSEX stat;
stat.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&stat);
m_Value = (double)(__int64)(stat.ullTotalPageFile + stat.ullTotalPhys - stat.ullAvailPageFile - stat.ullAvailPhys);
}
}
@ -62,13 +63,13 @@ void CMeasureMemory::UpdateValue()
*/
void CMeasureMemory::ReadOptions(CConfigParser& parser, const WCHAR* section)
{
double oldMaxValue = m_MaxValue;
CMeasure::ReadOptions(parser, section);
m_MaxValue = oldMaxValue;
m_Total = (1 == parser.ReadInt(section, L"Total", 0));
MEMORYSTATUSEX stat;
stat.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&stat);
m_MaxValue = (double)(__int64)(stat.ullTotalPageFile + stat.ullTotalPhys);
if (m_Total)
{
m_Value = m_MaxValue;
}
}

View File

@ -27,6 +27,10 @@
CMeasurePhysicalMemory::CMeasurePhysicalMemory(CMeterWindow* meterWindow, const WCHAR* name) : CMeasure(meterWindow, name),
m_Total(false)
{
MEMORYSTATUSEX stat;
stat.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&stat);
m_MaxValue = (double)(__int64)stat.ullTotalPhys;
}
/*
@ -43,15 +47,12 @@ CMeasurePhysicalMemory::~CMeasurePhysicalMemory()
*/
void CMeasurePhysicalMemory::UpdateValue()
{
MEMORYSTATUSEX stat;
stat.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&stat);
if (m_Total)
{
m_Value = (double)(__int64)stat.ullTotalPhys;
}
else
if (!m_Total)
{
MEMORYSTATUSEX stat;
stat.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&stat);
m_Value = (double)(__int64)(stat.ullTotalPhys - stat.ullAvailPhys);
}
}
@ -62,13 +63,14 @@ void CMeasurePhysicalMemory::UpdateValue()
*/
void CMeasurePhysicalMemory::ReadOptions(CConfigParser& parser, const WCHAR* section)
{
double oldMaxValue = m_MaxValue;
CMeasure::ReadOptions(parser, section);
m_MaxValue = oldMaxValue;
m_Total = (1 == parser.ReadInt(section, L"Total", 0));
MEMORYSTATUSEX stat;
stat.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&stat);
m_MaxValue = (double)(__int64)stat.ullTotalPhys;
if (m_Total)
{
m_Value = m_MaxValue;
}
}

View File

@ -27,6 +27,10 @@
CMeasureVirtualMemory::CMeasureVirtualMemory(CMeterWindow* meterWindow, const WCHAR* name) : CMeasure(meterWindow, name),
m_Total(false)
{
MEMORYSTATUSEX stat;
stat.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&stat);
m_MaxValue = (double)(__int64)stat.ullTotalPageFile;
}
/*
@ -43,15 +47,12 @@ CMeasureVirtualMemory::~CMeasureVirtualMemory()
*/
void CMeasureVirtualMemory::UpdateValue()
{
MEMORYSTATUSEX stat;
stat.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&stat);
if (m_Total)
{
m_Value = (double)(__int64)stat.ullTotalPageFile;
}
else
if (!m_Total)
{
MEMORYSTATUSEX stat;
stat.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&stat);
m_Value = (double)(__int64)(stat.ullTotalPageFile - stat.ullAvailPageFile);
}
}
@ -62,13 +63,14 @@ void CMeasureVirtualMemory::UpdateValue()
*/
void CMeasureVirtualMemory::ReadOptions(CConfigParser& parser, const WCHAR* section)
{
double oldMaxValue = m_MaxValue;
CMeasure::ReadOptions(parser, section);
m_MaxValue = oldMaxValue;
m_Total = (1 == parser.ReadInt(section, L"Total", 0));
MEMORYSTATUSEX stat;
stat.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&stat);
m_MaxValue = (double)(__int64)stat.ullTotalPageFile;
if (m_Total)
{
m_Value = m_MaxValue;
}
}