[go: nahoru, domu]

blob: 75bedb432f183c0feb691d092b4a961a2a7426a4 [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2017 The Chromium Authors
Scott Grahame160c7f2017-05-25 23:07:142// 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
Wez5c3c6f152018-06-09 18:24:027#include <lib/fdio/limits.h>
Fabrice de Gans4072fcf2021-08-20 21:35:298#include <lib/zx/process.h>
Wez148618c2018-02-08 05:56:139
Fabrice de Gans4072fcf2021-08-20 21:35:2910#include "base/fuchsia/fuchsia_logging.h"
11#include "base/memory/ptr_util.h"
Hans Wennborgafeb3902020-06-17 14:42:2912
Scott Grahame160c7f2017-05-25 23:07:1413namespace base {
14
Wez148618c2018-02-08 05:56:1315size_t GetMaxFds() {
16 return FDIO_MAX_FD;
17}
18
Matthew Cary144069d2019-07-11 19:26:1719size_t GetHandleLimit() {
20 // Duplicated from the internal Magenta kernel constant kMaxHandleCount
21 // (zircon/kernel/object/handle.cc).
22 return 256 * 1024u;
23}
24
Scott Grahame160c7f2017-05-25 23:07:1425size_t GetSystemCommitCharge() {
Wez2b2c80a2019-01-31 23:03:2226 // TODO(https://crbug.com/926581): Fuchsia does not support this.
Scott Grahame160c7f2017-05-25 23:07:1427 return 0;
28}
29
Fabrice de Gans4072fcf2021-08-20 21:35:2930ProcessMetrics::ProcessMetrics(ProcessHandle process) : process_(process) {}
31
Scott Graham9e8c7cf2017-06-05 20:01:4532// static
33std::unique_ptr<ProcessMetrics> ProcessMetrics::CreateProcessMetrics(
34 ProcessHandle process) {
Fabrice de Gans4072fcf2021-08-20 21:35:2935 return base::WrapUnique(new ProcessMetrics(process));
Scott Graham9e8c7cf2017-06-05 20:01:4536}
37
Sigurdur Asgeirssoneb27eae72018-05-16 15:29:1038TimeDelta ProcessMetrics::GetCumulativeCPUUsage() {
Fabrice de Gans4072fcf2021-08-20 21:35:2939 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 Graham9e8c7cf2017-06-05 20:01:4546}
47
Scott Graham61ea11e2017-08-18 20:22:1548bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) {
Wez65450742019-03-25 17:34:2449 // TODO(https://crbug.com/926581).
Scott Graham61ea11e2017-08-18 20:22:1550 return false;
51}
52
Scott Graham9e8c7cf2017-06-05 20:01:4553} // namespace base