OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/memory/swap_metrics_observer.h" | 5 #include "content/browser/memory/swap_metrics_observer_mac.h" |
| 6 |
| 7 #include <mach/mach.h> |
| 8 #include <mach/mach_vm.h> |
| 9 |
| 10 #include "base/mac/mach_logging.h" |
| 11 #include "base/metrics/histogram_macros.h" |
6 | 12 |
7 namespace content { | 13 namespace content { |
8 | 14 |
9 // static | 15 // static |
10 SwapMetricsObserver* SwapMetricsObserver::GetInstance() { | 16 SwapMetricsObserver* SwapMetricsObserver::GetInstance() { |
11 // TODO(bashi): Implement SwapMetricsObserver for macOS. | 17 static SwapMetricsObserverMac* instance = new SwapMetricsObserverMac(); |
12 return nullptr; | 18 return instance; |
| 19 } |
| 20 |
| 21 SwapMetricsObserverMac::SwapMetricsObserverMac() : host_(mach_host_self()) {} |
| 22 |
| 23 SwapMetricsObserverMac::~SwapMetricsObserverMac() {} |
| 24 |
| 25 void SwapMetricsObserverMac::UpdateMetricsInternal(base::TimeDelta interval) { |
| 26 vm_statistics64_data_t statistics; |
| 27 mach_msg_type_number_t count = HOST_VM_INFO64_COUNT; |
| 28 kern_return_t result = |
| 29 host_statistics64(host_.get(), HOST_VM_INFO64, |
| 30 reinterpret_cast<host_info64_t>(&statistics), &count); |
| 31 if (result != KERN_SUCCESS) { |
| 32 MACH_DLOG(WARNING, result) << "host_statistics64"; |
| 33 Stop(); |
| 34 return; |
| 35 } |
| 36 DCHECK_EQ(HOST_VM_INFO64_COUNT, count); |
| 37 |
| 38 double swapins = statistics.swapins - last_swapins_; |
| 39 double swapouts = statistics.swapouts - last_swapouts_; |
| 40 double decompressions = statistics.decompressions - last_decompressions_; |
| 41 double compressions = statistics.compressions - last_compressions_; |
| 42 last_swapins_ = statistics.swapins; |
| 43 last_swapouts_ = statistics.swapouts; |
| 44 last_decompressions_ = statistics.decompressions; |
| 45 last_compressions_ = statistics.compressions; |
| 46 |
| 47 if (interval.is_zero()) |
| 48 return; |
| 49 |
| 50 UMA_HISTOGRAM_COUNTS_10000("Memory.Experimental.SwapInPerSecond", |
| 51 swapins / interval.InSecondsF()); |
| 52 UMA_HISTOGRAM_COUNTS_10000("Memory.Experimental.SwapOutPerSecond", |
| 53 swapouts / interval.InSecondsF()); |
| 54 UMA_HISTOGRAM_COUNTS_10000("Memory.Experimental.DecompressedPagesPerSecond", |
| 55 decompressions / interval.InSecondsF()); |
| 56 UMA_HISTOGRAM_COUNTS_10000("Memory.Experimental.CompressedPagesPerSecond", |
| 57 compressions / interval.InSecondsF()); |
13 } | 58 } |
14 | 59 |
15 } // namespace content | 60 } // namespace content |
OLD | NEW |