process_metrics_fuchsia.cc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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
  3. // found in the LICENSE file.
  4. #include "base/process/process_metrics.h"
  5. #include <lib/fdio/limits.h>
  6. #include <lib/zx/process.h>
  7. #include "base/fuchsia/fuchsia_logging.h"
  8. #include "base/memory/ptr_util.h"
  9. namespace base {
  10. size_t GetMaxFds() {
  11. return FDIO_MAX_FD;
  12. }
  13. size_t GetHandleLimit() {
  14. // Duplicated from the internal Magenta kernel constant kMaxHandleCount
  15. // (zircon/kernel/object/handle.cc).
  16. return 256 * 1024u;
  17. }
  18. size_t GetSystemCommitCharge() {
  19. // TODO(https://crbug.com/926581): Fuchsia does not support this.
  20. return 0;
  21. }
  22. ProcessMetrics::ProcessMetrics(ProcessHandle process) : process_(process) {}
  23. // static
  24. std::unique_ptr<ProcessMetrics> ProcessMetrics::CreateProcessMetrics(
  25. ProcessHandle process) {
  26. return base::WrapUnique(new ProcessMetrics(process));
  27. }
  28. TimeDelta ProcessMetrics::GetCumulativeCPUUsage() {
  29. zx_info_task_runtime_t stats;
  30. zx_status_t status = zx::unowned_process(process_)->get_info(
  31. ZX_INFO_TASK_RUNTIME, &stats, sizeof(stats), nullptr, nullptr);
  32. ZX_CHECK(status == ZX_OK, status);
  33. return TimeDelta::FromZxDuration(stats.cpu_time);
  34. }
  35. bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) {
  36. // TODO(https://crbug.com/926581).
  37. return false;
  38. }
  39. } // namespace base