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

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: . Created 6 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 unified diff | Download patch | Annotate | Revision Log
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 namespace base { 7 namespace base {
8 8
9 ProcessMetrics::ProcessMetrics(ProcessHandle process) 9 ProcessMetrics::ProcessMetrics(ProcessHandle process)
10 : process_(process), 10 : process_(process),
11 last_cpu_time_(0),
12 last_system_time_(0), 11 last_system_time_(0),
13 last_cpu_(0) { 12 last_cpu_(0) {
14 processor_count_ = base::SysInfo::NumberOfProcessors(); 13 processor_count_ = base::SysInfo::NumberOfProcessors();
15 } 14 }
16 15
17 // static 16 // static
18 ProcessMetrics* ProcessMetrics::CreateProcessMetrics(ProcessHandle process) { 17 ProcessMetrics* ProcessMetrics::CreateProcessMetrics(ProcessHandle process) {
19 return new ProcessMetrics(process); 18 return new ProcessMetrics(process);
20 } 19 }
21 20
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 ws_usage->shared = 0; 73 ws_usage->shared = 0;
75 74
76 return true; 75 return true;
77 } 76 }
78 77
79 double ProcessMetrics::GetCPUUsage() { 78 double ProcessMetrics::GetCPUUsage() {
80 struct kinfo_proc info; 79 struct kinfo_proc info;
81 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, process_ }; 80 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, process_ };
82 size_t length = sizeof(info); 81 size_t length = sizeof(info);
83 82
84 struct timeval now;
85 int retval = gettimeofday(&now, NULL);
86 if (retval)
87 return 0;
88
89 if (sysctl(mib, arraysize(mib), &info, &length, NULL, 0) < 0) 83 if (sysctl(mib, arraysize(mib), &info, &length, NULL, 0) < 0)
90 return 0; 84 return 0;
91 85
92 return (info.ki_pctcpu / FSCALE) * 100.0; 86 return (info.ki_pctcpu / FSCALE) * 100.0;
93 } 87 }
94 88
95 bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) const { 89 bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) const {
96 return false; 90 return false;
97 } 91 }
98 92
(...skipping 14 matching lines...) Expand all
113 NULL, 0) < 0) { 107 NULL, 0) < 0) {
114 return 0; 108 return 0;
115 } 109 }
116 110
117 pagesize = getpagesize(); 111 pagesize = getpagesize();
118 112
119 return mem_total - (mem_free*pagesize) - (mem_inactive*pagesize); 113 return mem_total - (mem_free*pagesize) - (mem_inactive*pagesize);
120 } 114 }
121 115
122 } // namespace base 116 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698