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()15size_t GetMaxFds() { 16 return FDIO_MAX_FD; 17 } 18 GetHandleLimit()19size_t GetHandleLimit() { 20 // Duplicated from the internal Magenta kernel constant kMaxHandleCount 21 // (zircon/kernel/object/handle.cc). 22 return 256 * 1024u; 23 } 24 GetSystemCommitCharge()25size_t GetSystemCommitCharge() { 26 // TODO(https://crbug.com/926581): Fuchsia does not support this. 27 return 0; 28 } 29 ProcessMetrics(ProcessHandle process)30ProcessMetrics::ProcessMetrics(ProcessHandle process) : process_(process) {} 31 32 // static CreateProcessMetrics(ProcessHandle process)33std::unique_ptr<ProcessMetrics> ProcessMetrics::CreateProcessMetrics( 34 ProcessHandle process) { 35 return base::WrapUnique(new ProcessMetrics(process)); 36 } 37 38 base::expected<TimeDelta, ProcessCPUUsageError> GetCumulativeCPUUsage()39ProcessMetrics::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)51bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { 52 // TODO(https://crbug.com/926581). 53 return false; 54 } 55 56 } // namespace base 57