Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors |
Scott Graham | e160c7f | 2017-05-25 23:07:14 | [diff] [blame] | 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 "base/process/process_metrics.h" |
| 6 | |
Wez | 5c3c6f15 | 2018-06-09 18:24:02 | [diff] [blame] | 7 | #include <lib/fdio/limits.h> |
Fabrice de Gans | 4072fcf | 2021-08-20 21:35:29 | [diff] [blame] | 8 | #include <lib/zx/process.h> |
Wez | 148618c | 2018-02-08 05:56:13 | [diff] [blame] | 9 | |
Fabrice de Gans | 4072fcf | 2021-08-20 21:35:29 | [diff] [blame] | 10 | #include "base/fuchsia/fuchsia_logging.h" |
| 11 | #include "base/memory/ptr_util.h" |
Hans Wennborg | afeb390 | 2020-06-17 14:42:29 | [diff] [blame] | 12 | |
Scott Graham | e160c7f | 2017-05-25 23:07:14 | [diff] [blame] | 13 | namespace base { |
| 14 | |
Wez | 148618c | 2018-02-08 05:56:13 | [diff] [blame] | 15 | size_t GetMaxFds() { |
| 16 | return FDIO_MAX_FD; |
| 17 | } |
| 18 | |
Matthew Cary | 144069d | 2019-07-11 19:26:17 | [diff] [blame] | 19 | size_t GetHandleLimit() { |
| 20 | // Duplicated from the internal Magenta kernel constant kMaxHandleCount |
| 21 | // (zircon/kernel/object/handle.cc). |
| 22 | return 256 * 1024u; |
| 23 | } |
| 24 | |
Scott Graham | e160c7f | 2017-05-25 23:07:14 | [diff] [blame] | 25 | size_t GetSystemCommitCharge() { |
Wez | 2b2c80a | 2019-01-31 23:03:22 | [diff] [blame] | 26 | // TODO(https://crbug.com/926581): Fuchsia does not support this. |
Scott Graham | e160c7f | 2017-05-25 23:07:14 | [diff] [blame] | 27 | return 0; |
| 28 | } |
| 29 | |
Fabrice de Gans | 4072fcf | 2021-08-20 21:35:29 | [diff] [blame] | 30 | ProcessMetrics::ProcessMetrics(ProcessHandle process) : process_(process) {} |
| 31 | |
Scott Graham | 9e8c7cf | 2017-06-05 20:01:45 | [diff] [blame] | 32 | // static |
| 33 | std::unique_ptr<ProcessMetrics> ProcessMetrics::CreateProcessMetrics( |
| 34 | ProcessHandle process) { |
Fabrice de Gans | 4072fcf | 2021-08-20 21:35:29 | [diff] [blame] | 35 | return base::WrapUnique(new ProcessMetrics(process)); |
Scott Graham | 9e8c7cf | 2017-06-05 20:01:45 | [diff] [blame] | 36 | } |
| 37 | |
Sigurdur Asgeirsson | eb27eae7 | 2018-05-16 15:29:10 | [diff] [blame] | 38 | TimeDelta ProcessMetrics::GetCumulativeCPUUsage() { |
Fabrice de Gans | 4072fcf | 2021-08-20 21:35:29 | [diff] [blame] | 39 | zx_info_task_runtime_t stats; |
| 40 | |
| 41 | zx_status_t status = zx::unowned_process(process_)->get_info( |
| 42 | ZX_INFO_TASK_RUNTIME, &stats, sizeof(stats), nullptr, nullptr); |
| 43 | ZX_CHECK(status == ZX_OK, status); |
| 44 | |
| 45 | return TimeDelta::FromZxDuration(stats.cpu_time); |
Scott Graham | 9e8c7cf | 2017-06-05 20:01:45 | [diff] [blame] | 46 | } |
| 47 | |
Scott Graham | 61ea11e | 2017-08-18 20:22:15 | [diff] [blame] | 48 | bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { |
Wez | 6545074 | 2019-03-25 17:34:24 | [diff] [blame] | 49 | // TODO(https://crbug.com/926581). |
Scott Graham | 61ea11e | 2017-08-18 20:22:15 | [diff] [blame] | 50 | return false; |
| 51 | } |
| 52 | |
Scott Graham | 9e8c7cf | 2017-06-05 20:01:45 | [diff] [blame] | 53 | } // namespace base |