Commit 34180ac9 authored by Robert Sesek's avatar Robert Sesek Committed by Commit Bot

Delete unused chrome/test/base/chrome_process_util

Bug: none
Change-Id: Ie4f051af9df60911cfef9c0a4b539a22ef92eb58
Reviewed-on: https://chromium-review.googlesource.com/c/1316111
Commit-Queue: Robert Sesek <rsesek@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605066}
parent 63b1278b
...@@ -69,9 +69,6 @@ static_library("test_support") { ...@@ -69,9 +69,6 @@ static_library("test_support") {
testonly = true testonly = true
sources = [ sources = [
"base/chrome_process_util.cc",
"base/chrome_process_util.h",
"base/chrome_process_util_mac.cc",
"base/chrome_render_view_host_test_harness.cc", "base/chrome_render_view_host_test_harness.cc",
"base/chrome_render_view_host_test_harness.h", "base/chrome_render_view_host_test_harness.h",
"base/chrome_test_launcher.cc", "base/chrome_test_launcher.cc",
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/test/base/chrome_process_util.h"
#include <set>
#include <string>
#include <vector>
#include "base/command_line.h"
#include "base/macros.h"
#include "base/process/process.h"
#include "base/process/process_iterator.h"
#include "base/process/process_metrics.h"
#include "base/stl_util.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/test/base/test_switches.h"
#include "content/public/common/result_codes.h"
using base::TimeDelta;
using base::TimeTicks;
void TerminateAllChromeProcesses(const ChromeProcessList& process_pids) {
for (auto pid : process_pids) {
base::Process process = base::Process::Open(pid);
if (process.IsValid()) {
// Ignore processes for which we can't open the handle. We don't
// guarantee that all processes will terminate, only try to do so.
process.Terminate(content::RESULT_CODE_KILLED, true);
}
}
}
class ChildProcessFilter : public base::ProcessFilter {
public:
explicit ChildProcessFilter(base::ProcessId parent_pid)
: parent_pids_(&parent_pid, (&parent_pid) + 1) {}
explicit ChildProcessFilter(const std::vector<base::ProcessId>& parent_pids)
: parent_pids_(parent_pids.begin(), parent_pids.end()) {}
bool Includes(const base::ProcessEntry& entry) const override {
return base::ContainsKey(parent_pids_, entry.parent_pid());
}
private:
const std::set<base::ProcessId> parent_pids_;
DISALLOW_COPY_AND_ASSIGN(ChildProcessFilter);
};
ChromeProcessList GetRunningChromeProcesses(base::ProcessId browser_pid) {
const base::FilePath::CharType* executable_name =
chrome::kBrowserProcessExecutableName;
ChromeProcessList result;
if (browser_pid == static_cast<base::ProcessId>(-1))
return result;
ChildProcessFilter filter(browser_pid);
base::NamedProcessIterator it(executable_name, &filter);
while (const base::ProcessEntry* process_entry = it.NextProcessEntry()) {
result.push_back(process_entry->pid());
}
#if defined(OS_POSIX) && !defined(OS_MACOSX)
// On Unix we might be running with a zygote process for the renderers.
// Because of that we sweep the list of processes again and pick those which
// are children of one of the processes that we've already seen.
{
ChildProcessFilter filter(result);
base::NamedProcessIterator it(executable_name, &filter);
while (const base::ProcessEntry* process_entry = it.NextProcessEntry())
result.push_back(process_entry->pid());
}
#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
#if defined(OS_POSIX)
// On Mac OS X we run the subprocesses with a different bundle, and
// on Linux via /proc/self/exe, so they end up with a different
// name. We must collect them in a second pass.
{
base::FilePath::StringType name = chrome::kHelperProcessExecutableName;
ChildProcessFilter filter(browser_pid);
base::NamedProcessIterator it(name, &filter);
while (const base::ProcessEntry* process_entry = it.NextProcessEntry())
result.push_back(process_entry->pid());
}
#endif // defined(OS_POSIX)
result.push_back(browser_pid);
return result;
}
ChromeTestProcessMetrics::~ChromeTestProcessMetrics() {}
ChromeTestProcessMetrics::ChromeTestProcessMetrics(
base::ProcessHandle process) {
#if defined(OS_MACOSX)
process_metrics_ =
base::ProcessMetrics::CreateProcessMetrics(process, nullptr);
#else
process_metrics_ = base::ProcessMetrics::CreateProcessMetrics(process);
#endif
process_handle_ = process;
}
bool ChromeTestProcessMetrics::GetIOCounters(base::IoCounters* io_counters) {
return process_metrics_->GetIOCounters(io_counters);
}
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_TEST_BASE_CHROME_PROCESS_UTIL_H_
#define CHROME_TEST_BASE_CHROME_PROCESS_UTIL_H_
#include <stddef.h>
#include <memory>
#include <vector>
#include "base/macros.h"
#include "base/process/process_handle.h"
#include "base/process/process_metrics.h"
#include "build/build_config.h"
using ChromeProcessList = std::vector<base::ProcessId>;
// Returns a vector of PIDs of all chrome processes (main and renderers etc)
// based on |browser_pid|, the PID of the main browser process.
ChromeProcessList GetRunningChromeProcesses(base::ProcessId browser_pid);
// Attempts to terminate all chrome processes in |process_list|.
void TerminateAllChromeProcesses(const ChromeProcessList& process_list);
// A wrapper class for tests to use in fetching process metrics.
// Delegates everything we need to base::ProcessMetrics, except
// memory stats on Mac (which have to parse ps output due to privilege
// restrictions, behavior we don't want in base). Long-term, if
// the production base::ProcessMetrics gets updated to return
// acceptable metrics on Mac, this class should disappear.
class ChromeTestProcessMetrics {
public:
static ChromeTestProcessMetrics* CreateProcessMetrics(
base::ProcessHandle process) {
return new ChromeTestProcessMetrics(process);
}
bool GetIOCounters(base::IoCounters* io_counters);
base::ProcessHandle process_handle_;
~ChromeTestProcessMetrics();
private:
explicit ChromeTestProcessMetrics(base::ProcessHandle process);
std::unique_ptr<base::ProcessMetrics> process_metrics_;
DISALLOW_COPY_AND_ASSIGN(ChromeTestProcessMetrics);
};
#if defined(OS_MACOSX)
// These types and API are here to fetch the information about a set of running
// processes by ID on the Mac. There are also APIs in base, but fetching the
// information for another process requires privileges that a normal executable
// does not have. This API fetches the data by spawning ps (which is setuid so
// it has the needed privileges) and processing its output. The API is provided
// here because we don't want code spawning processes like this in base, where
// someone writing cross platform code might use it without realizing that it's
// a heavyweight call on the Mac.
struct MacChromeProcessInfo {
base::ProcessId pid;
int rsz_in_kb;
int vsz_in_kb;
};
using MacChromeProcessInfoList = std::vector<MacChromeProcessInfo>;
// Any ProcessId that info can't be found for will be left out.
MacChromeProcessInfoList GetRunningMacProcessInfo(
const ChromeProcessList& process_list);
#endif // defined(OS_MACOSX)
#endif // CHROME_TEST_BASE_CHROME_PROCESS_UTIL_H_
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/test/base/chrome_process_util.h"
#include <stddef.h>
#include <stdint.h>
#include <string>
#include <vector>
#include "base/command_line.h"
#include "base/process/launch.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
MacChromeProcessInfoList GetRunningMacProcessInfo(
const ChromeProcessList& process_list) {
MacChromeProcessInfoList result;
// Build up the ps command line
std::vector<std::string> cmdline;
cmdline.push_back("ps");
cmdline.push_back("-o");
cmdline.push_back("pid=,rss=,vsz="); // fields we need, no headings
ChromeProcessList::const_iterator process_iter;
for (process_iter = process_list.begin();
process_iter != process_list.end();
++process_iter) {
cmdline.push_back("-p");
cmdline.push_back(base::IntToString(*process_iter));
}
// Invoke it
std::string ps_output;
if (!base::GetAppOutput(base::CommandLine(cmdline), &ps_output))
return result; // All the pids might have exited
// Process the results.
for (const std::string& raw_line : base::SplitString(
ps_output, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
std::string line(base::CollapseWhitespaceASCII(raw_line, false));
std::vector<base::StringPiece> values = base::SplitStringPiece(
line, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
if (values.size() == 3) {
MacChromeProcessInfo proc_info;
int pid;
base::StringToInt(values[0], &pid);
proc_info.pid = pid;
base::StringToInt(values[1], &proc_info.rsz_in_kb);
base::StringToInt(values[2], &proc_info.vsz_in_kb);
if (proc_info.pid && proc_info.rsz_in_kb && proc_info.vsz_in_kb)
result.push_back(proc_info);
}
}
return result;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment