summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-22 13:44:48 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-22 13:44:48 +0000
commit1d775f6c60b825702fd638503e8e630b49ef7bef (patch)
tree2deccf6a97c3dadc6d42b6ab26aaac7034e2a2d3 /base
parent22f5bde796240e9b53dc48367bfecbd0b66b0faf (diff)
downloadchromium_src-1d775f6c60b825702fd638503e8e630b49ef7bef.zip
chromium_src-1d775f6c60b825702fd638503e8e630b49ef7bef.tar.gz
chromium_src-1d775f6c60b825702fd638503e8e630b49ef7bef.tar.bz2
This implements the functions necessary for the task manager on Linux.
Patch by Joel Stanley. BUG=http://crbug.com/16251 Review URL: http://codereview.chromium.org/149455 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21271 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/process_util_linux.cc66
1 files changed, 62 insertions, 4 deletions
diff --git a/base/process_util_linux.cc b/base/process_util_linux.cc
index 4915b8f..b784803 100644
--- a/base/process_util_linux.cc
+++ b/base/process_util_linux.cc
@@ -282,8 +282,13 @@ size_t ProcessMetrics::GetPagefileUsage() const {
return 0;
}
+// On linux, we return the high water mark of vsize.
size_t ProcessMetrics::GetPeakPagefileUsage() const {
- // http://crbug.com/16251
+ std::vector<std::string> proc_stats;
+ GetProcStats(process_, &proc_stats);
+ const size_t kVmPeak = 21;
+ if (proc_stats.size() > kVmPeak)
+ return static_cast<size_t>(StringToInt(proc_stats[kVmPeak]));
return 0;
}
@@ -299,8 +304,15 @@ size_t ProcessMetrics::GetWorkingSetSize() const {
return 0;
}
+// On linux, we return the high water mark of RSS.
size_t ProcessMetrics::GetPeakWorkingSetSize() const {
- // http://crbug.com/16251
+ std::vector<std::string> proc_stats;
+ GetProcStats(process_, &proc_stats);
+ const size_t kVmHwm = 23;
+ if (proc_stats.size() > kVmHwm) {
+ size_t num_pages = static_cast<size_t>(StringToInt(proc_stats[kVmHwm]));
+ return num_pages * getpagesize();
+ }
return 0;
}
@@ -309,9 +321,55 @@ size_t ProcessMetrics::GetPrivateBytes() const {
return 0;
}
+// Private and Shared working set sizes are obtained from /proc/<pid>/smaps,
+// as in http://www.pixelbeat.org/scripts/ps_mem.py
bool ProcessMetrics::GetWorkingSetKBytes(WorkingSetKBytes* ws_usage) const {
- // http://crbug.com/16251
- return false;
+ FilePath stat_file =
+ FilePath("/proc").Append(IntToString(process_)).Append("smaps");
+ std::string smaps;
+ int shared_kb = 0;
+ int private_kb = 0;
+ int pss_kb = 0;
+ bool have_pss = false;
+ const int kPssAdjust = 0.5;
+ if (!file_util::ReadFileToString(stat_file, &smaps))
+ return false;
+
+ StringTokenizer tokenizer(smaps, ":\n");
+ ParsingState state = KEY_NAME;
+ std::string last_key_name;
+ while (tokenizer.GetNext()) {
+ switch (state) {
+ case KEY_NAME:
+ last_key_name = tokenizer.token();
+ state = KEY_VALUE;
+ break;
+ case KEY_VALUE:
+ if (last_key_name.empty()) {
+ NOTREACHED();
+ return false;
+ }
+ if (StartsWithASCII(last_key_name, "Shared_", 1)) {
+ shared_kb += StringToInt(tokenizer.token());
+ } else if (StartsWithASCII(last_key_name, "Private_", 1)) {
+ private_kb += StringToInt(tokenizer.token());
+ } else if (StartsWithASCII(last_key_name, "Pss", 1)) {
+ have_pss = true;
+ pss_kb += StringToInt(tokenizer.token()) + kPssAdjust;
+ }
+ state = KEY_NAME;
+ break;
+ }
+ }
+ ws_usage->priv = private_kb;
+ // Sharable is not calculated, as it does not provide interesting data.
+ ws_usage->shareable = 0;
+ if (have_pss) {
+ ws_usage->shared = pss_kb - private_kb;
+ } else {
+ ws_usage->shared = shared_kb;
+ }
+ return true;
}
// To have /proc/self/io file you must enable CONFIG_TASK_IO_ACCOUNTING