Bug 1426513, part 1 - Remove ProcessMetrics and ProcessFilter. r=jld

MozReview-Commit-ID: 7991I7JtkIw

--HG--
extra : rebase_source : f4b04d9b3bd1b752363aef8628133f359038c361
This commit is contained in:
Andrew McCreight 2017-12-20 13:43:01 -08:00
Родитель 4228c58572
Коммит e2c8b28f84
3 изменённых файлов: 0 добавлений и 171 удалений

Просмотреть файл

@ -167,15 +167,6 @@ 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.
@ -191,40 +182,6 @@ bool KillProcess(ProcessHandle process, int exit_code, bool wait);
// 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 {

Просмотреть файл

@ -249,19 +249,6 @@ void SetAllFDsToCloseOnExec() {
}
}
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));
@ -309,53 +296,6 @@ bool DidProcessCrash(bool* child_exited, ProcessHandle handle) {
return false;
}
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)
{

Просмотреть файл

@ -402,72 +402,4 @@ bool DidProcessCrash(bool* child_exited, ProcessHandle handle) {
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