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

Side by Side Diff: base/process/process_metrics_freebsd.cc

Issue 139103007: Use TimeTicks instead of gettimeofday in ProcessMetrics. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: reverty Created 6 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/process/process_metrics.h ('k') | base/process/process_metrics_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/process/process_metrics.h" 5 #include "base/process/process_metrics.h"
6 6
7 #include <sys/sysctl.h> 7 #include <sys/sysctl.h>
8 #include <sys/user.h> 8 #include <sys/user.h>
9 #include <unistd.h> 9 #include <unistd.h>
10 10
11 #include "base/sys_info.h" 11 #include "base/sys_info.h"
12 12
13 namespace base { 13 namespace base {
14 14
15 ProcessMetrics::ProcessMetrics(ProcessHandle process) 15 ProcessMetrics::ProcessMetrics(ProcessHandle process)
16 : process_(process), 16 : process_(process),
17 last_cpu_time_(0),
18 last_system_time_(0), 17 last_system_time_(0),
19 last_cpu_(0) { 18 last_cpu_(0) {
20 processor_count_ = base::SysInfo::NumberOfProcessors(); 19 processor_count_ = base::SysInfo::NumberOfProcessors();
21 } 20 }
22 21
23 // static 22 // static
24 ProcessMetrics* ProcessMetrics::CreateProcessMetrics(ProcessHandle process) { 23 ProcessMetrics* ProcessMetrics::CreateProcessMetrics(ProcessHandle process) {
25 return new ProcessMetrics(process); 24 return new ProcessMetrics(process);
26 } 25 }
27 26
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 ws_usage->shared = 0; 79 ws_usage->shared = 0;
81 80
82 return true; 81 return true;
83 } 82 }
84 83
85 double ProcessMetrics::GetCPUUsage() { 84 double ProcessMetrics::GetCPUUsage() {
86 struct kinfo_proc info; 85 struct kinfo_proc info;
87 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, process_ }; 86 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, process_ };
88 size_t length = sizeof(info); 87 size_t length = sizeof(info);
89 88
90 struct timeval now;
91 int retval = gettimeofday(&now, NULL);
92 if (retval)
93 return 0;
94
95 if (sysctl(mib, arraysize(mib), &info, &length, NULL, 0) < 0) 89 if (sysctl(mib, arraysize(mib), &info, &length, NULL, 0) < 0)
96 return 0; 90 return 0;
97 91
98 return (info.ki_pctcpu / FSCALE) * 100.0; 92 return (info.ki_pctcpu / FSCALE) * 100.0;
99 } 93 }
100 94
101 bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) const { 95 bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) const {
102 return false; 96 return false;
103 } 97 }
104 98
(...skipping 14 matching lines...) Expand all
119 NULL, 0) < 0) { 113 NULL, 0) < 0) {
120 return 0; 114 return 0;
121 } 115 }
122 116
123 pagesize = getpagesize(); 117 pagesize = getpagesize();
124 118
125 return mem_total - (mem_free*pagesize) - (mem_inactive*pagesize); 119 return mem_total - (mem_free*pagesize) - (mem_inactive*pagesize);
126 } 120 }
127 121
128 } // namespace base 122 } // namespace base
OLDNEW
« no previous file with comments | « base/process/process_metrics.h ('k') | base/process/process_metrics_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698