Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: chrome/browser/process_info_snapshot.h

Issue 333008: Mac: Implement about:memory. (Closed)
Patch Set: Merged ToT. Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/memory_details_mac.cc ('k') | chrome/browser/process_info_snapshot_mac.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_PROCESS_INFO_SNAPSHOT_H_
6 #define CHROME_BROWSER_PROCESS_INFO_SNAPSHOT_H_
7
8 #include <sys/types.h>
9
10 #include <map>
11 #include <string>
12 #include <vector>
13
14 #include "base/process_util.h"
15
16 // A class which captures process information at a given point in time when its
17 // |Sample()| method is called. This information can then be probed by PID.
18 // |Sample()| may take a while to complete, so if calling from the browser
19 // process, only do so from the file thread. The current implementation, only on
20 // Mac, pulls information from /bin/ps. /usr/bin/top provides much more
21 // information about memory, but it has changed greatly from Mac OS 10.5.x to
22 // 10.6.x, thereby raising future compatibility concerns. Moreover, the 10.6.x
23 // version is less capable in terms of configuring output and its output is
24 // harder to parse.
25 // TODO(viettrungluu): This is currently only implemented and used on Mac, so
26 // things are very Mac-specific. If this is ever implemented for other
27 // platforms, we should subclass and add opaqueness (probably |ProcInfoEntry|
28 // should be considered opaque).
29 class ProcessInfoSnapshot {
30 public:
31 ProcessInfoSnapshot();
32 ~ProcessInfoSnapshot();
33
34 // Capture a snapshot of process memory information (by running ps) for the
35 // given list of PIDs. Call only from the file thread.
36 // |pid_list| - list of |ProcessId|s on which to capture information.
37 // returns - |true| if okay, |false| on error.
38 bool Sample(std::vector<base::ProcessId> pid_list);
39
40 // Reset all statistics (deallocating any memory allocated).
41 void Reset();
42
43 // Our basic structure for storing information about a process (the names are
44 // mostly self-explanatory). Note that |command| may not actually reflect the
45 // actual executable name; never trust it absolutely, and only take it
46 // half-seriously when it begins with '/'.
47 struct ProcInfoEntry {
48 base::ProcessId pid;
49 base::ProcessId ppid;
50 uid_t uid;
51 uid_t euid;
52 size_t rss;
53 size_t vsize;
54 std::string command;
55 };
56
57 // Get process information for a given PID.
58 // |pid| - self-explanatory.
59 // |proc_info| - place to put the process information.
60 // returns - |true| if okay, |false| on error (including PID not found).
61 bool GetProcInfo(int pid,
62 ProcInfoEntry* proc_info) const;
63
64 // Fills a |CommittedKBytes| with both resident and paged memory usage, as per
65 // its definition (or as close as we can manage). In the current (Mac)
66 // implementation, we map:
67 // vsize --> comm_priv,
68 // 0 --> comm_mapped,
69 // 0 --> comm_image;
70 // in about:memory: virtual:private = comm_priv,
71 // virtual:mapped = comm_mapped.
72 // TODO(viettrungluu): Doing such a mapping is kind of ugly.
73 // |pid| - self-explanatory.
74 // |usage| - pointer to |CommittedBytes| to fill; zero-ed on error.
75 // returns - |true| on success, |false| on error (including PID not found).
76 bool GetCommittedKBytesOfPID(int pid,
77 base::CommittedKBytes* usage) const;
78
79 // Fills a |WorkingSetKBytes| containing resident private and shared memory,
80 // as per its definition (or as close as we can manage). In the current (Mac)
81 // implementation, we map:
82 // 0 --> ws_priv,
83 // rss --> ws_shareable,
84 // 0 --> ws_shared;
85 // in about:memory: res:private = ws_priv + ws_shareable - ws_shared,
86 // res:shared = ws_shared / num_procs,
87 // res:total = res:private + res:shared.
88 // TODO(viettrungluu): Doing such a mapping is kind of ugly.
89 // |pid| - self-explanatory.
90 // |ws_usage| - pointer to |WorkingSetKBytes| to fill; zero-ed on error.
91 // returns - |true| on success, |false| on error (including PID not found).
92 bool GetWorkingSetKBytesOfPID(int pid,
93 base::WorkingSetKBytes* ws_usage) const;
94
95 // TODO(viettrungluu): Maybe we should also have the following (again, for
96 // "compatibility"):
97 // size_t GetWorkingSetSizeOfPID(int pid) const;
98 // size_t GetPeakWorkingSetSizeOfPID(int pid) const;
99 // size_t GetPrivateBytesOfPID(int pid) const;
100
101 private:
102 // map from |int| (PID) to |ProcInfoEntry|
103 std::map<int,ProcInfoEntry> proc_info_entries_;
104 };
105
106 #endif // CHROME_BROWSER_PROCESS_INFO_SNAPSHOT_H_
OLDNEW
« no previous file with comments | « chrome/browser/memory_details_mac.cc ('k') | chrome/browser/process_info_snapshot_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698