Permalink
Browse files

Minor optimizations for memory measures

  • Loading branch information...
1 parent adeb734 commit cbee39e5d5dcfaef1b3e9c4da8b3f99731ba9284 @poiru poiru committed Aug 12, 2012
Showing with 45 additions and 40 deletions.
  1. +15 −14 Library/MeasureMemory.cpp
  2. +15 −13 Library/MeasurePhysicalMemory.cpp
  3. +15 −13 Library/MeasureVirtualMemory.cpp
View
@@ -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;
+ }
}
-
@@ -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;
+ }
}
@@ -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;
+ }
}

2 comments on commit cbee39e

Member

spx268 replied Aug 13, 2012

I think we are able to increase pagefile size on runtime. Can this change track the total pagefile size except physical memory?

Owner

poiru replied Aug 13, 2012

@spx268: Yeah. I will (partially) revert MeasureMemory.cpp/MeasureVirtualMemory.cpp when I get back home.

Please sign in to comment.