diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-18 22:48:19 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-18 22:48:19 +0000 |
commit | 14620b39945285390b90a0d84cae39c677ce18aa (patch) | |
tree | 93b5966947f6c9e04632decdd88d8d480c36b6bd /base/process_util_posix.cc | |
parent | a8c8b34888746435dfe73ff529aaf3b1d9ace3e3 (diff) | |
download | chromium_src-14620b39945285390b90a0d84cae39c677ce18aa.zip chromium_src-14620b39945285390b90a0d84cae39c677ce18aa.tar.gz chromium_src-14620b39945285390b90a0d84cae39c677ce18aa.tar.bz2 |
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
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34994 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_posix.cc')
-rw-r--r-- | base/process_util_posix.cc | 67 |
1 files changed, 20 insertions, 47 deletions
diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc index 4392c7b..16469db 100644 --- a/base/process_util_posix.cc +++ b/base/process_util_posix.cc @@ -360,20 +360,36 @@ bool LaunchApp(const CommandLine& cl, return LaunchApp(cl.argv(), no_files, wait, process_handle); } -ProcessMetrics::ProcessMetrics(ProcessHandle process) : process_(process), - last_time_(0), - last_system_time_(0) +#if !defined(OS_MACOSX) +ProcessMetrics::ProcessMetrics(ProcessHandle process) +#else +ProcessMetrics::ProcessMetrics(ProcessHandle process, + ProcessMetrics::PortProvider* port_provider) +#endif + : process_(process), + last_time_(0), + last_system_time_(0) #if defined(OS_LINUX) - , last_cpu_(0) + , last_cpu_(0) +#elif defined (OS_MACOSX) + , port_provider_(port_provider) #endif { processor_count_ = base::SysInfo::NumberOfProcessors(); } // static +#if !defined(OS_MACOSX) ProcessMetrics* ProcessMetrics::CreateProcessMetrics(ProcessHandle process) { return new ProcessMetrics(process); } +#else +ProcessMetrics* ProcessMetrics::CreateProcessMetrics( + ProcessHandle process, + ProcessMetrics::PortProvider* port_provider) { + return new ProcessMetrics(process, port_provider); +} +#endif ProcessMetrics::~ProcessMetrics() { } @@ -494,49 +510,6 @@ int64 TimeValToMicroseconds(const struct timeval& tv) { return tv.tv_sec * kMicrosecondsPerSecond + tv.tv_usec; } -#if defined(OS_MACOSX) -// TODO(port): this function only returns the *current* CPU's usage; -// we want to return this->process_'s CPU usage. -int ProcessMetrics::GetCPUUsage() { - struct timeval now; - struct rusage usage; - - int retval = gettimeofday(&now, NULL); - if (retval) - return 0; - retval = getrusage(RUSAGE_SELF, &usage); - if (retval) - return 0; - - int64 system_time = (TimeValToMicroseconds(usage.ru_stime) + - TimeValToMicroseconds(usage.ru_utime)) / - processor_count_; - int64 time = TimeValToMicroseconds(now); - - if ((last_system_time_ == 0) || (last_time_ == 0)) { - // First call, just set the last values. - last_system_time_ = system_time; - last_time_ = time; - return 0; - } - - int64 system_time_delta = system_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_ = system_time; - last_time_ = time; - - return cpu; -} -#endif - // Executes the application specified by |cl| and wait for it to exit. Stores // the output (stdout) in |output|. If |do_search_path| is set, it searches the // path for the application; in that case, |envp| must be null, and it will use |