diff options
author | jamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-01 23:51:17 +0000 |
---|---|---|
committer | jamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-01 23:51:17 +0000 |
commit | ae9f26cada993a1f38878e0194de6d9925c0249f (patch) | |
tree | 82fce08d1dda17d0514a5649411362b760b55244 /base | |
parent | 327fda2054ff1642aab71f5edd88af46b896fd54 (diff) | |
download | chromium_src-ae9f26cada993a1f38878e0194de6d9925c0249f.zip chromium_src-ae9f26cada993a1f38878e0194de6d9925c0249f.tar.gz chromium_src-ae9f26cada993a1f38878e0194de6d9925c0249f.tar.bz2 |
Revert 94999 - CrOS - Add memory consumption status bar widget behind flag
Pass --memory-widget on CrOS to get a real-time display, updated every 5 seconds, of the system's free memory. Tooltip and menu itself detail the data from /proc/meminfo. Also made base::GetSystemMemoryInfo() available on Linux systems to provide detailed data.
BUG=chromium-os:18446
TEST=manual
Review URL: http://codereview.chromium.org/7518010
TBR=jamescook@chromium.org
Review URL: http://codereview.chromium.org/7544033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95004 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/process_util.h | 9 | ||||
-rw-r--r-- | base/process_util_linux.cc | 36 |
2 files changed, 10 insertions, 35 deletions
diff --git a/base/process_util.h b/base/process_util.h index 5f88c62..3d9b7d1 100644 --- a/base/process_util.h +++ b/base/process_util.h @@ -653,14 +653,7 @@ class BASE_API ProcessMetrics { DISALLOW_COPY_AND_ASSIGN(ProcessMetrics); }; -#if defined(OS_LINUX) -// Retrieves data from /proc/meminfo about system-wide memory consumption. -// Values are in KB. Returns true on success. -BASE_API bool GetSystemMemoryInfo(int* total_kb, int* free_kb, int* buffers_kb, - int* cache_kb, int* shmem_kb); -#endif - -// Returns the memory committed by the system in KBytes. +// Returns the memory commited by the system in KBytes. // Returns 0 if it can't compute the commit charge. BASE_API size_t GetSystemCommitCharge(); diff --git a/base/process_util_linux.cc b/base/process_util_linux.cc index 3ea383f..aabd201 100644 --- a/base/process_util_linux.cc +++ b/base/process_util_linux.cc @@ -562,8 +562,7 @@ const size_t kMemCacheIndex = 10; } // namespace -bool GetSystemMemoryInfo(int* mem_total, int* mem_free, int* mem_buffers, - int* mem_cache, int* shmem) { +size_t GetSystemCommitCharge() { // Synchronously reading files in /proc is safe. base::ThreadRestrictions::ScopedAllowIO allow_io; @@ -572,7 +571,7 @@ bool GetSystemMemoryInfo(int* mem_total, int* mem_free, int* mem_buffers, std::string meminfo_data; if (!file_util::ReadFileToString(meminfo_file, &meminfo_data)) { LOG(WARNING) << "Failed to open /proc/meminfo."; - return false; + return 0; } std::vector<std::string> meminfo_fields; SplitStringAlongWhitespace(meminfo_data, &meminfo_fields); @@ -580,7 +579,7 @@ bool GetSystemMemoryInfo(int* mem_total, int* mem_free, int* mem_buffers, if (meminfo_fields.size() < kMemCacheIndex) { LOG(WARNING) << "Failed to parse /proc/meminfo. Only found " << meminfo_fields.size() << " fields."; - return false; + return 0; } DCHECK_EQ(meminfo_fields[kMemTotalIndex-1], "MemTotal:"); @@ -588,30 +587,13 @@ bool GetSystemMemoryInfo(int* mem_total, int* mem_free, int* mem_buffers, DCHECK_EQ(meminfo_fields[kMemBuffersIndex-1], "Buffers:"); DCHECK_EQ(meminfo_fields[kMemCacheIndex-1], "Cached:"); - base::StringToInt(meminfo_fields[kMemTotalIndex], mem_total); - base::StringToInt(meminfo_fields[kMemFreeIndex], mem_free); - base::StringToInt(meminfo_fields[kMemBuffersIndex], mem_buffers); - base::StringToInt(meminfo_fields[kMemCacheIndex], mem_cache); -#if defined(OS_CHROMEOS) - // Chrome OS has a tweaked kernel that allows us to query Shmem, which is - // usually video memory otherwise invisible to the OS. Unfortunately, the - // meminfo format varies on different hardware so we have to search for the - // string. It always appears after "Cached:". - for (size_t i = kMemCacheIndex+2; i < meminfo_fields.size(); i += 3) { - if (meminfo_fields[i] == "Shmem:") { - base::StringToInt(meminfo_fields[i+1], shmem); - break; - } - } -#endif - return true; -} + int mem_total, mem_free, mem_buffers, mem_cache; + base::StringToInt(meminfo_fields[kMemTotalIndex], &mem_total); + base::StringToInt(meminfo_fields[kMemFreeIndex], &mem_free); + base::StringToInt(meminfo_fields[kMemBuffersIndex], &mem_buffers); + base::StringToInt(meminfo_fields[kMemCacheIndex], &mem_cache); -size_t GetSystemCommitCharge() { - int total, free, buffers, cache, shmem; - if (!GetSystemMemoryInfo(&total, &free, &buffers, &cache, &shmem)) - return 0; - return total - free - buffers - cache; + return mem_total - mem_free - mem_buffers - mem_cache; } namespace { |