| 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 <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 // } | 105 // } |
| 106 // | 106 // |
| 107 // // Your other class stuff here | 107 // // Your other class stuff here |
| 108 // | 108 // |
| 109 // virtual void OnDetailsAvailable() { | 109 // virtual void OnDetailsAvailable() { |
| 110 // // do work with memory info here | 110 // // do work with memory info here |
| 111 // } | 111 // } |
| 112 // } | 112 // } |
| 113 class MemoryDetails : public base::RefCountedThreadSafe<MemoryDetails> { | 113 class MemoryDetails : public base::RefCountedThreadSafe<MemoryDetails> { |
| 114 public: | 114 public: |
| 115 enum CollectionMode { | |
| 116 // Collect metrics from Chrome and other running browsers. | |
| 117 FROM_ALL_BROWSERS, | |
| 118 // Collect metrics from Chrome processes only. | |
| 119 FROM_CHROME_ONLY | |
| 120 }; | |
| 121 | |
| 122 // Constructor. | 115 // Constructor. |
| 123 MemoryDetails(); | 116 MemoryDetails(); |
| 124 | 117 |
| 125 // Initiate updating the current memory details (based on |mode|). These are | 118 // Initiate updating the current memory details. These are fetched |
| 126 // fetched asynchronously because data must be collected from multiple | 119 // asynchronously because data must be collected from multiple threads. |
| 127 // threads. OnDetailsAvailable will be called when this process is complete. | 120 // OnDetailsAvailable will be called when this process is complete. |
| 128 void StartFetch(CollectionMode mode); | 121 void StartFetch(); |
| 129 | 122 |
| 130 virtual void OnDetailsAvailable() = 0; | 123 virtual void OnDetailsAvailable() = 0; |
| 131 | 124 |
| 132 // Returns a string summarizing memory usage of the Chrome browser process | 125 // Returns a string summarizing memory usage of the Chrome browser process |
| 133 // and all sub-processes, suitable for logging. | 126 // and all sub-processes, suitable for logging. |
| 134 std::string ToLogString(); | 127 std::string ToLogString(); |
| 135 | 128 |
| 136 protected: | 129 protected: |
| 137 friend class base::RefCountedThreadSafe<MemoryDetails>; | 130 friend class base::RefCountedThreadSafe<MemoryDetails>; |
| 138 | 131 |
| 139 virtual ~MemoryDetails(); | 132 virtual ~MemoryDetails(); |
| 140 | 133 |
| 141 // Access to the process detail information. This data is only available | 134 // Access to the process detail information. This data is only available |
| 142 // after OnDetailsAvailable() has been called. | 135 // after OnDetailsAvailable() has been called. |
| 143 const std::vector<ProcessData>& processes() { return process_data_; } | 136 const std::vector<ProcessData>& processes() { return process_data_; } |
| 144 | 137 |
| 145 // Returns a pointer to the ProcessData structure for Chrome. | 138 // Returns a pointer to the ProcessData structure for Chrome. |
| 146 ProcessData* ChromeBrowser(); | 139 ProcessData* ChromeBrowser(); |
| 147 | 140 |
| 148 #if defined(OS_CHROMEOS) | 141 #if defined(OS_CHROMEOS) |
| 149 const base::SwapInfo& swap_info() const { return swap_info_; } | 142 const base::SwapInfo& swap_info() const { return swap_info_; } |
| 150 #endif | 143 #endif |
| 151 | 144 |
| 152 private: | 145 private: |
| 153 // Collect child process information on the IO thread. This is needed because | 146 // Collect child process information on the IO thread. This is needed because |
| 154 // information about some child process types (i.e. plugins) can only be taken | 147 // information about some child process types (i.e. plugins) can only be taken |
| 155 // on that thread. The data will be used by about:memory. When finished, | 148 // on that thread. The data will be used by about:memory. When finished, |
| 156 // invokes back to the file thread to run the rest of the about:memory | 149 // invokes back to the file thread to run the rest of the about:memory |
| 157 // functionality. | 150 // functionality. |
| 158 void CollectChildInfoOnIOThread(CollectionMode mode); | 151 void CollectChildInfoOnIOThread(); |
| 159 | 152 |
| 160 // Collect current process information from the OS and store it | 153 // Collect current process information from the OS and store it |
| 161 // for processing. If data has already been collected, clears old | 154 // for processing. If data has already been collected, clears old |
| 162 // data and re-collects the data. | 155 // data and re-collects the data. |
| 163 // Note - this function enumerates memory details from many processes | 156 // Note - this function enumerates memory details from many processes |
| 164 // and is fairly expensive to run, hence it's run on the blocking pool. | 157 // and is fairly expensive to run, hence it's run on the blocking pool. |
| 165 // The parameter holds information about processes from the IO thread. | 158 // The parameter holds information about processes from the IO thread. |
| 166 void CollectProcessData( | 159 void CollectProcessData( |
| 167 CollectionMode mode, | |
| 168 const std::vector<ProcessMemoryInformation>& child_info); | 160 const std::vector<ProcessMemoryInformation>& child_info); |
| 169 | 161 |
| 170 // Collect child process information on the UI thread. Information about | 162 // Collect child process information on the UI thread. Information about |
| 171 // renderer processes is only available there. | 163 // renderer processes is only available there. |
| 172 void CollectChildInfoOnUIThread(); | 164 void CollectChildInfoOnUIThread(); |
| 173 | 165 |
| 174 std::vector<ProcessData> process_data_; | 166 std::vector<ProcessData> process_data_; |
| 175 | 167 |
| 176 #if defined(OS_CHROMEOS) | 168 #if defined(OS_CHROMEOS) |
| 177 base::SwapInfo swap_info_; | 169 base::SwapInfo swap_info_; |
| 178 #endif | 170 #endif |
| 179 | 171 |
| 180 DISALLOW_COPY_AND_ASSIGN(MemoryDetails); | 172 DISALLOW_COPY_AND_ASSIGN(MemoryDetails); |
| 181 }; | 173 }; |
| 182 | 174 |
| 183 #endif // CHROME_BROWSER_MEMORY_DETAILS_H_ | 175 #endif // CHROME_BROWSER_MEMORY_DETAILS_H_ |
| OLD | NEW |