Chromium Code Reviews| 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 | |
|
Ilya Sherman
2015/01/16 04:57:36
Why 30 minutes? Is it too expensive to compute on
Alexei Svitkine (slow)
2015/01/16 16:07:50
I'm not changing this - this is just moving from t
| |
| 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. | |
| 40 // Will run the provided task after finished. | |
| 41 class MetricsMemoryDetails : public MemoryDetails { | |
| 42 public: | |
| 43 MetricsMemoryDetails(const base::Closure& callback, | |
| 44 MemoryGrowthTracker* memory_growth_tracker); | |
| 45 | |
| 46 protected: | |
| 47 ~MetricsMemoryDetails() override; | |
| 48 | |
| 49 // MemoryDetails: | |
| 50 void OnDetailsAvailable() override; | |
| 51 | |
| 52 private: | |
| 53 // Updates the global histograms for tracking memory usage. | |
| 54 void UpdateHistograms(); | |
| 55 | |
| 56 #if defined(OS_CHROMEOS) | |
| 57 void UpdateSwapHistograms(); | |
| 58 #endif | |
| 59 | |
| 60 base::Closure callback_; | |
| 61 | |
| 62 // A pointer to MemoryGrowthTracker which is contained in a longer-lived | |
| 63 // owner of MemoryDetails, for example, ChromeMetricsServiceClient. | |
| 64 // The pointer is NULL by default and set by SetMemoryGrowthTracker(). | |
| 65 // If it is NULL, nothing is tracked. | |
|
Ilya Sherman
2015/01/16 04:57:36
Please update this comment -- there's no longer a
Alexei Svitkine (slow)
2015/01/16 16:07:50
Done.
| |
| 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 |