Bug 1426513, part 1 - Remove ProcessMetrics and ProcessFilter. r=jld
☠☠ backed out by 8a45850ffc2e ☠ ☠
authorAndrew McCreight <continuation@gmail.com>
Wed, 20 Dec 2017 13:43:01 -0800
changeset 448940 9d80a554866cc8d1b2af88d9a5286bda19e18e66
parent 448939 b5b951c9a615410b7838db458556fa76f78053d0
child 448941 64021383118d4e301fae210005791996d5e10786
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjld
bugs1426513
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1426513, part 1 - Remove ProcessMetrics and ProcessFilter. r=jld MozReview-Commit-ID: 7991I7JtkIw
ipc/chromium/src/base/process_util.h
ipc/chromium/src/base/process_util_posix.cc
ipc/chromium/src/base/process_util_win.cc
--- a/ipc/chromium/src/base/process_util.h
+++ b/ipc/chromium/src/base/process_util.h
@@ -162,74 +162,31 @@ EnvironmentArray BuildEnvironmentArray(c
 #endif
 
 // Executes the application specified by cl. This function delegates to one
 // of the above two platform-specific functions.
 bool LaunchApp(const CommandLine& cl,
                const LaunchOptions&,
                ProcessHandle* process_handle);
 
-// Used to filter processes by process ID.
-class ProcessFilter {
- public:
-  // Returns true to indicate set-inclusion and false otherwise.  This method
-  // should not have side-effects and should be idempotent.
-  virtual bool Includes(ProcessId pid, ProcessId parent_pid) const = 0;
-  virtual ~ProcessFilter() { }
-};
-
 // Attempts to kill the process identified by the given process
 // entry structure, giving it the specified exit code. If |wait| is true, wait
 // for the process to be actually terminated before returning.
 // Returns true if this is successful, false otherwise.
 bool KillProcess(ProcessHandle process, int exit_code, bool wait);
 
 // Get the termination status (exit code) of the process and return true if the
 // status indicates the process crashed. |child_exited| is set to true iff the
 // child process has terminated. (|child_exited| may be NULL.)
 //
 // On Windows, it is an error to call this if the process hasn't terminated
 // yet. On POSIX, |child_exited| is set correctly since we detect terminate in
 // a different manner on POSIX.
 bool DidProcessCrash(bool* child_exited, ProcessHandle handle);
 
-// Provides performance metrics for a specified process (CPU usage, memory and
-// IO counters). To use it, invoke CreateProcessMetrics() to get an instance
-// for a specific process, then access the information with the different get
-// methods.
-class ProcessMetrics {
- public:
-  // Creates a ProcessMetrics for the specified process.
-  // The caller owns the returned object.
-  static ProcessMetrics* CreateProcessMetrics(ProcessHandle process);
-
-  ~ProcessMetrics();
-
-  // Returns the CPU usage in percent since the last time this method was
-  // called. The first time this method is called it returns 0 and will return
-  // the actual CPU info on subsequent calls.
-  // Note that on multi-processor machines, the CPU usage value is for all
-  // CPUs. So if you have 2 CPUs and your process is using all the cycles
-  // of 1 CPU and not the other CPU, this method returns 50.
-  int GetCPUUsage();
-
- private:
-  explicit ProcessMetrics(ProcessHandle process);
-
-  ProcessHandle process_;
-
-  int processor_count_;
-
-  // Used to store the previous times so we can compute the CPU usage.
-  int64_t last_time_;
-  int64_t last_system_time_;
-
-  DISALLOW_EVIL_CONSTRUCTORS(ProcessMetrics);
-};
-
 }  // namespace base
 
 namespace mozilla {
 
 class EnvironmentLog
 {
 public:
   explicit EnvironmentLog(const char* varname) {
--- a/ipc/chromium/src/base/process_util_posix.cc
+++ b/ipc/chromium/src/base/process_util_posix.cc
@@ -244,29 +244,16 @@ void SetAllFDsToCloseOnExec() {
 
     int flags = fcntl(i, F_GETFD);
     if ((flags == -1) || (fcntl(i, F_SETFD, flags | FD_CLOEXEC) == -1)) {
       DLOG(ERROR) << "fcntl failure.";
     }
   }
 }
 
-ProcessMetrics::ProcessMetrics(ProcessHandle process) : process_(process),
-                                                        last_time_(0),
-                                                        last_system_time_(0) {
-  processor_count_ = base::SysInfo::NumberOfProcessors();
-}
-
-// static
-ProcessMetrics* ProcessMetrics::CreateProcessMetrics(ProcessHandle process) {
-  return new ProcessMetrics(process);
-}
-
-ProcessMetrics::~ProcessMetrics() { }
-
 bool DidProcessCrash(bool* child_exited, ProcessHandle handle) {
   int status;
   const int result = HANDLE_EINTR(waitpid(handle, &status, WNOHANG));
   if (result == -1) {
     // This shouldn't happen, but sometimes it does.  The error is
     // probably ECHILD and the reason is probably that a pid was
     // waited on again after a previous wait reclaimed its zombie.
     // (It could also occur if the process isn't a direct child, but
@@ -312,55 +299,16 @@ bool DidProcessCrash(bool* child_exited,
 namespace {
 
 int64_t TimeValToMicroseconds(const struct timeval& tv) {
   return tv.tv_sec * kMicrosecondsPerSecond + tv.tv_usec;
 }
 
 }
 
-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_t system_time = (TimeValToMicroseconds(usage.ru_stime) +
-                       TimeValToMicroseconds(usage.ru_utime)) /
-                        processor_count_;
-  int64_t 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_t system_time_delta = system_time - last_system_time_;
-  int64_t 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;
-}
-
 void
 FreeEnvVarsArray::operator()(char** array)
 {
   for (char** varPtr = array; *varPtr != nullptr; ++varPtr) {
     free(*varPtr);
   }
   delete[] array;
 }
--- a/ipc/chromium/src/base/process_util_win.cc
+++ b/ipc/chromium/src/base/process_util_win.cc
@@ -397,77 +397,9 @@ bool DidProcessCrash(bool* child_exited,
       exitcode == 0xC000013A ||     // Control-C/end session.
       exitcode == 0x40010004) {     // Debugger terminated process/end session.
     return false;
   }
 
   return true;
 }
 
-///////////////////////////////////////////////////////////////////////////////
-// ProcesMetrics
-
-ProcessMetrics::ProcessMetrics(ProcessHandle process) : process_(process),
-                                                        last_time_(0),
-                                                        last_system_time_(0) {
-  SYSTEM_INFO system_info;
-  GetSystemInfo(&system_info);
-  processor_count_ = system_info.dwNumberOfProcessors;
-}
-
-// static
-ProcessMetrics* ProcessMetrics::CreateProcessMetrics(ProcessHandle process) {
-  return new ProcessMetrics(process);
-}
-
-ProcessMetrics::~ProcessMetrics() { }
-
-static uint64_t FileTimeToUTC(const FILETIME& ftime) {
-  LARGE_INTEGER li;
-  li.LowPart = ftime.dwLowDateTime;
-  li.HighPart = ftime.dwHighDateTime;
-  return li.QuadPart;
-}
-
-int ProcessMetrics::GetCPUUsage() {
-  FILETIME now;
-  FILETIME creation_time;
-  FILETIME exit_time;
-  FILETIME kernel_time;
-  FILETIME user_time;
-
-  GetSystemTimeAsFileTime(&now);
-
-  if (!GetProcessTimes(process_, &creation_time, &exit_time,
-                       &kernel_time, &user_time)) {
-    // We don't assert here because in some cases (such as in the Task Manager)
-    // we may call this function on a process that has just exited but we have
-    // not yet received the notification.
-    return 0;
-  }
-  int64_t system_time = (FileTimeToUTC(kernel_time) + FileTimeToUTC(user_time)) /
-                        processor_count_;
-  int64_t time = FileTimeToUTC(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_t system_time_delta = system_time - last_system_time_;
-  int64_t 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;
-}
-
 }  // namespace base