| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_MEMORY_DETAILS_H_ | 5 #ifndef CHROME_BROWSER_MEMORY_DETAILS_H_ |
| 6 #define CHROME_BROWSER_MEMORY_DETAILS_H_ | 6 #define CHROME_BROWSER_MEMORY_DETAILS_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 12 #include "base/process/process_handle.h" | 13 #include "base/process/process_handle.h" |
| 13 #include "base/process/process_metrics.h" | 14 #include "base/process/process_metrics.h" |
| 14 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 16 #include "chrome/browser/site_details.h" | 17 #include "chrome/browser/site_details.h" |
| 17 #include "content/public/common/process_type.h" | 18 #include "content/public/common/process_type.h" |
| 18 | 19 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 79 |
| 79 base::string16 name; | 80 base::string16 name; |
| 80 base::string16 process_name; | 81 base::string16 process_name; |
| 81 ProcessMemoryInformationList processes; | 82 ProcessMemoryInformationList processes; |
| 82 | 83 |
| 83 // Track site data for predicting process counts with out-of-process iframes. | 84 // Track site data for predicting process counts with out-of-process iframes. |
| 84 // See site_details.h. | 85 // See site_details.h. |
| 85 BrowserContextSiteDataMap site_data; | 86 BrowserContextSiteDataMap site_data; |
| 86 }; | 87 }; |
| 87 | 88 |
| 88 // MemoryGrowthTracker tracks latest metrics about record time and memory usage | |
| 89 // at that time per process. | |
| 90 class MemoryGrowthTracker { | |
| 91 public: | |
| 92 MemoryGrowthTracker(); | |
| 93 ~MemoryGrowthTracker(); | |
| 94 | |
| 95 // If 30 minutes have passed since last UMA record, UpdateSample() computes | |
| 96 // a difference between current memory usage |sample| of process |pid| and | |
| 97 // stored memory usage at the time of last UMA record. Then, it updates the | |
| 98 // stored memory usage to |sample|, stores the difference in |diff| and | |
| 99 // returns true. | |
| 100 // If no memory usage of |pid| has not been recorded so far or 30 minutes | |
| 101 // have not passed since last record, it just returns false. | |
| 102 // |sample| is memory usage in kB. | |
| 103 bool UpdateSample(base::ProcessId pid, int sample, int* diff); | |
| 104 | |
| 105 private: | |
| 106 // Latest metrics about record time and memory usage at that time per process. | |
| 107 // The second values of |memory_sizes_| are in kB. | |
| 108 std::map<base::ProcessId, base::TimeTicks> times_; | |
| 109 std::map<base::ProcessId, int> memory_sizes_; | |
| 110 | |
| 111 DISALLOW_COPY_AND_ASSIGN(MemoryGrowthTracker); | |
| 112 }; | |
| 113 | |
| 114 #if defined(OS_MACOSX) | 89 #if defined(OS_MACOSX) |
| 115 class ProcessInfoSnapshot; | 90 class ProcessInfoSnapshot; |
| 116 #endif | 91 #endif |
| 117 | 92 |
| 118 // MemoryDetails fetches memory details about current running browsers. | 93 // MemoryDetails fetches memory details about current running browsers. |
| 119 // Because this data can only be fetched asynchronously, callers use | 94 // Because this data can only be fetched asynchronously, callers use |
| 120 // this class via a callback. | 95 // this class via a callback. |
| 121 // | 96 // |
| 122 // Example usage: | 97 // Example usage: |
| 123 // | 98 // |
| (...skipping 25 matching lines...) Expand all Loading... |
| 149 | 124 |
| 150 // Constructor. | 125 // Constructor. |
| 151 MemoryDetails(); | 126 MemoryDetails(); |
| 152 | 127 |
| 153 // Access to the process detail information. This data is only available | 128 // Access to the process detail information. This data is only available |
| 154 // after OnDetailsAvailable() has been called. | 129 // after OnDetailsAvailable() has been called. |
| 155 const std::vector<ProcessData>& processes() { return process_data_; } | 130 const std::vector<ProcessData>& processes() { return process_data_; } |
| 156 | 131 |
| 157 // Initiate updating the current memory details. These are fetched | 132 // Initiate updating the current memory details. These are fetched |
| 158 // asynchronously because data must be collected from multiple threads. | 133 // asynchronously because data must be collected from multiple threads. |
| 159 // Updates UMA memory histograms if |mode| is UPDATE_USER_METRICS. | |
| 160 // OnDetailsAvailable will be called when this process is complete. | 134 // OnDetailsAvailable will be called when this process is complete. |
| 161 void StartFetch(UserMetricsMode user_metrics_mode); | 135 void StartFetch(); |
| 162 | 136 |
| 163 virtual void OnDetailsAvailable() = 0; | 137 virtual void OnDetailsAvailable() = 0; |
| 164 | 138 |
| 165 // Returns a string summarizing memory usage of the Chrome browser process | 139 // Returns a string summarizing memory usage of the Chrome browser process |
| 166 // and all sub-processes, suitable for logging. | 140 // and all sub-processes, suitable for logging. |
| 167 std::string ToLogString(); | 141 std::string ToLogString(); |
| 168 | 142 |
| 169 protected: | 143 protected: |
| 170 friend class base::RefCountedThreadSafe<MemoryDetails>; | 144 friend class base::RefCountedThreadSafe<MemoryDetails>; |
| 171 | 145 |
| 172 virtual ~MemoryDetails(); | 146 virtual ~MemoryDetails(); |
| 173 | 147 |
| 174 // Set MemoryGrowthTracker into MemoryDetails. | 148 // Returns a pointer to the ProcessData structure for Chrome. |
| 175 void SetMemoryGrowthTracker(MemoryGrowthTracker* memory_growth_tracker); | 149 ProcessData* ChromeBrowser(); |
| 150 |
| 151 #if defined(OS_CHROMEOS) |
| 152 const base::SwapInfo& swap_info() const { return swap_info_; } |
| 153 #endif |
| 176 | 154 |
| 177 private: | 155 private: |
| 178 // Collect child process information on the IO thread. This is needed because | 156 // Collect child process information on the IO thread. This is needed because |
| 179 // information about some child process types (i.e. plugins) can only be taken | 157 // information about some child process types (i.e. plugins) can only be taken |
| 180 // on that thread. The data will be used by about:memory. When finished, | 158 // on that thread. The data will be used by about:memory. When finished, |
| 181 // invokes back to the file thread to run the rest of the about:memory | 159 // invokes back to the file thread to run the rest of the about:memory |
| 182 // functionality. | 160 // functionality. |
| 183 void CollectChildInfoOnIOThread(); | 161 void CollectChildInfoOnIOThread(); |
| 184 | 162 |
| 185 // Collect current process information from the OS and store it | 163 // Collect current process information from the OS and store it |
| (...skipping 11 matching lines...) Expand all Loading... |
| 197 void CollectProcessDataChrome( | 175 void CollectProcessDataChrome( |
| 198 const std::vector<ProcessMemoryInformation>& child_info, | 176 const std::vector<ProcessMemoryInformation>& child_info, |
| 199 base::ProcessId pid, | 177 base::ProcessId pid, |
| 200 const ProcessInfoSnapshot& process_info); | 178 const ProcessInfoSnapshot& process_info); |
| 201 #endif | 179 #endif |
| 202 | 180 |
| 203 // Collect child process information on the UI thread. Information about | 181 // Collect child process information on the UI thread. Information about |
| 204 // renderer processes is only available there. | 182 // renderer processes is only available there. |
| 205 void CollectChildInfoOnUIThread(); | 183 void CollectChildInfoOnUIThread(); |
| 206 | 184 |
| 207 // Updates the global histograms for tracking memory usage. | |
| 208 void UpdateHistograms(); | |
| 209 | |
| 210 #if defined(OS_CHROMEOS) | |
| 211 void UpdateSwapHistograms(); | |
| 212 #endif | |
| 213 | |
| 214 // Returns a pointer to the ProcessData structure for Chrome. | |
| 215 ProcessData* ChromeBrowser(); | |
| 216 | |
| 217 std::vector<ProcessData> process_data_; | 185 std::vector<ProcessData> process_data_; |
| 218 | 186 |
| 219 UserMetricsMode user_metrics_mode_; | |
| 220 | |
| 221 // A pointer to MemoryGrowthTracker which is contained in a longer-lived | |
| 222 // owner of MemoryDetails, for example, ChromeMetricsServiceClient. | |
| 223 // The pointer is NULL by default and set by SetMemoryGrowthTracker(). | |
| 224 // If it is NULL, nothing is tracked. | |
| 225 MemoryGrowthTracker* memory_growth_tracker_; | |
| 226 | |
| 227 #if defined(OS_CHROMEOS) | 187 #if defined(OS_CHROMEOS) |
| 228 base::SwapInfo swap_info_; | 188 base::SwapInfo swap_info_; |
| 229 #endif | 189 #endif |
| 230 | 190 |
| 231 DISALLOW_COPY_AND_ASSIGN(MemoryDetails); | 191 DISALLOW_COPY_AND_ASSIGN(MemoryDetails); |
| 232 }; | 192 }; |
| 233 | 193 |
| 234 #endif // CHROME_BROWSER_MEMORY_DETAILS_H_ | 194 #endif // CHROME_BROWSER_MEMORY_DETAILS_H_ |
| OLD | NEW |