xref: /aosp_15_r20/external/cronet/base/process/process_metrics_fuchsia.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2017 The Chromium Authors
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 
7 #include <lib/fdio/limits.h>
8 #include <lib/zx/process.h>
9 
10 #include "base/fuchsia/fuchsia_logging.h"
11 #include "base/memory/ptr_util.h"
12 
13 namespace base {
14 
GetMaxFds()15 size_t GetMaxFds() {
16   return FDIO_MAX_FD;
17 }
18 
GetHandleLimit()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 
GetSystemCommitCharge()25 size_t GetSystemCommitCharge() {
26   // TODO(https://crbug.com/926581): Fuchsia does not support this.
27   return 0;
28 }
29 
ProcessMetrics(ProcessHandle process)30 ProcessMetrics::ProcessMetrics(ProcessHandle process) : process_(process) {}
31 
32 // static
CreateProcessMetrics(ProcessHandle process)33 std::unique_ptr<ProcessMetrics> ProcessMetrics::CreateProcessMetrics(
34     ProcessHandle process) {
35   return base::WrapUnique(new ProcessMetrics(process));
36 }
37 
38 base::expected<TimeDelta, ProcessCPUUsageError>
GetCumulativeCPUUsage()39 ProcessMetrics::GetCumulativeCPUUsage() {
40   zx_info_task_runtime_t stats;
41 
42   zx_status_t status = zx::unowned_process(process_)->get_info(
43       ZX_INFO_TASK_RUNTIME, &stats, sizeof(stats), nullptr, nullptr);
44   if (status != ZX_OK) {
45     return base::unexpected(ProcessCPUUsageError::kSystemError);
46   }
47 
48   return base::ok(TimeDelta::FromZxDuration(stats.cpu_time));
49 }
50 
GetSystemMemoryInfo(SystemMemoryInfoKB * meminfo)51 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) {
52   // TODO(https://crbug.com/926581).
53   return false;
54 }
55 
56 }  // namespace base
57