Chromium Code Reviews| Index: content/browser/memory/swap_metrics_observer_linux.cc |
| diff --git a/content/browser/memory/swap_metrics_observer_linux.cc b/content/browser/memory/swap_metrics_observer_linux.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..51259a8631a0978b075e887df2f02c9f18d6484f |
| --- /dev/null |
| +++ b/content/browser/memory/swap_metrics_observer_linux.cc |
| @@ -0,0 +1,51 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/memory/swap_metrics_observer_linux.h" |
| + |
| +#include "base/metrics/histogram_macros.h" |
| +#include "base/process/process_metrics.h" |
| + |
| +namespace content { |
| + |
| +// static |
| +SwapMetricsObserver* SwapMetricsObserver::GetInstance() { |
| + return SwapMetricsObserverLinux::GetInstance(); |
| +} |
| + |
| +// static |
| +SwapMetricsObserverLinux* SwapMetricsObserverLinux::GetInstance() { |
| + return base::Singleton< |
|
Primiano Tucci (use gerrit)
2017/04/27 10:01:20
IWYU (+base/singleton.h).
BTW these days you can j
bashi
2017/04/28 02:05:35
Changed to use static local. Thanks for the info!
|
| + SwapMetricsObserverLinux, |
| + base::LeakySingletonTraits<SwapMetricsObserverLinux>>::get(); |
| +} |
| + |
| +SwapMetricsObserverLinux::SwapMetricsObserverLinux() {} |
| + |
| +SwapMetricsObserverLinux::~SwapMetricsObserverLinux() {} |
| + |
| +void SwapMetricsObserverLinux::UpdateMetricsInternal(base::TimeDelta interval) { |
| + base::SystemMemoryInfoKB memory_info; |
| + if (!base::GetSystemMemoryInfo(&memory_info)) |
| + return; |
| + |
| + // Don't record metrics when the system doesn't seem to have swap. |
| + if (memory_info.pswpin == 0) |
| + return; |
|
Primiano Tucci (use gerrit)
2017/04/27 10:01:20
maybe also stop the timer in these failure cases?
bashi
2017/04/28 02:05:35
Yes. Probably we shouldn't start the timer in the
|
| + |
| + double in_counts = memory_info.pswpin - last_pswpin_; |
| + double out_counts = memory_info.pswpout - last_pswpout_; |
| + last_pswpin_ = memory_info.pswpin; |
| + last_pswpout_ = memory_info.pswpout; |
| + |
| + if (interval.is_zero()) |
| + return; |
| + |
| + UMA_HISTOGRAM_COUNTS_10000("Memory.Experimental.SwapInPerSecond", |
| + in_counts / interval.InSecondsF()); |
| + UMA_HISTOGRAM_COUNTS_10000("Memory.Experimental.SwapOutPerSecond", |
| + out_counts / interval.InSecondsF()); |
| +} |
| + |
| +} // namespace content |