OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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_METRICS_METRICS_MEMORY_DETAILS_H_ |
| 6 #define CHROME_BROWSER_METRICS_METRICS_MEMORY_DETAILS_H_ |
| 7 |
| 8 #include <map> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "chrome/browser/memory_details.h" |
| 12 |
| 13 // MemoryGrowthTracker tracks latest metrics about record time and memory usage |
| 14 // at that time per process. |
| 15 class MemoryGrowthTracker { |
| 16 public: |
| 17 MemoryGrowthTracker(); |
| 18 ~MemoryGrowthTracker(); |
| 19 |
| 20 // If 30 minutes have passed since last UMA record, UpdateSample() computes |
| 21 // a difference between current memory usage |sample| of process |pid| and |
| 22 // stored memory usage at the time of last UMA record. Then, it updates the |
| 23 // stored memory usage to |sample|, stores the difference in |diff| and |
| 24 // returns true. |
| 25 // If no memory usage of |pid| has not been recorded so far or 30 minutes |
| 26 // have not passed since last record, it just returns false. |
| 27 // |sample| is memory usage in kB. |
| 28 bool UpdateSample(base::ProcessId pid, int sample, int* diff); |
| 29 |
| 30 private: |
| 31 // Latest metrics about record time and memory usage at that time per process. |
| 32 // The second values of |memory_sizes_| are in kB. |
| 33 std::map<base::ProcessId, base::TimeTicks> times_; |
| 34 std::map<base::ProcessId, int> memory_sizes_; |
| 35 |
| 36 DISALLOW_COPY_AND_ASSIGN(MemoryGrowthTracker); |
| 37 }; |
| 38 |
| 39 // Handles asynchronous fetching of memory details and logging histograms about |
| 40 // memory use of various processes. |
| 41 // Will run the provided callback when finished. |
| 42 class MetricsMemoryDetails : public MemoryDetails { |
| 43 public: |
| 44 MetricsMemoryDetails(const base::Closure& callback, |
| 45 MemoryGrowthTracker* memory_growth_tracker); |
| 46 |
| 47 protected: |
| 48 ~MetricsMemoryDetails() override; |
| 49 |
| 50 // MemoryDetails: |
| 51 void OnDetailsAvailable() override; |
| 52 |
| 53 private: |
| 54 // Updates the global histograms for tracking memory usage. |
| 55 void UpdateHistograms(); |
| 56 |
| 57 #if defined(OS_CHROMEOS) |
| 58 void UpdateSwapHistograms(); |
| 59 #endif |
| 60 |
| 61 base::Closure callback_; |
| 62 |
| 63 // A pointer to MemoryGrowthTracker which is contained in a longer-lived |
| 64 // owner of MetricsMemoryDetails, for example, ChromeMetricsServiceClient. |
| 65 // If it is null, nothing is tracked. |
| 66 MemoryGrowthTracker* memory_growth_tracker_; |
| 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails); |
| 69 }; |
| 70 |
| 71 #endif // CHROME_BROWSER_METRICS_METRICS_MEMORY_DETAILS_H_ |
OLD | NEW |