Skip to content
Snippets Groups Projects
Commit abf50e8c authored by Nat Goodspeed's avatar Nat Goodspeed
Browse files

CHOP-753: Fix compile errors in LLMemoryInfo Windows-specific code.

parent 01607fe4
Branches
Tags
No related merge requests found
...@@ -665,7 +665,7 @@ static U32 LLMemoryAdjustKBResult(U32 inKB) ...@@ -665,7 +665,7 @@ static U32 LLMemoryAdjustKBResult(U32 inKB)
U32 LLMemoryInfo::getPhysicalMemoryKB() const U32 LLMemoryInfo::getPhysicalMemoryKB() const
{ {
#if LL_WINDOWS #if LL_WINDOWS
return LLMemoryAdjustKBResult(mStatsMap["Total Physical KB"]); return LLMemoryAdjustKBResult(mStatsMap["Total Physical KB"].asInteger());
#elif LL_DARWIN #elif LL_DARWIN
// This might work on Linux as well. Someone check... // This might work on Linux as well. Someone check...
...@@ -712,9 +712,13 @@ U32 LLMemoryInfo::getPhysicalMemoryClamped() const ...@@ -712,9 +712,13 @@ U32 LLMemoryInfo::getPhysicalMemoryClamped() const
//static //static
void LLMemoryInfo::getAvailableMemoryKB(U32& avail_physical_mem_kb, U32& avail_virtual_mem_kb) void LLMemoryInfo::getAvailableMemoryKB(U32& avail_physical_mem_kb, U32& avail_virtual_mem_kb)
{ {
// Sigh, this shouldn't be a static method, then we wouldn't have to
// reload this data separately from refresh()
LLSD statsMap(loadStatsMap(loadStatsArray()));
#if LL_WINDOWS #if LL_WINDOWS
avail_physical_mem_kb = mStatsMap["Avail Physical KB"]; avail_physical_mem_kb = statsMap["Avail Physical KB"].asInteger();
avail_virtual_mem_kb = mStatsMap["Avail Virtual KB"]; avail_virtual_mem_kb = statsMap["Avail Virtual KB"].asInteger();
#elif LL_DARWIN #elif LL_DARWIN
// mStatsMap is derived from vm_stat, look for (e.g.) "kb free": // mStatsMap is derived from vm_stat, look for (e.g.) "kb free":
...@@ -839,22 +843,35 @@ LLSD LLMemoryInfo::getStatsArray() const ...@@ -839,22 +843,35 @@ LLSD LLMemoryInfo::getStatsArray() const
} }
LLMemoryInfo& LLMemoryInfo::refresh() LLMemoryInfo& LLMemoryInfo::refresh()
{
mStatsArray = loadStatsArray();
// Recast same data as mStatsMap for easy access
mStatsMap = loadStatsMap(mStatsArray);
LL_DEBUGS("LLMemoryInfo") << "Populated mStatsMap:\n";
LLSDSerialize::toPrettyXML(mStatsMap, LL_CONT);
LL_ENDL;
return *this;
}
LLSD LLMemoryInfo::loadStatsArray()
{ {
// This implementation is derived from stream() code (as of 2011-06-29). // This implementation is derived from stream() code (as of 2011-06-29).
mStatsArray = LLSD::emptyArray(); LLSD statsArray(LLSD::emptyArray());
#if LL_WINDOWS #if LL_WINDOWS
MEMORYSTATUSEX state; MEMORYSTATUSEX state;
state.dwLength = sizeof(state); state.dwLength = sizeof(state);
GlobalMemoryStatusEx(&state); GlobalMemoryStatusEx(&state);
mStatsArray.append(LLSDArray("Percent Memory use")(LLSD::Integer(state.dwMemoryLoad))); statsArray.append(LLSDArray("Percent Memory use")(LLSD::Integer(state.dwMemoryLoad)));
mStatsArray.append(LLSDArray("Total Physical KB") (LLSD::Integer(state.ullTotalPhys/1024))); statsArray.append(LLSDArray("Total Physical KB") (LLSD::Integer(state.ullTotalPhys/1024)));
mStatsArray.append(LLSDArray("Avail Physical KB") (LLSD::Integer(state.ullAvailPhys/1024))); statsArray.append(LLSDArray("Avail Physical KB") (LLSD::Integer(state.ullAvailPhys/1024)));
mStatsArray.append(LLSDArray("Total page KB") (LLSD::Integer(state.ullTotalPageFile/1024))); statsArray.append(LLSDArray("Total page KB") (LLSD::Integer(state.ullTotalPageFile/1024)));
mStatsArray.append(LLSDArray("Avail page KB") (LLSD::Integer(state.ullAvailPageFile/1024))); statsArray.append(LLSDArray("Avail page KB") (LLSD::Integer(state.ullAvailPageFile/1024)));
mStatsArray.append(LLSDArray("Total Virtual KB") (LLSD::Integer(state.ullTotalVirtual/1024))); statsArray.append(LLSDArray("Total Virtual KB") (LLSD::Integer(state.ullTotalVirtual/1024)));
mStatsArray.append(LLSDArray("Avail Virtual KB") (LLSD::Integer(state.ullAvailVirtual/1024))); statsArray.append(LLSDArray("Avail Virtual KB") (LLSD::Integer(state.ullAvailVirtual/1024)));
#elif LL_DARWIN #elif LL_DARWIN
uint64_t phys = 0; uint64_t phys = 0;
...@@ -863,7 +880,7 @@ LLMemoryInfo& LLMemoryInfo::refresh() ...@@ -863,7 +880,7 @@ LLMemoryInfo& LLMemoryInfo::refresh()
if (sysctlbyname("hw.memsize", &phys, &len, NULL, 0) == 0) if (sysctlbyname("hw.memsize", &phys, &len, NULL, 0) == 0)
{ {
mStatsArray.append(LLSDArray("Total Physical KB")(LLSD::Integer(phys/1024))); statsArray.append(LLSDArray("Total Physical KB")(LLSD::Integer(phys/1024)));
} }
else else
{ {
...@@ -925,7 +942,7 @@ LLMemoryInfo& LLMemoryInfo::refresh() ...@@ -925,7 +942,7 @@ LLMemoryInfo& LLMemoryInfo::refresh()
<< "' in vm_stat line: " << line << LL_ENDL; << "' in vm_stat line: " << line << LL_ENDL;
continue; continue;
} }
mStatsArray.append(LLSDArray("page size")(pagesizekb)); statsArray.append(LLSDArray("page size")(pagesizekb));
} }
else if (boost::regex_match(line, matched, stat_rx)) else if (boost::regex_match(line, matched, stat_rx))
{ {
...@@ -951,7 +968,7 @@ LLMemoryInfo& LLMemoryInfo::refresh() ...@@ -951,7 +968,7 @@ LLMemoryInfo& LLMemoryInfo::refresh()
continue; continue;
} }
// Store this statistic. // Store this statistic.
mStatsArray.append(LLSDArray(key)(value)); statsArray.append(LLSDArray(key)(value));
// Is this in units of pages? If so, convert to Kb. // Is this in units of pages? If so, convert to Kb.
static const LLSD::String pages("Pages "); static const LLSD::String pages("Pages ");
if (key.substr(0, pages.length()) == pages) if (key.substr(0, pages.length()) == pages)
...@@ -959,7 +976,7 @@ LLMemoryInfo& LLMemoryInfo::refresh() ...@@ -959,7 +976,7 @@ LLMemoryInfo& LLMemoryInfo::refresh()
// Synthesize a new key with kb in place of Pages // Synthesize a new key with kb in place of Pages
LLSD::String kbkey("kb "); LLSD::String kbkey("kb ");
kbkey.append(key.substr(pages.length())); kbkey.append(key.substr(pages.length()));
mStatsArray.append(LLSDArray(kbkey)(value * pagesizekb)); statsArray.append(LLSDArray(kbkey)(value * pagesizekb));
} }
} }
else if (boost::regex_match(line, matched, cache_rx)) else if (boost::regex_match(line, matched, cache_rx))
...@@ -981,7 +998,7 @@ LLMemoryInfo& LLMemoryInfo::refresh() ...@@ -981,7 +998,7 @@ LLMemoryInfo& LLMemoryInfo::refresh()
<< "' in vm_stat line: " << line << LL_ENDL; << "' in vm_stat line: " << line << LL_ENDL;
continue; continue;
} }
mStatsArray.append(LLSDArray(cache_keys[i])(value)); statsArray.append(LLSDArray(cache_keys[i])(value));
} }
} }
else else
...@@ -997,7 +1014,7 @@ LLMemoryInfo& LLMemoryInfo::refresh() ...@@ -997,7 +1014,7 @@ LLMemoryInfo& LLMemoryInfo::refresh()
phys = (U64)(sysconf(_SC_PHYS_PAGES)) * (U64)(sysconf(_SC_PAGESIZE)/1024); phys = (U64)(sysconf(_SC_PHYS_PAGES)) * (U64)(sysconf(_SC_PAGESIZE)/1024);
mStatsArray.append(LLSDArray("Total Physical KB")(phys)); statsArray.append(LLSDArray("Total Physical KB")(phys));
#elif LL_LINUX #elif LL_LINUX
std::ifstream meminfo(MEMINFO_FILE); std::ifstream meminfo(MEMINFO_FILE);
...@@ -1048,7 +1065,7 @@ LLMemoryInfo& LLMemoryInfo::refresh() ...@@ -1048,7 +1065,7 @@ LLMemoryInfo& LLMemoryInfo::refresh()
continue; continue;
} }
// Store this statistic. // Store this statistic.
mStatsArray.append(LLSDArray(key)(value)); statsArray.append(LLSDArray(key)(value));
} }
else else
{ {
...@@ -1067,19 +1084,20 @@ LLMemoryInfo& LLMemoryInfo::refresh() ...@@ -1067,19 +1084,20 @@ LLMemoryInfo& LLMemoryInfo::refresh()
#endif #endif
// Recast same data as mStatsMap for easy access return statsArray;
BOOST_FOREACH(LLSD pair, inArray(mStatsArray)) }
LLSD LLMemoryInfo::loadStatsMap(const LLSD& statsArray)
{
LLSD statsMap;
BOOST_FOREACH(LLSD pair, inArray(statsArray))
{ {
// Specify asString() to disambiguate map indexing from array // Specify asString() to disambiguate map indexing from array
// subscripting. // subscripting.
mStatsMap[pair[0].asString()] = pair[1]; statsMap[pair[0].asString()] = pair[1];
} }
return statsMap;
LL_DEBUGS("LLMemoryInfo") << "Populated mStatsMap:\n";
LLSDSerialize::toPrettyXML(mStatsMap, LL_CONT);
LL_ENDL;
return *this;
} }
std::ostream& operator<<(std::ostream& s, const LLOSInfo& info) std::ostream& operator<<(std::ostream& s, const LLOSInfo& info)
......
...@@ -141,6 +141,10 @@ class LL_COMMON_API LLMemoryInfo ...@@ -141,6 +141,10 @@ class LL_COMMON_API LLMemoryInfo
LLMemoryInfo& refresh(); LLMemoryInfo& refresh();
private: private:
// These methods are used to set mStatsArray and mStatsMap.
static LLSD loadStatsArray();
static LLSD loadStatsMap(const LLSD&);
// Memory stats for getStatsArray(). It's straightforward to convert that // Memory stats for getStatsArray(). It's straightforward to convert that
// to getStatsMap() form, less so to reconstruct the original order when // to getStatsMap() form, less so to reconstruct the original order when
// converting the other way. // converting the other way.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment