Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / performance_monitor / process_metrics_history.h
blob8837e1faccec4433bc6563e3ff0d583cbbdf553a
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.
5 #ifndef CHROME_BROWSER_PERFORMANCE_MONITOR_PROCESS_METRICS_HISTORY_H_
6 #define CHROME_BROWSER_PERFORMANCE_MONITOR_PROCESS_METRICS_HISTORY_H_
8 #include "base/memory/linked_ptr.h"
9 #include "base/process/process_handle.h"
11 namespace base {
12 class ProcessMetrics;
15 namespace performance_monitor {
17 class ProcessMetricsHistory {
18 public:
19 ProcessMetricsHistory();
20 ~ProcessMetricsHistory();
22 // Configure this to monitor a specific process.
23 void Initialize(base::ProcessHandle process_handle,
24 int process_type,
25 int initial_update_sequence);
27 // End of a measurement cycle; check for performance issues and reset
28 // accumulated statistics.
29 void EndOfCycle();
31 // Gather metrics for the process and accumulate with past data.
32 void SampleMetrics();
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;
40 int last_update_sequence() const { return last_update_sequence_; }
42 // Average CPU over all the past sampling points since last reset.
43 double GetAverageCPUUsage() const {
44 return accumulated_cpu_usage_ / sample_count_;
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_;
54 private:
55 void ResetCounters();
56 void RunPerformanceTriggers();
58 base::ProcessHandle process_handle_;
59 int process_type_;
60 linked_ptr<base::ProcessMetrics> process_metrics_;
61 int last_update_sequence_;
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_;
70 } // namespace performance_monitor
72 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PROCESS_METRICS_HISTORY_H_