Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Unified Diff: base/process/process_metrics_openbsd.cc

Issue 1647803004: Move base to DEPS (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/process/process_metrics_mac.cc ('k') | base/process/process_metrics_posix.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process/process_metrics_openbsd.cc
diff --git a/base/process/process_metrics_openbsd.cc b/base/process/process_metrics_openbsd.cc
deleted file mode 100644
index 72927a1b5786b5d3246328fe4c09e31eeaae8ba0..0000000000000000000000000000000000000000
--- a/base/process/process_metrics_openbsd.cc
+++ /dev/null
@@ -1,161 +0,0 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/process/process_metrics.h"
-
-#include <sys/param.h>
-#include <sys/sysctl.h>
-
-namespace base {
-
-// static
-ProcessMetrics* ProcessMetrics::CreateProcessMetrics(ProcessHandle process) {
- return new ProcessMetrics(process);
-}
-
-size_t ProcessMetrics::GetPagefileUsage() const {
- struct kinfo_proc info;
- size_t length;
- int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, process_,
- sizeof(struct kinfo_proc), 0 };
-
- if (sysctl(mib, arraysize(mib), NULL, &length, NULL, 0) < 0)
- return -1;
-
- mib[5] = (length / sizeof(struct kinfo_proc));
-
- if (sysctl(mib, arraysize(mib), &info, &length, NULL, 0) < 0)
- return -1;
-
- return (info.p_vm_tsize + info.p_vm_dsize + info.p_vm_ssize);
-}
-
-size_t ProcessMetrics::GetPeakPagefileUsage() const {
- return 0;
-}
-
-size_t ProcessMetrics::GetWorkingSetSize() const {
- struct kinfo_proc info;
- size_t length;
- int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, process_,
- sizeof(struct kinfo_proc), 0 };
-
- if (sysctl(mib, arraysize(mib), NULL, &length, NULL, 0) < 0)
- return -1;
-
- mib[5] = (length / sizeof(struct kinfo_proc));
-
- if (sysctl(mib, arraysize(mib), &info, &length, NULL, 0) < 0)
- return -1;
-
- return info.p_vm_rssize * getpagesize();
-}
-
-size_t ProcessMetrics::GetPeakWorkingSetSize() const {
- return 0;
-}
-
-bool ProcessMetrics::GetMemoryBytes(size_t* private_bytes,
- size_t* shared_bytes) {
- WorkingSetKBytes ws_usage;
-
- if (!GetWorkingSetKBytes(&ws_usage))
- return false;
-
- if (private_bytes)
- *private_bytes = ws_usage.priv << 10;
-
- if (shared_bytes)
- *shared_bytes = ws_usage.shared * 1024;
-
- return true;
-}
-
-bool ProcessMetrics::GetWorkingSetKBytes(WorkingSetKBytes* ws_usage) const {
- // TODO(bapt): be sure we can't be precise
- size_t priv = GetWorkingSetSize();
- if (!priv)
- return false;
- ws_usage->priv = priv / 1024;
- ws_usage->shareable = 0;
- ws_usage->shared = 0;
-
- return true;
-}
-
-bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) const {
- return false;
-}
-
-static int GetProcessCPU(pid_t pid) {
- struct kinfo_proc info;
- size_t length;
- int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid,
- sizeof(struct kinfo_proc), 0 };
-
- if (sysctl(mib, arraysize(mib), NULL, &length, NULL, 0) < 0)
- return -1;
-
- mib[5] = (length / sizeof(struct kinfo_proc));
-
- if (sysctl(mib, arraysize(mib), &info, &length, NULL, 0) < 0)
- return 0;
-
- return info.p_pctcpu;
-}
-
-double ProcessMetrics::GetCPUUsage() {
- TimeTicks time = TimeTicks::Now();
-
- if (last_cpu_ == 0) {
- // First call, just set the last values.
- last_cpu_time_ = time;
- last_cpu_ = GetProcessCPU(process_);
- return 0;
- }
-
- int64 time_delta = (time - last_cpu_time_).InMicroseconds();
- DCHECK_NE(time_delta, 0);
-
- if (time_delta == 0)
- return 0;
-
- int cpu = GetProcessCPU(process_);
-
- last_cpu_time_ = time;
- last_cpu_ = cpu;
-
- double percentage = static_cast<double>((cpu * 100.0) / FSCALE);
-
- return percentage;
-}
-
-ProcessMetrics::ProcessMetrics(ProcessHandle process)
- : process_(process),
- last_system_time_(0),
- last_cpu_(0) {
-
- processor_count_ = base::SysInfo::NumberOfProcessors();
-}
-
-size_t GetSystemCommitCharge() {
- int mib[] = { CTL_VM, VM_METER };
- int pagesize;
- struct vmtotal vmtotal;
- unsigned long mem_total, mem_free, mem_inactive;
- size_t len = sizeof(vmtotal);
-
- if (sysctl(mib, arraysize(mib), &vmtotal, &len, NULL, 0) < 0)
- return 0;
-
- mem_total = vmtotal.t_vm;
- mem_free = vmtotal.t_free;
- mem_inactive = vmtotal.t_vm - vmtotal.t_avm;
-
- pagesize = getpagesize();
-
- return mem_total - (mem_free*pagesize) - (mem_inactive*pagesize);
-}
-
-} // namespace base
« no previous file with comments | « base/process/process_metrics_mac.cc ('k') | base/process/process_metrics_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698