summaryrefslogtreecommitdiffstats
path: root/base/process_util_mac.mm
diff options
context:
space:
mode:
authorthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-19 01:31:03 +0000
committerthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-19 01:31:03 +0000
commit0d525036512529fc73287726ac65649040672f86 (patch)
treec7228937ed591491d541b76aee909ee3090fb1db /base/process_util_mac.mm
parent27f2b6626e1c0e71d8b8e5d20e017beee762d7d6 (diff)
downloadchromium_src-0d525036512529fc73287726ac65649040672f86.zip
chromium_src-0d525036512529fc73287726ac65649040672f86.tar.gz
chromium_src-0d525036512529fc73287726ac65649040672f86.tar.bz2
Revert 34994, maybe it regressed startup perf - Fix cpu/memory measurements on OS X.
Right now, this only works for the current process; support for child processes will be added in a later CL. BUG=13156,25454 TEST=Hook up task manager (connect menu item to commandDispatch:, give it the right tag). Stats for the browser process should now be right, and %cpu should be 0 (for now) for all other processes. Review URL: http://codereview.chromium.org/500118 TBR=thakis@chromium.org Review URL: http://codereview.chromium.org/504068 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35025 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_mac.mm')
-rw-r--r--base/process_util_mac.mm125
1 files changed, 7 insertions, 118 deletions
diff --git a/base/process_util_mac.mm b/base/process_util_mac.mm
index dd4dc37..91944e8 100644
--- a/base/process_util_mac.mm
+++ b/base/process_util_mac.mm
@@ -182,46 +182,23 @@ bool NamedProcessIterator::IncludeEntry() {
// ------------------------------------------------------------------------
// NOTE: about ProcessMetrics
//
-// Getting a mach task from a pid for another process requires permissions in
-// general, so there doesn't really seem to be a way to do these (and spinning
-// up ps to fetch each stats seems dangerous to put in a base api for anyone to
-// call). Child processes ipc their port, so return something if available,
-// otherwise return 0.
+// Mac doesn't have /proc, and getting a mach task from a pid for another
+// process requires permissions, so there doesn't really seem to be a way
+// to do these (and spinning up ps to fetch each stats seems dangerous to
+// put in a base api for anyone to call.
//
bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) const {
return false;
}
-
-static bool GetTaskInfo(mach_port_t task, task_basic_info_64* task_info_data) {
- if (!task)
- return false;
- mach_msg_type_number_t count = TASK_BASIC_INFO_64_COUNT;
- kern_return_t kr = task_info(task,
- TASK_BASIC_INFO_64,
- reinterpret_cast<task_info_t>(task_info_data),
- &count);
- // Most likely cause for failure: |task| is a zombie.
- return kr == KERN_SUCCESS;
-}
-
size_t ProcessMetrics::GetPagefileUsage() const {
- task_basic_info_64 task_info_data;
- if (!GetTaskInfo(TaskForPid(process_), &task_info_data))
- return 0;
- return task_info_data.virtual_size;
+ return 0;
}
-
size_t ProcessMetrics::GetPeakPagefileUsage() const {
return 0;
}
-
size_t ProcessMetrics::GetWorkingSetSize() const {
- task_basic_info_64 task_info_data;
- if (!GetTaskInfo(TaskForPid(process_), &task_info_data))
- return 0;
- return task_info_data.resident_size;
+ return 0;
}
-
size_t ProcessMetrics::GetPeakWorkingSetSize() const {
return 0;
}
@@ -234,95 +211,7 @@ void ProcessMetrics::GetCommittedKBytes(CommittedKBytes* usage) const {
}
bool ProcessMetrics::GetWorkingSetKBytes(WorkingSetKBytes* ws_usage) const {
- size_t priv = GetWorkingSetSize();
- if (!priv)
- return false;
- ws_usage->priv = priv / 1024;
- ws_usage->shareable = 0;
- ws_usage->shared = 0;
- return true;
-}
-
-#define TIME_VALUE_TO_TIMEVAL(a, r) do { \
- (r)->tv_sec = (a)->seconds; \
- (r)->tv_usec = (a)->microseconds; \
-} while (0)
-
-int ProcessMetrics::GetCPUUsage() {
- mach_port_t task = TaskForPid(process_);
- if (!task)
- return 0;
-
- kern_return_t kr;
-
- // TODO(thakis): Libtop doesn't use thread info. How can they get away
- // without it?
- task_thread_times_info thread_info_data;
- mach_msg_type_number_t thread_info_count = TASK_THREAD_TIMES_INFO_COUNT;
- kr = task_info(task,
- TASK_THREAD_TIMES_INFO,
- reinterpret_cast<task_info_t>(&thread_info_data),
- &thread_info_count);
- if (kr != KERN_SUCCESS) {
- // Most likely cause: |task| is a zombie.
- return 0;
- }
-
- task_basic_info_64 task_info_data;
- if (!GetTaskInfo(task, &task_info_data))
- return 0;
-
- /* Set total_time. */
- // thread info contains live time...
- struct timeval user_timeval, system_timeval, task_timeval;
- TIME_VALUE_TO_TIMEVAL(&thread_info_data.user_time, &user_timeval);
- TIME_VALUE_TO_TIMEVAL(&thread_info_data.system_time, &system_timeval);
- timeradd(&user_timeval, &system_timeval, &task_timeval);
-
- // ... task info contains terminated time.
- TIME_VALUE_TO_TIMEVAL(&task_info_data.user_time, &user_timeval);
- TIME_VALUE_TO_TIMEVAL(&task_info_data.system_time, &system_timeval);
- timeradd(&user_timeval, &task_timeval, &task_timeval);
- timeradd(&system_timeval, &task_timeval, &task_timeval);
-
- struct timeval now;
- int retval = gettimeofday(&now, NULL);
- if (retval)
- return 0;
-
- int64 time = TimeValToMicroseconds(now);
- int64 task_time = TimeValToMicroseconds(task_timeval);
-
- if ((last_system_time_ == 0) || (last_time_ == 0)) {
- // First call, just set the last values.
- last_system_time_ = task_time;
- last_time_ = time;
- return 0;
- }
-
- int64 system_time_delta = task_time - last_system_time_;
- int64 time_delta = time - last_time_;
- DCHECK(time_delta != 0);
- if (time_delta == 0)
- return 0;
-
- // We add time_delta / 2 so the result is rounded.
- int cpu = static_cast<int>((system_time_delta * 100 + time_delta / 2) /
- (time_delta));
-
- last_system_time_ = task_time;
- last_time_ = time;
-
- return cpu;
-}
-
-mach_port_t ProcessMetrics::TaskForPid(ProcessHandle process) const {
- mach_port_t task = 0;
- if (port_provider_)
- task = port_provider_->TaskForPid(process_);
- if (!task && process_ == getpid())
- task = mach_task_self();
- return task;
+ return false;
}
// ------------------------------------------------------------------------