Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / metrics / metrics_memory_details.h
blobcee946f81174d0920f7454dddcca24200fe0ec17
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.
5 #ifndef CHROME_BROWSER_METRICS_METRICS_MEMORY_DETAILS_H_
6 #define CHROME_BROWSER_METRICS_METRICS_MEMORY_DETAILS_H_
8 #include <map>
10 #include "base/callback.h"
11 #include "chrome/browser/memory_details.h"
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();
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);
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_;
36 DISALLOW_COPY_AND_ASSIGN(MemoryGrowthTracker);
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);
47 protected:
48 ~MetricsMemoryDetails() override;
50 // MemoryDetails:
51 void OnDetailsAvailable() override;
53 private:
54 // Updates the global histograms for tracking memory usage.
55 void UpdateHistograms();
57 #if defined(OS_CHROMEOS)
58 void UpdateSwapHistograms();
59 #endif
61 base::Closure callback_;
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_;
68 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails);
71 #endif // CHROME_BROWSER_METRICS_METRICS_MEMORY_DETAILS_H_