| OLD | NEW |
| (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 <stddef.h> | |
| 9 #include <stdint.h> | |
| 10 #include <sys/types.h> | |
| 11 | |
| 12 #include <map> | |
| 13 #include <string> | |
| 14 #include <vector> | |
| 15 | |
| 16 #include "base/process/process_handle.h" | |
| 17 #include "base/process/process_metrics.h" | |
| 18 | |
| 19 // A class which captures process information at a given point in time when its | |
| 20 // |Sample()| method is called. This information can then be probed by PID. | |
| 21 // |Sample()| may take a while to complete, so if calling from the browser | |
| 22 // process, only do so from the file thread. | |
| 23 // TODO(viettrungluu): This is currently only implemented and used on Mac, so | |
| 24 // things are very Mac-specific. If this is ever implemented for other | |
| 25 // platforms, we should subclass and add opaqueness (probably |ProcInfoEntry| | |
| 26 // should be considered opaque). | |
| 27 class ProcessInfoSnapshot { | |
| 28 public: | |
| 29 ProcessInfoSnapshot(); | |
| 30 ~ProcessInfoSnapshot(); | |
| 31 | |
| 32 // Maximum size of lists of PIDs which this class will accept; used in | |
| 33 // |Sample()| below. | |
| 34 static const size_t kMaxPidListSize; | |
| 35 | |
| 36 // Capture a snapshot of process memory information for the | |
| 37 // given list of PIDs. Call only from the file thread. | |
| 38 // |pid_list| - list of |ProcessId|s on which to capture information; must | |
| 39 // have no more than |kMaxPidListSize| (above) entries, | |
| 40 // returns - |true| if okay, |false| on error. | |
| 41 bool Sample(std::vector<base::ProcessId> pid_list); | |
| 42 | |
| 43 // Reset all statistics (deallocating any memory allocated). | |
| 44 void Reset(); | |
| 45 | |
| 46 // Our basic structure for storing information about a process (the names are | |
| 47 // mostly self-explanatory). Note that |command| may not actually reflect the | |
| 48 // actual executable name; never trust it absolutely, and only take it | |
| 49 // half-seriously when it begins with '/'. | |
| 50 struct ProcInfoEntry { | |
| 51 base::ProcessId pid; | |
| 52 base::ProcessId ppid; | |
| 53 uid_t uid; | |
| 54 uid_t euid; | |
| 55 // Explicitly use uint64_t instead of size_t in case this code is running | |
| 56 // in a 32 bit process and the target process is 64 bit. | |
| 57 uint64_t rss; | |
| 58 uint64_t rshrd; | |
| 59 uint64_t rprvt; | |
| 60 uint64_t vsize; | |
| 61 std::string command; | |
| 62 | |
| 63 ProcInfoEntry(); | |
| 64 ProcInfoEntry(const ProcInfoEntry& other); | |
| 65 }; | |
| 66 | |
| 67 // Get process information for a given PID. | |
| 68 // |pid| - self-explanatory. | |
| 69 // |proc_info| - place to put the process information. | |
| 70 // returns - |true| if okay, |false| on error (including PID not found). | |
| 71 bool GetProcInfo(int pid, | |
| 72 ProcInfoEntry* proc_info) const; | |
| 73 | |
| 74 // Fills a |CommittedKBytes| with both resident and paged memory usage, as per | |
| 75 // its definition (or as close as we can manage). In the current (Mac) | |
| 76 // implementation, we map: | |
| 77 // vsize --> comm_priv, | |
| 78 // 0 --> comm_mapped, | |
| 79 // 0 --> comm_image; | |
| 80 // in about:memory: virtual:private = comm_priv, | |
| 81 // virtual:mapped = comm_mapped. | |
| 82 // TODO(viettrungluu): Doing such a mapping is kind of ugly. | |
| 83 // |pid| - self-explanatory. | |
| 84 // |usage| - pointer to |CommittedBytes| to fill; zero-ed on error. | |
| 85 // returns - |true| on success, |false| on error (including PID not found). | |
| 86 bool GetCommittedKBytesOfPID(int pid, | |
| 87 base::CommittedKBytes* usage) const; | |
| 88 | |
| 89 // Fills a |WorkingSetKBytes| containing resident private and shared memory, | |
| 90 // as per its definition (or as close as we can manage). In the current (Mac) | |
| 91 // implementation, we map: | |
| 92 // rprvt --> ws_priv, | |
| 93 // rss --> ws_shareable, | |
| 94 // rshrd --> ws_shared; | |
| 95 // in about:memory: res:private = ws_priv + ws_shareable - ws_shared, | |
| 96 // res:shared = ws_shared / num_procs, | |
| 97 // res:total = res:private + res:shared. | |
| 98 // TODO(viettrungluu): Doing such a mapping is kind of ugly. | |
| 99 // |pid| - self-explanatory. | |
| 100 // |ws_usage| - pointer to |WorkingSetKBytes| to fill; zero-ed on error. | |
| 101 // returns - |true| on success, |false| on error (including PID not found). | |
| 102 bool GetWorkingSetKBytesOfPID(int pid, | |
| 103 base::WorkingSetKBytes* ws_usage) const; | |
| 104 | |
| 105 // TODO(viettrungluu): Maybe we should also have the following (again, for | |
| 106 // "compatibility"): | |
| 107 // size_t GetWorkingSetSizeOfPID(int pid) const; | |
| 108 // size_t GetPeakWorkingSetSizeOfPID(int pid) const; | |
| 109 // size_t GetPrivateBytesOfPID(int pid) const; | |
| 110 | |
| 111 private: | |
| 112 // map from |int| (PID) to |ProcInfoEntry| | |
| 113 std::map<int,ProcInfoEntry> proc_info_entries_; | |
| 114 }; | |
| 115 | |
| 116 #endif // CHROME_BROWSER_PROCESS_INFO_SNAPSHOT_H_ | |
| OLD | NEW |