OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 #include "content/browser/memory/swap_metrics_observer_linux.h" |
| 6 |
| 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "base/process/process_metrics.h" |
| 9 |
| 10 namespace content { |
| 11 |
| 12 namespace { |
| 13 |
| 14 bool HasSwap() { |
| 15 base::SystemMemoryInfoKB memory_info; |
| 16 if (!base::GetSystemMemoryInfo(&memory_info)) |
| 17 return false; |
| 18 return memory_info.swap_total > 0; |
| 19 } |
| 20 |
| 21 } // namespace |
| 22 |
| 23 // static |
| 24 SwapMetricsObserver* SwapMetricsObserver::GetInstance() { |
| 25 static SwapMetricsObserverLinux* instance = |
| 26 HasSwap() ? new SwapMetricsObserverLinux() : nullptr; |
| 27 return instance; |
| 28 } |
| 29 |
| 30 SwapMetricsObserverLinux::SwapMetricsObserverLinux() {} |
| 31 |
| 32 SwapMetricsObserverLinux::~SwapMetricsObserverLinux() {} |
| 33 |
| 34 void SwapMetricsObserverLinux::UpdateMetricsInternal(base::TimeDelta interval) { |
| 35 base::SystemMemoryInfoKB memory_info; |
| 36 if (!base::GetSystemMemoryInfo(&memory_info)) { |
| 37 Stop(); |
| 38 return; |
| 39 } |
| 40 |
| 41 double in_counts = memory_info.pswpin - last_pswpin_; |
| 42 double out_counts = memory_info.pswpout - last_pswpout_; |
| 43 last_pswpin_ = memory_info.pswpin; |
| 44 last_pswpout_ = memory_info.pswpout; |
| 45 |
| 46 if (interval.is_zero()) |
| 47 return; |
| 48 |
| 49 UMA_HISTOGRAM_COUNTS_10000("Memory.Experimental.SwapInPerSecond", |
| 50 in_counts / interval.InSecondsF()); |
| 51 UMA_HISTOGRAM_COUNTS_10000("Memory.Experimental.SwapOutPerSecond", |
| 52 out_counts / interval.InSecondsF()); |
| 53 } |
| 54 |
| 55 } // namespace content |
OLD | NEW |