OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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_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 set_last_update_sequence(int new_update_sequence) { |
| 37 last_update_sequence_ = new_update_sequence; |
| 38 } |
| 39 |
| 40 int last_update_sequence() const { return last_update_sequence_; } |
| 41 |
| 42 // Average CPU over all the past sampling points since last reset. |
| 43 double GetAverageCPUUsage() const { |
| 44 return accumulated_cpu_usage_ / sample_count_; |
| 45 } |
| 46 |
| 47 // Average mem usage over all the past sampling points since last reset. |
| 48 void GetAverageMemoryBytes(size_t* private_bytes, |
| 49 size_t* shared_bytes) const { |
| 50 *private_bytes = accumulated_private_bytes_ / sample_count_; |
| 51 *shared_bytes = accumulated_shared_bytes_ / sample_count_; |
| 52 } |
| 53 |
| 54 private: |
| 55 void ResetCounters(); |
| 56 void RunPerformanceTriggers(); |
| 57 |
| 58 base::ProcessHandle process_handle_; |
| 59 int process_type_; |
| 60 linked_ptr<base::ProcessMetrics> process_metrics_; |
| 61 int last_update_sequence_; |
| 62 |
| 63 double accumulated_cpu_usage_; |
| 64 double min_cpu_usage_; |
| 65 size_t accumulated_private_bytes_; |
| 66 size_t accumulated_shared_bytes_; |
| 67 int sample_count_; |
| 68 }; |
| 69 |
| 70 } // namespace performance_monitor |
| 71 |
| 72 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PROCESS_METRICS_HISTORY_H_ |
OLD | NEW |