Commit 0d6d080a authored by Ken Rockot's avatar Ken Rockot Committed by Commit Bot

Migrate heap_profiling service away from Mojo EDK APIs

Switches all heap_profiling code to new public Mojo APIs which
are replacing their EDK equivalents. No functional changes.

This also includes appropriate DEPS and GN deps cleanup.

Bug: 844763
Change-Id: Ica8969ae83d884e582025ddf92bf1f0104eb910e
Reviewed-on: https://chromium-review.googlesource.com/1100077
Commit-Queue: Ken Rockot <rockot@chromium.org>
Reviewed-by: default avatarErik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567335}
parent fa8f7938
...@@ -36,7 +36,6 @@ static_library("heap_profiling") { ...@@ -36,7 +36,6 @@ static_library("heap_profiling") {
deps = [ deps = [
"//base", "//base",
"//components/services/heap_profiling/public/cpp", "//components/services/heap_profiling/public/cpp",
"//mojo/edk",
"//services/resource_coordinator/public/cpp:resource_coordinator_cpp", "//services/resource_coordinator/public/cpp:resource_coordinator_cpp",
"//third_party/zlib", "//third_party/zlib",
] ]
......
include_rules = [ include_rules = [
"+components/services/heap_profiling/public", "+components/services/heap_profiling/public",
"+mojo/edk/embedder",
"+services/resource_coordinator/public", "+services/resource_coordinator/public",
"+third_party/zlib/zlib.h", "+third_party/zlib/zlib.h",
] ]
...@@ -147,12 +147,8 @@ void ConnectionManager::OnNewConnection(base::ProcessId pid, ...@@ -147,12 +147,8 @@ void ConnectionManager::OnNewConnection(base::ProcessId pid,
// when the user is attempting to manually start profiling for processes, so // when the user is attempting to manually start profiling for processes, so
// we ignore this edge case. // we ignore this edge case.
base::PlatformFile receiver_handle; scoped_refptr<ReceiverPipe> new_pipe = new ReceiverPipe(
CHECK_EQ(MOJO_RESULT_OK, mojo::UnwrapPlatformFile( mojo::UnwrapPlatformHandle(std::move(receiver_pipe_end)));
std::move(receiver_pipe_end), &receiver_handle));
scoped_refptr<ReceiverPipe> new_pipe =
new ReceiverPipe(mojo::edk::ScopedInternalPlatformHandle(
mojo::edk::InternalPlatformHandle(receiver_handle)));
// The allocation tracker will call this on a background thread, so thunk // The allocation tracker will call this on a background thread, so thunk
// back to the current thread with weak pointers. // back to the current thread with weak pointers.
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#include "components/services/heap_profiling/allocation_tracker.h" #include "components/services/heap_profiling/allocation_tracker.h"
#include "components/services/heap_profiling/backtrace_storage.h" #include "components/services/heap_profiling/backtrace_storage.h"
#include "components/services/heap_profiling/public/mojom/heap_profiling_service.mojom.h" #include "components/services/heap_profiling/public/mojom/heap_profiling_service.mojom.h"
#include "mojo/edk/embedder/scoped_platform_handle.h"
#include "services/resource_coordinator/public/mojom/memory_instrumentation/memory_instrumentation.mojom.h" #include "services/resource_coordinator/public/mojom/memory_instrumentation/memory_instrumentation.mojom.h"
namespace base { namespace base {
......
...@@ -26,7 +26,6 @@ static_library("cpp") { ...@@ -26,7 +26,6 @@ static_library("cpp") {
"//base", "//base",
"//base:debugging_buildflags", "//base:debugging_buildflags",
"//base/allocator:buildflags", "//base/allocator:buildflags",
"//mojo/edk",
"//services/resource_coordinator/public/mojom:", "//services/resource_coordinator/public/mojom:",
"//services/service_manager/public/cpp", "//services/service_manager/public/cpp",
] ]
...@@ -47,7 +46,6 @@ source_set("unit_tests") { ...@@ -47,7 +46,6 @@ source_set("unit_tests") {
"//base", "//base",
"//base/allocator:buildflags", "//base/allocator:buildflags",
"//base/test:test_support", "//base/test:test_support",
"//mojo/edk",
"//testing/gtest", "//testing/gtest",
] ]
} }
include_rules = [ include_rules = [
"+mojo/edk/embedder",
"+components/services/heap_profiling/public", "+components/services/heap_profiling/public",
] ]
...@@ -66,12 +66,8 @@ void Client::StartProfiling(mojom::ProfilingParamsPtr params) { ...@@ -66,12 +66,8 @@ void Client::StartProfiling(mojom::ProfilingParamsPtr params) {
return; return;
started_profiling_ = true; started_profiling_ = true;
base::PlatformFile platform_file; sender_pipe_.reset(new SenderPipe(
CHECK_EQ(MOJO_RESULT_OK, mojo::UnwrapPlatformFile( mojo::UnwrapPlatformHandle(std::move(params->sender_pipe))));
std::move(params->sender_pipe), &platform_file));
base::ScopedPlatformFile scoped_platform_file(platform_file);
sender_pipe_.reset(new SenderPipe(std::move(scoped_platform_file)));
StreamHeader header; StreamHeader header;
header.signature = kStreamSignature; header.signature = kStreamSignature;
......
...@@ -50,12 +50,10 @@ void Controller::StartProfilingClient(mojom::ProfilingClientPtr client, ...@@ -50,12 +50,10 @@ void Controller::StartProfilingClient(mojom::ProfilingClientPtr client,
mojom::ProfilingParamsPtr params = mojom::ProfilingParams::New(); mojom::ProfilingParamsPtr params = mojom::ProfilingParams::New();
params->sampling_rate = sampling_rate_; params->sampling_rate = sampling_rate_;
params->sender_pipe = params->sender_pipe = mojo::WrapPlatformHandle(pipes.PassSender());
mojo::WrapPlatformFile(pipes.PassSender().release().handle);
params->stack_mode = stack_mode_; params->stack_mode = stack_mode_;
heap_profiling_service_->AddProfilingClient( heap_profiling_service_->AddProfilingClient(
pid, std::move(client), pid, std::move(client), mojo::WrapPlatformHandle(pipes.PassReceiver()),
mojo::WrapPlatformFile(pipes.PassReceiver().release().handle),
process_type, std::move(params)); process_type, std::move(params));
} }
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "base/files/platform_file.h" #include "base/files/platform_file.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "mojo/edk/embedder/scoped_platform_handle.h" #include "mojo/public/cpp/platform/platform_handle.h"
namespace heap_profiling { namespace heap_profiling {
...@@ -32,20 +32,16 @@ class SenderPipe { ...@@ -32,20 +32,16 @@ class SenderPipe {
// |kPipeSize|. // |kPipeSize|.
PipePair(); PipePair();
PipePair(PipePair&&); PipePair(PipePair&&);
mojo::edk::ScopedInternalPlatformHandle PassSender() { mojo::PlatformHandle PassSender() { return std::move(sender_); }
return std::move(sender_); mojo::PlatformHandle PassReceiver() { return std::move(receiver_); }
}
mojo::edk::ScopedInternalPlatformHandle PassReceiver() {
return std::move(receiver_);
}
private: private:
mojo::edk::ScopedInternalPlatformHandle sender_; mojo::PlatformHandle sender_;
mojo::edk::ScopedInternalPlatformHandle receiver_; mojo::PlatformHandle receiver_;
DISALLOW_COPY_AND_ASSIGN(PipePair); DISALLOW_COPY_AND_ASSIGN(PipePair);
}; };
explicit SenderPipe(base::ScopedPlatformFile file); explicit SenderPipe(mojo::PlatformHandle handle);
~SenderPipe(); ~SenderPipe();
enum class Result { kSuccess, kTimeout, kError }; enum class Result { kSuccess, kTimeout, kError };
......
...@@ -31,14 +31,13 @@ SenderPipe::PipePair::PipePair() { ...@@ -31,14 +31,13 @@ SenderPipe::PipePair::PipePair() {
PCHECK(fcntl(fds[0], F_SETNOSIGPIPE, 1) == 0); PCHECK(fcntl(fds[0], F_SETNOSIGPIPE, 1) == 0);
PCHECK(fcntl(fds[1], F_SETNOSIGPIPE, 1) == 0); PCHECK(fcntl(fds[1], F_SETNOSIGPIPE, 1) == 0);
#endif #endif
receiver_.reset(mojo::edk::InternalPlatformHandle(fds[0])); receiver_ = mojo::PlatformHandle(base::ScopedFD(fds[0]));
sender_.reset(mojo::edk::InternalPlatformHandle(fds[1])); sender_ = mojo::PlatformHandle(base::ScopedFD(fds[1]));
} }
SenderPipe::PipePair::PipePair(PipePair&& other) = default; SenderPipe::PipePair::PipePair(PipePair&& other) = default;
SenderPipe::SenderPipe(base::ScopedPlatformFile file) SenderPipe::SenderPipe(mojo::PlatformHandle handle) : file_(handle.TakeFD()) {}
: file_(std::move(file)) {}
SenderPipe::~SenderPipe() = default; SenderPipe::~SenderPipe() = default;
......
...@@ -7,11 +7,11 @@ ...@@ -7,11 +7,11 @@
#include <vector> #include <vector>
#include "build/build_config.h" #include "build/build_config.h"
#include "mojo/edk/embedder/scoped_platform_handle.h" #include "mojo/public/cpp/platform/platform_handle.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#if !defined(OS_MACOSX) #if defined(OS_WIN)
#include "mojo/edk/embedder/platform_channel_pair.h" #include <windows.h>
#endif #endif
namespace heap_profiling { namespace heap_profiling {
...@@ -22,13 +22,10 @@ using Result = SenderPipe::Result; ...@@ -22,13 +22,10 @@ using Result = SenderPipe::Result;
class SenderPipeTest : public testing::Test { class SenderPipeTest : public testing::Test {
public: public:
void SetUp() override { void SetUp() override {
mojo::edk::ScopedInternalPlatformHandle write_handle;
SenderPipe::PipePair pipes; SenderPipe::PipePair pipes;
read_handle_ = pipes.PassReceiver(); read_handle_ = pipes.PassReceiver();
base::ScopedPlatformFile file(pipes.PassSender().release().handle); sender_pipe_.reset(new SenderPipe(pipes.PassSender()));
sender_pipe_.reset(new SenderPipe(std::move(file)));
// A large buffer for both writing and reading. // A large buffer for both writing and reading.
buffer_.resize(64 * 1024); buffer_.resize(64 * 1024);
...@@ -38,21 +35,21 @@ class SenderPipeTest : public testing::Test { ...@@ -38,21 +35,21 @@ class SenderPipeTest : public testing::Test {
void Read(int size) { void Read(int size) {
#if defined(OS_POSIX) #if defined(OS_POSIX)
ssize_t bytes_read = read(read_handle_.get().handle, buffer_.data(), size); ssize_t bytes_read = read(read_handle_.GetFD().get(), buffer_.data(), size);
ASSERT_EQ(size, bytes_read); ASSERT_EQ(size, bytes_read);
#else #else
OVERLAPPED overlapped; OVERLAPPED overlapped;
DWORD bytes_read = 0; DWORD bytes_read = 0;
memset(&overlapped, 0, sizeof(OVERLAPPED)); memset(&overlapped, 0, sizeof(OVERLAPPED));
BOOL result = ::ReadFile(read_handle_.get().handle, buffer_.data(), size, BOOL result = ::ReadFile(read_handle_.GetHandle().Get(), buffer_.data(),
&bytes_read, &overlapped); size, &bytes_read, &overlapped);
ASSERT_TRUE(result); ASSERT_TRUE(result);
ASSERT_EQ(static_cast<DWORD>(size), bytes_read); ASSERT_EQ(static_cast<DWORD>(size), bytes_read);
#endif #endif
} }
private: private:
mojo::edk::ScopedInternalPlatformHandle read_handle_; mojo::PlatformHandle read_handle_;
std::unique_ptr<SenderPipe> sender_pipe_; std::unique_ptr<SenderPipe> sender_pipe_;
std::vector<char> buffer_; std::vector<char> buffer_;
}; };
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "components/services/heap_profiling/public/cpp/sender_pipe.h" #include "components/services/heap_profiling/public/cpp/sender_pipe.h"
#include <windows.h>
#include "base/logging.h" #include "base/logging.h"
#include "base/rand_util.h" #include "base/rand_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
...@@ -69,7 +71,7 @@ SenderPipe::PipePair::PipePair() { ...@@ -69,7 +71,7 @@ SenderPipe::PipePair::PipePair() {
// nothing to do with Send() timeout. // nothing to do with Send() timeout.
nullptr); nullptr);
PCHECK(handle != INVALID_HANDLE_VALUE); PCHECK(handle != INVALID_HANDLE_VALUE);
receiver_.reset(mojo::edk::InternalPlatformHandle(handle)); receiver_ = mojo::PlatformHandle(base::win::ScopedHandle(handle));
// Allow the handle to be inherited by child processes. // Allow the handle to be inherited by child processes.
SECURITY_ATTRIBUTES security_attributes; SECURITY_ATTRIBUTES security_attributes;
...@@ -84,19 +86,19 @@ SenderPipe::PipePair::PipePair() { ...@@ -84,19 +86,19 @@ SenderPipe::PipePair::PipePair() {
SECURITY_SQOS_PRESENT | SECURITY_ANONYMOUS | FILE_FLAG_OVERLAPPED, SECURITY_SQOS_PRESENT | SECURITY_ANONYMOUS | FILE_FLAG_OVERLAPPED,
nullptr); nullptr);
PCHECK(handle != INVALID_HANDLE_VALUE); PCHECK(handle != INVALID_HANDLE_VALUE);
sender_.reset(mojo::edk::InternalPlatformHandle(handle)); sender_ = mojo::PlatformHandle(base::win::ScopedHandle(handle));
// Since a client has connected, ConnectNamedPipe() should return zero and // Since a client has connected, ConnectNamedPipe() should return zero and
// GetLastError() should return ERROR_PIPE_CONNECTED. // GetLastError() should return ERROR_PIPE_CONNECTED.
BOOL result = ConnectNamedPipe(receiver_.get().handle, nullptr); BOOL result = ConnectNamedPipe(receiver_.GetHandle().Get(), nullptr);
DWORD error = GetLastError(); DWORD error = GetLastError();
CHECK((result == 0) && (error == ERROR_PIPE_CONNECTED)); CHECK((result == 0) && (error == ERROR_PIPE_CONNECTED));
} }
SenderPipe::PipePair::PipePair(PipePair&& other) = default; SenderPipe::PipePair::PipePair(PipePair&& other) = default;
SenderPipe::SenderPipe(base::ScopedPlatformFile file) SenderPipe::SenderPipe(mojo::PlatformHandle handle)
: file_(std::move(file)) {} : file_(handle.TakeHandle()) {}
SenderPipe::~SenderPipe() {} SenderPipe::~SenderPipe() {}
......
...@@ -10,8 +10,7 @@ ...@@ -10,8 +10,7 @@
namespace heap_profiling { namespace heap_profiling {
ReceiverPipeBase::ReceiverPipeBase( ReceiverPipeBase::ReceiverPipeBase(mojo::PlatformHandle handle)
mojo::edk::ScopedInternalPlatformHandle handle)
: handle_(std::move(handle)) {} : handle_(std::move(handle)) {}
ReceiverPipeBase::~ReceiverPipeBase() = default; ReceiverPipeBase::~ReceiverPipeBase() = default;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "mojo/edk/embedder/scoped_platform_handle.h" #include "mojo/public/cpp/platform/platform_handle.h"
namespace base { namespace base {
class TaskRunner; class TaskRunner;
...@@ -29,7 +29,7 @@ class ReceiverPipeBase : public base::RefCountedThreadSafe<ReceiverPipeBase> { ...@@ -29,7 +29,7 @@ class ReceiverPipeBase : public base::RefCountedThreadSafe<ReceiverPipeBase> {
protected: protected:
friend class base::RefCountedThreadSafe<ReceiverPipeBase>; friend class base::RefCountedThreadSafe<ReceiverPipeBase>;
explicit ReceiverPipeBase(mojo::edk::ScopedInternalPlatformHandle handle); explicit ReceiverPipeBase(mojo::PlatformHandle handle);
virtual ~ReceiverPipeBase(); virtual ~ReceiverPipeBase();
// Callback that indicates an error has occurred and the connection should // Callback that indicates an error has occurred and the connection should
...@@ -46,7 +46,7 @@ class ReceiverPipeBase : public base::RefCountedThreadSafe<ReceiverPipeBase> { ...@@ -46,7 +46,7 @@ class ReceiverPipeBase : public base::RefCountedThreadSafe<ReceiverPipeBase> {
scoped_refptr<base::TaskRunner> receiver_task_runner_; scoped_refptr<base::TaskRunner> receiver_task_runner_;
scoped_refptr<StreamReceiver> receiver_; scoped_refptr<StreamReceiver> receiver_;
mojo::edk::ScopedInternalPlatformHandle handle_; mojo::PlatformHandle handle_;
}; };
} // namespace heap_profiling } // namespace heap_profiling
......
...@@ -13,12 +13,10 @@ ...@@ -13,12 +13,10 @@
#include "components/services/heap_profiling/public/cpp/sender_pipe.h" #include "components/services/heap_profiling/public/cpp/sender_pipe.h"
#include "components/services/heap_profiling/receiver_pipe.h" #include "components/services/heap_profiling/receiver_pipe.h"
#include "components/services/heap_profiling/stream_receiver.h" #include "components/services/heap_profiling/stream_receiver.h"
#include "mojo/edk/embedder/platform_channel_utils_posix.h"
#include "mojo/edk/embedder/platform_handle.h"
namespace heap_profiling { namespace heap_profiling {
ReceiverPipe::ReceiverPipe(mojo::edk::ScopedInternalPlatformHandle handle) ReceiverPipe::ReceiverPipe(mojo::PlatformHandle handle)
: ReceiverPipeBase(std::move(handle)), : ReceiverPipeBase(std::move(handle)),
controller_(FROM_HERE), controller_(FROM_HERE),
read_buffer_(new char[SenderPipe::kPipeSize]) {} read_buffer_(new char[SenderPipe::kPipeSize]) {}
...@@ -27,18 +25,16 @@ ReceiverPipe::~ReceiverPipe() {} ...@@ -27,18 +25,16 @@ ReceiverPipe::~ReceiverPipe() {}
void ReceiverPipe::StartReadingOnIOThread() { void ReceiverPipe::StartReadingOnIOThread() {
base::MessageLoopCurrentForIO::Get()->WatchFileDescriptor( base::MessageLoopCurrentForIO::Get()->WatchFileDescriptor(
handle_.get().handle, true, base::MessagePumpForIO::WATCH_READ, handle_.GetFD().get(), true, base::MessagePumpForIO::WATCH_READ,
&controller_, this); &controller_, this);
OnFileCanReadWithoutBlocking(handle_.get().handle); OnFileCanReadWithoutBlocking(handle_.GetFD().get());
} }
void ReceiverPipe::OnFileCanReadWithoutBlocking(int fd) { void ReceiverPipe::OnFileCanReadWithoutBlocking(int fd) {
ssize_t bytes_read = 0; ssize_t bytes_read = 0;
do { do {
base::circular_deque<mojo::edk::InternalPlatformHandle> dummy_for_receive;
bytes_read = HANDLE_EINTR( bytes_read = HANDLE_EINTR(
read(handle_.get().handle, read_buffer_.get(), SenderPipe::kPipeSize)); read(handle_.GetFD().get(), read_buffer_.get(), SenderPipe::kPipeSize));
if (bytes_read > 0) { if (bytes_read > 0) {
receiver_task_runner_->PostTask( receiver_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
......
...@@ -18,7 +18,7 @@ namespace heap_profiling { ...@@ -18,7 +18,7 @@ namespace heap_profiling {
class ReceiverPipe : public ReceiverPipeBase, class ReceiverPipe : public ReceiverPipeBase,
public base::MessagePumpForIO::FdWatcher { public base::MessagePumpForIO::FdWatcher {
public: public:
explicit ReceiverPipe(mojo::edk::ScopedInternalPlatformHandle handle); explicit ReceiverPipe(mojo::PlatformHandle handle);
// Must be called on the IO thread. // Must be called on the IO thread.
void StartReadingOnIOThread(); void StartReadingOnIOThread();
......
...@@ -16,12 +16,12 @@ ...@@ -16,12 +16,12 @@
namespace heap_profiling { namespace heap_profiling {
ReceiverPipe::ReceiverPipe(mojo::edk::ScopedInternalPlatformHandle handle) ReceiverPipe::ReceiverPipe(mojo::PlatformHandle handle)
: ReceiverPipeBase(std::move(handle)), : ReceiverPipeBase(std::move(handle)),
read_buffer_(new char[SenderPipe::kPipeSize]) { read_buffer_(new char[SenderPipe::kPipeSize]) {
ZeroOverlapped(); ZeroOverlapped();
base::MessageLoopCurrentForIO::Get()->RegisterIOHandler(handle_.get().handle, base::MessageLoopCurrentForIO::Get()->RegisterIOHandler(
this); handle_.GetHandle().Get(), this);
} }
ReceiverPipe::~ReceiverPipe() {} ReceiverPipe::~ReceiverPipe() {}
...@@ -41,7 +41,7 @@ void ReceiverPipe::ReadUntilBlocking() { ...@@ -41,7 +41,7 @@ void ReceiverPipe::ReadUntilBlocking() {
DCHECK(!read_outstanding_); DCHECK(!read_outstanding_);
read_outstanding_ = this; read_outstanding_ = this;
if (!::ReadFile(handle_.get().handle, read_buffer_.get(), if (!::ReadFile(handle_.GetHandle().Get(), read_buffer_.get(),
SenderPipe::kPipeSize, &bytes_read, &context_.overlapped)) { SenderPipe::kPipeSize, &bytes_read, &context_.overlapped)) {
if (GetLastError() == ERROR_IO_PENDING) { if (GetLastError() == ERROR_IO_PENDING) {
return; return;
......
...@@ -21,7 +21,7 @@ namespace heap_profiling { ...@@ -21,7 +21,7 @@ namespace heap_profiling {
class ReceiverPipe : public ReceiverPipeBase, class ReceiverPipe : public ReceiverPipeBase,
public base::MessagePumpForIO::IOHandler { public base::MessagePumpForIO::IOHandler {
public: public:
explicit ReceiverPipe(mojo::edk::ScopedInternalPlatformHandle handle); explicit ReceiverPipe(mojo::PlatformHandle handle);
// Must be called on the IO thread. // Must be called on the IO thread.
void StartReadingOnIOThread(); void StartReadingOnIOThread();
......
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