Skip to content

Commit

Permalink
Minor optimizations for memory measures
Browse files Browse the repository at this point in the history
  • Loading branch information
poiru committed Aug 12, 2012
1 parent adeb734 commit cbee39e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 40 deletions.
29 changes: 15 additions & 14 deletions Library/MeasureMemory.cpp
Expand Up @@ -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);
}

/*
Expand All @@ -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);
}
}
Expand All @@ -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;
}
}

28 changes: 15 additions & 13 deletions Library/MeasurePhysicalMemory.cpp
Expand Up @@ -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;
}

/*
Expand All @@ -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);
}
}
Expand All @@ -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;
}
}

28 changes: 15 additions & 13 deletions Library/MeasureVirtualMemory.cpp
Expand Up @@ -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;
}

/*
Expand All @@ -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);
}
}
Expand All @@ -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

@spx268
Copy link
Member

@spx268 spx268 commented on cbee39e Aug 13, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@poiru
Copy link
Member Author

@poiru poiru commented on cbee39e Aug 13, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.