Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
|
Devlin
2013/09/12 00:44:47
nit: no (c)
| |
| 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_PERFORMANCE_MONITOR_PROCESS_METRICS_HISTORY_H_ | |
| 6 #define CHROME_BROWSER_PERFORMANCE_MONITOR_PROCESS_METRICS_HISTORY_H_ | |
| 7 | |
| 8 #include "base/memory/linked_ptr.h" | |
| 9 #include "base/process/process_handle.h" | |
| 10 | |
| 11 namespace base { | |
| 12 class ProcessMetrics; | |
| 13 } | |
| 14 | |
| 15 namespace performance_monitor { | |
| 16 | |
| 17 class ProcessMetricsHistory { | |
| 18 public: | |
| 19 ProcessMetricsHistory(); | |
| 20 ~ProcessMetricsHistory(); | |
| 21 | |
| 22 // Configure this to monitor a specific process. | |
| 23 void Initialize(base::ProcessHandle process_handle, | |
| 24 int process_type, | |
| 25 int initial_update_sequence); | |
| 26 | |
| 27 // End of a measurement cycle; check for performance issues and reset | |
| 28 // accumulated statistics. | |
| 29 void EndOfCycle(); | |
| 30 | |
| 31 // Gather metrics for the process and accumulate with past data. | |
| 32 void SampleMetrics(); | |
| 33 | |
| 34 // Used to mark when this object was last updated, so we can cull | |
| 35 // dead ones. | |
| 36 void SetLastUpdateSequence(int new_update_sequence) { | |
|
Devlin
2013/09/12 00:44:47
for functions that don't do (real) work, prefer un
oystein (OOO til 10th of July)
2013/09/12 15:02:31
Done.
| |
| 37 last_update_sequence_ = new_update_sequence; | |
| 38 } | |
| 39 | |
| 40 int GetLastUpdateSequence() const { return last_update_sequence_; } | |
|
Devlin
2013/09/12 00:44:47
unix_hacker_style - "last_updated_sequence()"
oystein (OOO til 10th of July)
2013/09/12 15:02:31
Done.
| |
| 41 | |
| 42 // Average CPU over all the past sampling points since last reset. | |
| 43 double GetAverageCPUUsage() { return accumulated_cpu_usage_ / sample_count_; } | |
| 44 | |
| 45 // // Average mem usage over all the past sampling points since last reset. | |
|
Devlin
2013/09/12 00:44:47
double comment?
oystein (OOO til 10th of July)
2013/09/12 15:02:31
Done.
| |
| 46 void GetAverageMemoryBytes(size_t* private_bytes, size_t* shared_bytes) { | |
| 47 *private_bytes = accumulated_private_bytes_ / sample_count_; | |
| 48 *shared_bytes = accumulated_shared_bytes_ / sample_count_; | |
| 49 } | |
| 50 | |
| 51 private: | |
| 52 void ResetCounters(); | |
| 53 void RunPerformanceTriggers(); | |
| 54 | |
| 55 base::ProcessHandle process_handle_; | |
| 56 int process_type_; | |
| 57 linked_ptr<base::ProcessMetrics> process_metrics_; | |
| 58 int last_update_sequence_; | |
| 59 | |
| 60 double accumulated_cpu_usage_; | |
| 61 double min_cpu_usage_; | |
| 62 size_t accumulated_private_bytes_; | |
| 63 size_t accumulated_shared_bytes_; | |
| 64 int sample_count_; | |
| 65 }; | |
| 66 | |
| 67 } // namespace performance_monitor | |
| 68 | |
| 69 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PROCESS_METRICS_HISTORY_H_ | |
| OLD | NEW |