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