Move cpp_common to base and its own namespace.
Looks like in next CL we need more shared bits (e.g. TaskRunner for
the Ftrace parser).
It makes sense to start splitting "base.h" in actual units before it
becomes too late and too painful.
Also turns out that the policy of just not including base headers
in public API headers isn't enough. Protobuf autogenerated .pb.h
headers in fact pull in a different definition of CHECK.
Hence moving our macros to be PERFETTO_CHECK and so on.
Change-Id: I9d340c6a26b94ee54ba45472c78409a432364100
diff --git a/BUILD.gn b/BUILD.gn
index 538ce2f..2b8918b 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -27,7 +27,7 @@
group("tests") {
testonly = true
deps = [
- "//cpp_common:base_unittests",
+ "//base:base_unittests",
"//libftrace:libftrace_unittests",
"//protozero:protozero_unittests",
"//tools/ftrace_proto_gen:ftrace_proto_gen_unittests",
diff --git a/cpp_common/BUILD.gn b/base/BUILD.gn
similarity index 66%
rename from cpp_common/BUILD.gn
rename to base/BUILD.gn
index 1265c9e..81509f8 100644
--- a/cpp_common/BUILD.gn
+++ b/base/BUILD.gn
@@ -12,14 +12,36 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+source_set("base") {
+ sources = [
+ "build_config.h",
+ "logging.h",
+ "scoped_file.h",
+ "task_runner.h",
+ "utils.h",
+ ]
+}
+
+source_set("test_support") {
+ testonly = true
+ deps += [ ":base" ]
+ sources = [
+ "test/test_task_runner.cc",
+ "test/test_task_runner.h",
+ ]
+}
+
executable("base_unittests") {
testonly = true
deps += [
+ ":base",
+ ":test_support",
"//buildtools:gmock",
"//buildtools:gtest",
"//buildtools:gtest_main",
]
sources = [
- "base_unittest.cc",
+ "scoped_file_unittest.cc",
+ "utils_unittest.cc",
]
}
diff --git a/cpp_common/build_config.h b/base/build_config.h
similarity index 92%
rename from cpp_common/build_config.h
rename to base/build_config.h
index d6f01e3..797d68a 100644
--- a/cpp_common/build_config.h
+++ b/base/build_config.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef CPP_COMMON_BUILD_CONFIG_H_
-#define CPP_COMMON_BUILD_CONFIG_H_
+#ifndef PERFETTO_BASE_BUILD_CONFIG_H_
+#define PERFETTO_BASE_BUILD_CONFIG_H_
// DO NOT include this file in public headers (include/) to avoid collisions.
@@ -41,4 +41,4 @@
#error OS not supported (see build_config.h)
#endif
-#endif // CPP_COMMON_BUILD_CONFIG_H_
+#endif // PERFETTO_BASE_BUILD_CONFIG_H_
diff --git a/base/logging.h b/base/logging.h
new file mode 100644
index 0000000..69f79af
--- /dev/null
+++ b/base/logging.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef PERFETTO_BASE_LOGGING_H_
+#define PERFETTO_BASE_LOGGING_H_
+
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#if defined(NDEBUG)
+#define PERFETTO_DCHECK_IS_ON() 0
+#else
+#define PERFETTO_DCHECK_IS_ON() 1
+#include <stdio.h> // For fprintf.
+#include <string.h> // For strerror.
+#endif
+
+#include "base/utils.h"
+
+#if PERFETTO_DCHECK_IS_ON()
+#define PERFETTO_DLOG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)
+#define PERFETTO_DPLOG(x) \
+ PERFETTO_DLOG("%s %s:%d (errno: %d %s)\n", (x), __FILE__, __LINE__, errno, \
+ errno ? strerror(errno) : "")
+#define PERFETTO_DCHECK(x) \
+ do { \
+ if (!__builtin_expect(!!(x), true)) { \
+ PERFETTO_DPLOG("PERFETTO_CHECK(" #x ")"); \
+ abort(); \
+ } \
+ } while (0)
+#else
+#define PERFETTO_DLOG(...) ::perfetto::base::ignore_result(__VA_ARGS__)
+#define PERFETTO_DPLOG(...) ::perfetto::base::ignore_result(__VA_ARGS__)
+#define PERFETTO_DCHECK(x) ::perfetto::base::ignore_result(x)
+#endif // PERFETTO_DCHECK_IS_ON()
+
+#if PERFETTO_DCHECK_IS_ON()
+#define PERFETTO_CHECK(x) PERFETTO_DCHECK(x)
+#else
+#define PERFETTO_CHECK(x) \
+ do { \
+ if (!__builtin_expect(!!(x), true)) \
+ abort(); \
+ } while (0)
+#endif // PERFETTO_DCHECK_IS_ON()
+
+#endif // PERFETTO_BASE_LOGGING_H_
diff --git a/base/scoped_file.h b/base/scoped_file.h
new file mode 100644
index 0000000..83507b4
--- /dev/null
+++ b/base/scoped_file.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef PERFETTO_BASE_SCOPED_FILE_H_
+#define PERFETTO_BASE_SCOPED_FILE_H_
+
+#include <dirent.h>
+#include <unistd.h>
+
+#include "base/logging.h"
+
+namespace perfetto {
+namespace base {
+
+// RAII classes for auto-releasing fds and dirs.
+template <typename T, int (*CloseFunction)(T), T InvalidValue>
+class ScopedResource {
+ public:
+ explicit ScopedResource(T t = InvalidValue) : t_(t) {}
+ ScopedResource(ScopedResource&& other) noexcept {
+ t_ = other.t_;
+ other.t_ = InvalidValue;
+ }
+ ScopedResource& operator=(ScopedResource&& other) {
+ reset(other.t_);
+ other.t_ = InvalidValue;
+ return *this;
+ }
+ T get() const { return t_; }
+ T operator*() const { return t_; }
+ explicit operator bool() const { return t_ != InvalidValue; }
+ void reset(T r = InvalidValue) {
+ if (t_ != InvalidValue) {
+ int res = CloseFunction(t_);
+ PERFETTO_CHECK(res == 0);
+ }
+ t_ = r;
+ }
+ ~ScopedResource() { reset(InvalidValue); }
+
+ private:
+ ScopedResource(const ScopedResource&) = delete;
+ ScopedResource& operator=(const ScopedResource&) = delete;
+
+ T t_;
+};
+
+using ScopedFile = ScopedResource<int, close, -1>;
+using ScopedDir = ScopedResource<DIR*, closedir, nullptr>;
+
+} // namespace base
+} // namespace perfetto
+
+#endif // PERFETTO_BASE_SCOPED_FILE_H_
diff --git a/cpp_common/base_unittest.cc b/base/scoped_file_unittest.cc
similarity index 72%
rename from cpp_common/base_unittest.cc
rename to base/scoped_file_unittest.cc
index 22f5d9c..174f220 100644
--- a/cpp_common/base_unittest.cc
+++ b/base/scoped_file_unittest.cc
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "cpp_common/base.h"
+#include "base/scoped_file.h"
#include <fcntl.h>
#include <unistd.h>
@@ -22,19 +22,35 @@
#include "gtest/gtest.h"
namespace perfetto {
+namespace base {
namespace {
-TEST(ScopedFD, CloseOutOfScope) {
+TEST(ScopedDir, CloseOutOfScope) {
+ DIR* dir_handle = opendir(".");
+ ASSERT_NE(nullptr, dir_handle);
+ int dir_handle_fd = dirfd(dir_handle);
+ ASSERT_GE(dir_handle_fd, 0);
+ {
+ ScopedDir scoped_dir(dir_handle);
+ ASSERT_EQ(dir_handle, scoped_dir.get());
+ ASSERT_TRUE(scoped_dir);
+ }
+ ASSERT_NE(0, close(dir_handle_fd)); // Should fail when closing twice.
+}
+
+TEST(ScopedFile, CloseOutOfScope) {
int raw_fd = open("/dev/null", O_RDONLY);
ASSERT_GE(raw_fd, 0);
{
ScopedFile scoped_file(raw_fd);
- ASSERT_GE(scoped_file.get(), 0);
+ ASSERT_EQ(raw_fd, scoped_file.get());
+ ASSERT_EQ(raw_fd, *scoped_file);
+ ASSERT_TRUE(scoped_file);
}
- ASSERT_NE(0, close(raw_fd)); // close() should fail if the fd is closed.
+ ASSERT_NE(0, close(raw_fd)); // Should fail when closing twice.
}
-TEST(ScopedFD, Reset) {
+TEST(ScopedFile, Reset) {
int raw_fd1 = open("/dev/null", O_RDONLY);
int raw_fd2 = open("/dev/zero", O_RDONLY);
ASSERT_GE(raw_fd1, 0);
@@ -44,7 +60,7 @@
ASSERT_EQ(raw_fd1, scoped_file.get());
scoped_file.reset(raw_fd2);
ASSERT_EQ(raw_fd2, scoped_file.get());
- ASSERT_NE(0, close(raw_fd1)); // close() should fail if the fd is closed.
+ ASSERT_NE(0, close(raw_fd1)); // Should fail when closing twice.
scoped_file.reset();
ASSERT_NE(0, close(raw_fd2));
scoped_file.reset(open("/dev/null", O_RDONLY));
@@ -52,7 +68,7 @@
}
}
-TEST(ScopedFD, MoveCtor) {
+TEST(ScopedFile, MoveCtor) {
int raw_fd1 = open("/dev/null", O_RDONLY);
int raw_fd2 = open("/dev/zero", O_RDONLY);
ASSERT_GE(raw_fd1, 0);
@@ -61,16 +77,18 @@
ScopedFile scoped_file1(ScopedFile{raw_fd1});
ScopedFile scoped_file2(std::move(scoped_file1));
ASSERT_EQ(-1, scoped_file1.get());
+ ASSERT_EQ(-1, *scoped_file1);
+ ASSERT_FALSE(scoped_file1);
ASSERT_EQ(raw_fd1, scoped_file2.get());
scoped_file1.reset(raw_fd2);
ASSERT_EQ(raw_fd2, scoped_file1.get());
}
- ASSERT_NE(0, close(raw_fd1)); // close() should fail if the fd is closed.
+ ASSERT_NE(0, close(raw_fd1)); // Should fail when closing twice.
ASSERT_NE(0, close(raw_fd2));
}
-TEST(ScopedFD, MoveAssignment) {
+TEST(ScopedFile, MoveAssignment) {
int raw_fd1 = open("/dev/null", O_RDONLY);
int raw_fd2 = open("/dev/zero", O_RDONLY);
ASSERT_GE(raw_fd1, 0);
@@ -80,6 +98,7 @@
ScopedFile scoped_file2(raw_fd2);
scoped_file2 = std::move(scoped_file1);
ASSERT_EQ(-1, scoped_file1.get());
+ ASSERT_FALSE(scoped_file1);
ASSERT_EQ(raw_fd1, scoped_file2.get());
ASSERT_NE(0, close(raw_fd2));
@@ -93,7 +112,7 @@
// File descriptors are capabilities and hence can be security critical. A
// failed close() suggests the memory ownership of the file is wrong and we
// might have leaked a capability.
-TEST(ScopedFD, CloseFailureIsFatal) {
+TEST(ScopedFile, CloseFailureIsFatal) {
int raw_fd = open("/dev/null", O_RDONLY);
ASSERT_DEATH(
{
@@ -104,4 +123,5 @@
}
} // namespace
+} // namespace base
} // namespace perfetto
diff --git a/tracing/include/tracing/core/task_runner.h b/base/task_runner.h
similarity index 82%
rename from tracing/include/tracing/core/task_runner.h
rename to base/task_runner.h
index a19a3f9..5cfb1da 100644
--- a/tracing/include/tracing/core/task_runner.h
+++ b/base/task_runner.h
@@ -14,25 +14,19 @@
* limitations under the License.
*/
-#ifndef TRACING_INCLUDE_TRACING_CORE_TASK_RUNNER_PROXY_H_
-#define TRACING_INCLUDE_TRACING_CORE_TASK_RUNNER_PROXY_H_
+#ifndef PERFETTO_BASE_TASK_RUNNER_H_
+#define PERFETTO_BASE_TASK_RUNNER_H_
#include <functional>
namespace perfetto {
+namespace base {
// A generic interface to allow the library clients to interleave the execution
// of the tracing internals in their runtime environment.
// The expectation is that all tasks, which are queued either via PostTask() or
// AddFileDescriptorWatch(), are executed on the same sequence (either on the
// same thread, or on a thread pool that gives sequencing guarantees).
-//
-// Exposed to:
-// Most internal classes under src/.
-//
-// Subclassed by:
-// 1. Library clients.
-// 2. Tests (See test/test_task_runner.h)
// TODO(skyostil): rework this.
// TODO: we should provide a reference implementation that just spins a
@@ -47,6 +41,7 @@
virtual void RemoveFileDescriptorWatch(int fd) = 0;
};
+} // namespace base
} // namespace perfetto
-#endif // TRACING_INCLUDE_TRACING_CORE_TASK_RUNNER_PROXY_H_
+#endif // PERFETTO_BASE_TASK_RUNNER_H_
diff --git a/tracing/src/test/test_task_runner.cc b/base/test/test_task_runner.cc
similarity index 72%
rename from tracing/src/test/test_task_runner.cc
rename to base/test/test_task_runner.cc
index f36919b..7efd300 100644
--- a/tracing/src/test/test_task_runner.cc
+++ b/base/test/test_task_runner.cc
@@ -14,22 +14,21 @@
* limitations under the License.
*/
-#include "tracing/src/test/test_task_runner.h"
+#include "base/test/test_task_runner.h"
#include <stdio.h>
#include <unistd.h>
-#include "cpp_common/base.h"
+#include "base/logging.h"
// TODO: the current implementation quite hacky as it keeps waking up every 1ms.
namespace perfetto {
+namespace base {
-TestTaskRunner::TestTaskRunner() {
- FD_ZERO(&fd_set_);
-}
+TestTaskRunner::TestTaskRunner() = default;
-TestTaskRunner::~TestTaskRunner() {}
+TestTaskRunner::~TestTaskRunner() = default;
void TestTaskRunner::Run() {
while (RunUntilIdle()) {
@@ -43,7 +42,7 @@
closure();
}
- int res = RunFileDescriptorWatches(1);
+ int res = RunFileDescriptorWatches(100);
if (res < 0)
return false;
return true;
@@ -53,19 +52,25 @@
struct timeval timeout;
timeout.tv_usec = (timeout_ms % 1000) * 1000L;
timeout.tv_sec = static_cast<time_t>(timeout_ms / 1000);
- int res = select(FD_SETSIZE, &fd_set_, nullptr, nullptr, &timeout);
+ int max_fd = 0;
+ fd_set fds = {};
+ for (const auto& it : watched_fds_) {
+ FD_SET(it.first, &fds);
+ max_fd = std::max(max_fd, it.first);
+ }
+ int res = select(max_fd + 1, &fds, nullptr, nullptr, &timeout);
+
if (res < 0) {
perror("select() failed");
return false;
}
if (res == 0)
return true; // timeout
-
- for (int fd = 0; fd < FD_SETSIZE; ++fd) {
- if (!FD_ISSET(fd, &fd_set_))
+ for (int fd = 0; fd <= max_fd; ++fd) {
+ if (!FD_ISSET(fd, &fds))
continue;
auto fd_and_callback = watched_fds_.find(fd);
- DCHECK(fd_and_callback != watched_fds_.end());
+ PERFETTO_DCHECK(fd_and_callback != watched_fds_.end());
fd_and_callback->second();
}
return true;
@@ -78,17 +83,16 @@
void TestTaskRunner::AddFileDescriptorWatch(int fd,
std::function<void()> callback) {
- DCHECK(fd > 0);
- DCHECK(watched_fds_.count(fd) == 0);
+ PERFETTO_DCHECK(fd >= 0);
+ PERFETTO_DCHECK(watched_fds_.count(fd) == 0);
watched_fds_.emplace(fd, std::move(callback));
- FD_SET(fd, &fd_set_);
}
void TestTaskRunner::RemoveFileDescriptorWatch(int fd) {
- DCHECK(fd > 0);
- DCHECK(watched_fds_.count(fd) == 1);
+ PERFETTO_DCHECK(fd >= 0);
+ PERFETTO_DCHECK(watched_fds_.count(fd) == 1);
watched_fds_.erase(fd);
- FD_CLR(fd, &fd_set_);
}
+} // namespace base
} // namespace perfetto
diff --git a/tracing/src/test/test_task_runner.h b/base/test/test_task_runner.h
similarity index 95%
rename from tracing/src/test/test_task_runner.h
rename to base/test/test_task_runner.h
index bcc0676..33b37d2 100644
--- a/tracing/src/test/test_task_runner.h
+++ b/base/test/test_task_runner.h
@@ -23,9 +23,10 @@
#include <list>
#include <map>
-#include "tracing/core/task_runner.h"
+#include "base/task_runner.h"
namespace perfetto {
+namespace base {
class TestTaskRunner : public TaskRunner {
public:
@@ -51,9 +52,9 @@
std::list<std::function<void()>> task_queue_;
std::map<int, std::function<void()>> watched_fds_;
- fd_set fd_set_;
};
+} // namespace base
} // namespace perfetto
#endif // TRACING_SRC_TEST_TEST_TASK_RUNNER_H_
diff --git a/base/utils.h b/base/utils.h
new file mode 100644
index 0000000..bd15d99
--- /dev/null
+++ b/base/utils.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef PERFETTO_BASE_UTILS_H_
+#define PERFETTO_BASE_UTILS_H_
+
+#include <errno.h>
+#include <stddef.h>
+
+#define PERFETTO_EINTR(x) \
+ ({ \
+ decltype(x) eintr_wrapper_result; \
+ do { \
+ eintr_wrapper_result = (x); \
+ } while (eintr_wrapper_result == -1 && errno == EINTR); \
+ eintr_wrapper_result; \
+ })
+
+namespace perfetto {
+namespace base {
+
+template <typename T>
+constexpr size_t ArraySize(const T& array) {
+ return sizeof(array) / sizeof(array[0]);
+}
+
+template <typename... T>
+inline void ignore_result(const T&...) {}
+
+} // namespace base
+} // namespace perfetto
+
+#endif // PERFETTO_BASE_UTILS_H_
diff --git a/base/utils_unittest.cc b/base/utils_unittest.cc
new file mode 100644
index 0000000..5495fd7
--- /dev/null
+++ b/base/utils_unittest.cc
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "base/utils.h"
+
+#include <fcntl.h>
+#include <signal.h>
+#include <stdint.h>
+#include <unistd.h>
+
+#include "gtest/gtest.h"
+
+namespace perfetto {
+namespace base {
+namespace {
+
+TEST(Utils, ArraySize) {
+ char char_arr_1[1];
+ char char_arr_4[4];
+ EXPECT_EQ(1u, ArraySize(char_arr_1));
+ EXPECT_EQ(4u, ArraySize(char_arr_4));
+
+ int32_t int32_arr_1[1];
+ int32_t int32_arr_4[4];
+ EXPECT_EQ(1u, ArraySize(int32_arr_1));
+ EXPECT_EQ(4u, ArraySize(int32_arr_4));
+
+ uint64_t int64_arr_1[1];
+ uint64_t int64_arr_4[4];
+ EXPECT_EQ(1u, ArraySize(int64_arr_1));
+ EXPECT_EQ(4u, ArraySize(int64_arr_4));
+
+ char kString[] = "foo";
+ EXPECT_EQ(4u, ArraySize(kString));
+
+ struct Bar {
+ int32_t a;
+ int32_t b;
+ };
+ Bar bar_1[1];
+ Bar bar_4[4];
+ EXPECT_EQ(1u, ArraySize(bar_1));
+ EXPECT_EQ(4u, ArraySize(bar_4));
+}
+
+int pipe_fd[2];
+
+TEST(Utils, EintrWrapper) {
+ ASSERT_EQ(0, pipe(pipe_fd));
+
+ struct sigaction sa = {};
+ struct sigaction old_sa = {};
+
+// Glibc headers for sa_sigaction trigger this.
+#pragma GCC diagnostic push
+#if defined(__clang__)
+#pragma GCC diagnostic ignored "-Wdisabled-macro-expansion"
+#endif
+ sa.sa_sigaction = [](int, siginfo_t*, void*) {};
+#pragma GCC diagnostic pop
+
+ ASSERT_EQ(0, sigaction(SIGUSR2, &sa, &old_sa));
+ int parent_pid = getpid();
+ pid_t pid = fork();
+ ASSERT_NE(-1, pid);
+ if (pid == 0 /* child */) {
+ usleep(5000);
+ kill(parent_pid, SIGUSR2);
+ ignore_result(write(pipe_fd[1], "foo\0", 4));
+ _exit(0);
+ }
+
+ char buf[6] = {};
+ EXPECT_EQ(4, PERFETTO_EINTR(read(pipe_fd[0], buf, sizeof(buf))));
+ EXPECT_STREQ("foo", buf);
+ EXPECT_EQ(0, PERFETTO_EINTR(close(pipe_fd[0])));
+ EXPECT_EQ(0, PERFETTO_EINTR(close(pipe_fd[1])));
+
+ // A 2nd close should fail with the proper errno.
+ int res = close(pipe_fd[0]);
+ auto err = errno;
+ EXPECT_EQ(-1, res);
+ EXPECT_EQ(EBADF, err);
+
+ // Restore the old handler.
+ sigaction(SIGUSR2, &old_sa, nullptr);
+}
+
+} // namespace
+} // namespace base
+} // namespace perfetto
diff --git a/build/BUILD.gn b/build/BUILD.gn
index 3fa8f70..a4527a5 100644
--- a/build/BUILD.gn
+++ b/build/BUILD.gn
@@ -32,7 +32,6 @@
"-Wno-gnu-zero-variadic-macro-arguments",
"-Wno-padded",
"-Wno-reserved-id-macro",
- "-Wno-unknown-warning-option",
"-Wno-unused-parameter",
"-Wno-weak-vtables",
]
@@ -72,7 +71,10 @@
# Color compiler output, see https://github.com/ninja-build/ninja/wiki/FAQ
if (is_clang) {
- cflags += [ "-fcolor-diagnostics" ]
+ cflags += [
+ "-fcolor-diagnostics",
+ "-Wno-unknown-warning-option",
+ ]
}
if (current_cpu == "arm") {
diff --git a/buildtools/BUILD.gn b/buildtools/BUILD.gn
index 627dcb4..e45b31c 100644
--- a/buildtools/BUILD.gn
+++ b/buildtools/BUILD.gn
@@ -40,11 +40,9 @@
"-Wno-shift-sign-overflow",
"-Wno-sign-conversion",
"-Wno-undef",
- "-Wno-unknown-warning-option",
"-Wno-unused-member-function",
"-Wno-used-but-marked-unused",
"-Wno-zero-as-null-pointer-constant",
- "-Wno-weak-vtables",
]
}
@@ -94,18 +92,16 @@
include_dirs = [ "protobuf/src" ]
cflags = [
"-Wno-deprecated",
- "-Wno-unknown-warning-option",
"-Wno-disabled-macro-expansion",
+ "-Wno-int-to-void-pointer-cast",
"-Wno-missing-variable-declarations",
"-Wno-old-style-cast",
- "-Wno-sign-conversion",
- "-Wno-int-to-void-pointer-cast",
+ "-Wno-shorten-64-to-32",
"-Wno-sign-compare",
+ "-Wno-sign-conversion",
+ "-Wno-undef",
"-Wno-zero-as-null-pointer-constant",
]
- if (is_clang) {
- cflags += [ "-Wno-weak-vtables" ]
- }
}
# Configuration used to build libprotobuf_* and the protoc compiler.
@@ -440,7 +436,6 @@
cflags = [
"-Wno-global-constructors",
"-Wno-covered-switch-default",
- "-Wno-weak-vtables",
]
}
diff --git a/cpp_common/base.h b/cpp_common/base.h
deleted file mode 100644
index d612328..0000000
--- a/cpp_common/base.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef CPP_COMMON_BASE_H_
-#define CPP_COMMON_BASE_H_
-
-// DO NOT include this file in public headers (include/) to avoid collisions.
-
-#include <errno.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#if defined(NDEBUG)
-#define DCHECK_IS_ON() 0
-#else
-#define DCHECK_IS_ON() 1
-#endif
-
-#if DCHECK_IS_ON()
-#include <stdio.h> // For fprintf.
-#include <string.h> // For strerror.
-#endif
-
-#define HANDLE_EINTR(x) \
- ({ \
- decltype(x) eintr_wrapper_result; \
- do { \
- eintr_wrapper_result = (x); \
- } while (eintr_wrapper_result == -1 && errno == EINTR); \
- eintr_wrapper_result; \
- })
-
-#if DCHECK_IS_ON()
-#define DLOG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)
-#define DPLOG(x) \
- DLOG("%s %s:%d (errno: %d %s)\n", (x), __FILE__, __LINE__, errno, \
- strerror(errno))
-#define DCHECK(x) \
- do { \
- if (!__builtin_expect(!!(x), true)) { \
- DPLOG("CHECK(" #x ")"); \
- abort(); \
- } \
- } while (0)
-#else
-#define DLOG(...) ::perfetto::ignore_result(__VA_ARGS__)
-#define DPLOG(...) ::perfetto::ignore_result(__VA_ARGS__)
-#define DCHECK(x) ::perfetto::ignore_result(x)
-#endif // DCHECK_IS_ON()
-
-#if DCHECK_IS_ON()
-#define CHECK(x) DCHECK(x)
-#else
-#define CHECK(x) \
- do { \
- if (!__builtin_expect(!!(x), true)) \
- abort(); \
- } while (0)
-#endif // DCHECK_IS_ON()
-
-namespace perfetto {
-
-template <typename T, size_t N>
-char (&ArraySizeHelper(T (&array)[N]))[N];
-#define arraysize(array) (sizeof(::perfetto::ArraySizeHelper(array)))
-
-template <typename... T>
-inline void ignore_result(const T&...) {}
-
-// RAII classes for auto-releasing fd/dirs.
-template <typename T, int (*CloseFunction)(T), T InvalidValue>
-class ScopedResource {
- public:
- explicit ScopedResource(T t = InvalidValue) : t_(t) {}
- ScopedResource(ScopedResource&& other) noexcept {
- t_ = other.t_;
- other.t_ = InvalidValue;
- }
- ScopedResource& operator=(ScopedResource&& other) {
- reset(other.t_);
- other.t_ = InvalidValue;
- return *this;
- }
- T get() const { return t_; }
- void reset(T r = InvalidValue) {
- if (t_ != InvalidValue) {
- int res = CloseFunction(t_);
- CHECK(res == 0);
- }
- t_ = r;
- }
- ~ScopedResource() { reset(InvalidValue); }
-
- private:
- ScopedResource(const ScopedResource&) = delete;
- ScopedResource& operator=(const ScopedResource&) = delete;
-
- T t_;
-};
-
-using ScopedFile = ScopedResource<int, close, -1>;
-
-} // namespace perfetto
-
-#endif // CPP_COMMON_BASE_H_
diff --git a/protozero/BUILD.gn b/protozero/BUILD.gn
index 3badeca..18f2036 100644
--- a/protozero/BUILD.gn
+++ b/protozero/BUILD.gn
@@ -21,7 +21,14 @@
source_set("protozero") {
all_dependent_configs = [ ":protozero_config" ]
configs += [ "//buildtools:googletest_prod_config" ]
+ deps += [ "//base" ]
sources = [
+ "include/protozero/contiguous_memory_range.h",
+ "include/protozero/proto_field_descriptor.h",
+ "include/protozero/proto_utils",
+ "include/protozero/protozero_message.h",
+ "include/protozero/protozero_message_handle.h",
+ "include/protozero/scattered_stream_writer.h",
"src/proto_utils.cc",
"src/protozero_message.cc",
"src/protozero_message_handle.cc",
@@ -34,6 +41,7 @@
deps += [
":protozero",
":testing_messages",
+ "//base",
"//buildtools:gmock",
"//buildtools:gtest",
"//buildtools:gtest_main",
@@ -43,6 +51,7 @@
"src/protozero_message_unittest.cc",
"src/scattered_stream_writer_unittest.cc",
"src/test/fake_scattered_buffer.cc",
+ "src/test/fake_scattered_buffer.h",
"src/test/protozero_conformance_unittest.cc",
]
}
diff --git a/protozero/src/proto_utils.cc b/protozero/src/proto_utils.cc
index 5bdaebc..4e2ead8 100644
--- a/protozero/src/proto_utils.cc
+++ b/protozero/src/proto_utils.cc
@@ -20,10 +20,11 @@
#include <limits>
-#include "cpp_common/base.h"
+#include "base/logging.h"
-#define CHECK_PTR_LE(a, b) \
- CHECK(reinterpret_cast<uintptr_t>(a) <= reinterpret_cast<uintptr_t>(b))
+#define PERFETTO_CHECK_PTR_LE(a, b) \
+ PERFETTO_CHECK(reinterpret_cast<uintptr_t>(a) <= \
+ reinterpret_cast<uintptr_t>(b))
namespace protozero {
namespace proto_utils {
@@ -42,8 +43,8 @@
uint64_t shift = 0;
*value = 0;
do {
- CHECK_PTR_LE(pos, end - 1);
- DCHECK(shift < 64ull);
+ PERFETTO_CHECK_PTR_LE(pos, end - 1);
+ PERFETTO_DCHECK(shift < 64ull);
*value |= static_cast<uint64_t>(*pos & 0x7f) << shift;
shift += 7;
} while (*pos++ & 0x80);
@@ -63,26 +64,26 @@
const uint8_t kFieldTypeMask = (1 << kFieldTypeNumBits) - 1; // 0000 0111;
const uint8_t* pos = start;
- CHECK_PTR_LE(pos, end - 1);
+ PERFETTO_CHECK_PTR_LE(pos, end - 1);
*field_type = static_cast<FieldType>(*pos & kFieldTypeMask);
uint64_t raw_field_id;
pos = ParseVarInt(pos, end, &raw_field_id);
raw_field_id >>= kFieldTypeNumBits;
- DCHECK(raw_field_id <= std::numeric_limits<uint32_t>::max());
+ PERFETTO_DCHECK(raw_field_id <= std::numeric_limits<uint32_t>::max());
*field_id = static_cast<uint32_t>(raw_field_id);
switch (*field_type) {
case kFieldTypeFixed64: {
- CHECK_PTR_LE(pos + sizeof(uint64_t), end);
+ PERFETTO_CHECK_PTR_LE(pos + sizeof(uint64_t), end);
memcpy(field_intvalue, pos, sizeof(uint64_t));
*field_intvalue = BYTE_SWAP_TO_LE64(*field_intvalue);
pos += sizeof(uint64_t);
break;
}
case kFieldTypeFixed32: {
- CHECK_PTR_LE(pos + sizeof(uint32_t), end);
+ PERFETTO_CHECK_PTR_LE(pos + sizeof(uint32_t), end);
uint32_t tmp;
memcpy(&tmp, pos, sizeof(uint32_t));
*field_intvalue = BYTE_SWAP_TO_LE32(tmp);
@@ -96,7 +97,7 @@
case kFieldTypeLengthDelimited: {
pos = ParseVarInt(pos, end, field_intvalue);
pos += *field_intvalue;
- CHECK_PTR_LE(pos, end);
+ PERFETTO_CHECK_PTR_LE(pos, end);
break;
}
}
diff --git a/protozero/src/proto_utils_unittest.cc b/protozero/src/proto_utils_unittest.cc
index 45f03ca..e1b3f2b 100644
--- a/protozero/src/proto_utils_unittest.cc
+++ b/protozero/src/proto_utils_unittest.cc
@@ -18,13 +18,16 @@
#include <limits>
-#include "cpp_common/base.h"
+#include "base/logging.h"
+#include "base/utils.h"
#include "gtest/gtest.h"
namespace protozero {
namespace proto_utils {
namespace {
+using ::perfetto::base::ArraySize;
+
struct VarIntExpectation {
const char* encoded;
size_t encoded_size;
@@ -103,7 +106,7 @@
}
TEST(ProtoUtilsTest, VarIntEncoding) {
- for (size_t i = 0; i < arraysize(kVarIntExpectations); ++i) {
+ for (size_t i = 0; i < ArraySize(kVarIntExpectations); ++i) {
const VarIntExpectation& exp = kVarIntExpectations[i];
uint8_t buf[32];
uint8_t* res = WriteVarInt<uint64_t>(exp.int_value, buf);
@@ -140,7 +143,7 @@
}
TEST(ProtoUtilsTest, VarIntDecoding) {
- for (size_t i = 0; i < arraysize(kVarIntExpectations); ++i) {
+ for (size_t i = 0; i < ArraySize(kVarIntExpectations); ++i) {
const VarIntExpectation& exp = kVarIntExpectations[i];
uint64_t value = std::numeric_limits<uint64_t>::max();
const uint8_t* res = ParseVarInt(
@@ -181,7 +184,7 @@
135, 1234, kFieldTypeLengthDelimited, 131},
};
- for (size_t i = 0; i < arraysize(kFieldExpectations); ++i) {
+ for (size_t i = 0; i < ArraySize(kFieldExpectations); ++i) {
const FieldExpectation& exp = kFieldExpectations[i];
FieldType field_type = kFieldTypeVarInt;
uint32_t field_id = std::numeric_limits<uint32_t>::max();
diff --git a/protozero/src/protoc_plugin/BUILD.gn b/protozero/src/protoc_plugin/BUILD.gn
index 5fe7bf7..7ab92fb 100644
--- a/protozero/src/protoc_plugin/BUILD.gn
+++ b/protozero/src/protoc_plugin/BUILD.gn
@@ -20,5 +20,9 @@
"protozero_plugin.cc",
]
deps += [ "//buildtools:protoc_lib" ]
+ if (is_clang) {
+ # Internal protobuf headers hit this.
+ cflags = [ "-Wno-unreachable-code" ]
+ }
}
} # host_toolchain
diff --git a/protozero/src/protozero_message.cc b/protozero/src/protozero_message.cc
index c87da38..5f7e849 100644
--- a/protozero/src/protozero_message.cc
+++ b/protozero/src/protozero_message.cc
@@ -18,7 +18,7 @@
#include <type_traits>
-#include "cpp_common/base.h"
+#include "base/logging.h"
#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__
// The memcpy() for float and double below needs to be adjusted if we want to
@@ -73,7 +73,7 @@
if (nested_message_)
EndNestedMessage();
- DCHECK(size < proto_utils::kMaxMessageLength);
+ PERFETTO_DCHECK(size < proto_utils::kMaxMessageLength);
// Write the proto preamble (field id, type and length of the field).
uint8_t buffer[proto_utils::kMaxSimpleFieldEncodedSize];
uint8_t* pos = buffer;
@@ -94,10 +94,10 @@
// redundant varint encoding.
if (size_field_.is_valid()) {
#if PROTOZERO_ENABLE_HANDLE_DEBUGGING()
- DCHECK(!sealed_);
+ PERFETTO_DCHECK(!sealed_);
#endif
- DCHECK(size_ < proto_utils::kMaxMessageLength);
- DCHECK(proto_utils::kMessageLengthFieldSize == size_field_.size());
+ PERFETTO_DCHECK(size_ < proto_utils::kMaxMessageLength);
+ PERFETTO_DCHECK(proto_utils::kMessageLengthFieldSize == size_field_.size());
proto_utils::WriteRedundantVarInt(
static_cast<uint32_t>(size_ - size_already_written_),
size_field_.begin);
@@ -125,7 +125,7 @@
WriteToStream(data, data_end);
message->Reset(stream_writer_);
- CHECK(nesting_depth_ < kMaxNestingDepth);
+ PERFETTO_CHECK(nesting_depth_ < kMaxNestingDepth);
message->nesting_depth_ = nesting_depth_ + 1;
// The length of the nested message cannot be known upfront. So right now
diff --git a/protozero/src/protozero_message_handle.cc b/protozero/src/protozero_message_handle.cc
index a072771..d48f57b 100644
--- a/protozero/src/protozero_message_handle.cc
+++ b/protozero/src/protozero_message_handle.cc
@@ -18,7 +18,7 @@
#include <utility>
-#include "cpp_common/base.h"
+#include "base/logging.h"
#include "protozero/protozero_message.h"
namespace protozero {
diff --git a/protozero/src/protozero_message_unittest.cc b/protozero/src/protozero_message_unittest.cc
index 0d9d928..5d23818 100644
--- a/protozero/src/protozero_message_unittest.cc
+++ b/protozero/src/protozero_message_unittest.cc
@@ -21,7 +21,7 @@
#include <utility>
#include <vector>
-#include "cpp_common/base.h"
+#include "base/logging.h"
#include "gtest/gtest.h"
#include "protozero/src/test/fake_scattered_buffer.h"
@@ -306,8 +306,8 @@
ASSERT_EQ(0x90u, msg3_size[0]); // |msg3| should be finalized at this point.
#if PROTOZERO_ENABLE_HANDLE_DEBUGGING()
- // In developer builds w/ DCHECK on a finalized message should invalidate the
- // handle, in order to early catch bugs in the client code.
+ // In developer builds w/ PERFETTO_DCHECK on a finalized message should
+ // invalidate the handle, in order to early catch bugs in the client code.
FakeRootMessage* msg4 = NewMessage();
ProtoZeroMessageHandle<FakeRootMessage> handle4(msg4);
ASSERT_EQ(msg4, &*handle4);
diff --git a/protozero/src/scattered_stream_writer.cc b/protozero/src/scattered_stream_writer.cc
index c0dfaec..3dc738d 100644
--- a/protozero/src/scattered_stream_writer.cc
+++ b/protozero/src/scattered_stream_writer.cc
@@ -18,7 +18,7 @@
#include <algorithm>
-#include "cpp_common/base.h"
+#include "base/logging.h"
namespace protozero {
@@ -34,7 +34,7 @@
void ScatteredStreamWriter::Reset(ContiguousMemoryRange range) {
cur_range_ = range;
write_ptr_ = range.begin;
- DCHECK(write_ptr_ < cur_range_.end);
+ PERFETTO_DCHECK(write_ptr_ < cur_range_.end);
}
void ScatteredStreamWriter::Extend() {
@@ -61,7 +61,7 @@
// Assume the reservations are always < Delegate::GetNewBuffer().size(),
// so that one single call to Extend() will definitely give enough headroom.
Extend();
- DCHECK(write_ptr_ + size <= cur_range_.end);
+ PERFETTO_DCHECK(write_ptr_ + size <= cur_range_.end);
}
uint8_t* begin = write_ptr_;
write_ptr_ += size;
diff --git a/protozero/src/scattered_stream_writer_unittest.cc b/protozero/src/scattered_stream_writer_unittest.cc
index f47834c..d1d37e1 100644
--- a/protozero/src/scattered_stream_writer_unittest.cc
+++ b/protozero/src/scattered_stream_writer_unittest.cc
@@ -20,7 +20,7 @@
#include <memory>
-#include "cpp_common/base.h"
+#include "base/logging.h"
#include "gtest/gtest.h"
#include "protozero/src/test/fake_scattered_buffer.h"
diff --git a/tracing/BUILD.gn b/tracing/BUILD.gn
index 443f40a..4f283cc 100644
--- a/tracing/BUILD.gn
+++ b/tracing/BUILD.gn
@@ -18,8 +18,16 @@
source_set("tracing") {
all_dependent_configs = [ ":tracing_config" ]
+ deps += [ "//base" ]
sources = [
+ "include/tracing/core/basic_types.h",
+ "include/tracing/core/data_source_config.h",
+ "include/tracing/core/data_source_descriptor.h",
+ "include/tracing/core/producer.h",
+ "include/tracing/core/service.h",
+ "include/tracing/core/shared_memory.h",
"src/core/service_impl.cc",
+ "src/core/service_impl.h",
]
}
@@ -27,6 +35,8 @@
testonly = true
deps += [
":tracing",
+ "//base",
+ "//base:test_support",
"//buildtools:gmock",
"//buildtools:gtest",
"//buildtools:gtest_main",
@@ -34,7 +44,7 @@
sources = [
"src/core/service_impl_unittest.cc",
"src/test/test_shared_memory.cc",
- "src/test/test_task_runner.cc",
+ "src/test/test_shared_memory.h",
]
}
diff --git a/tracing/include/tracing/core/service.h b/tracing/include/tracing/core/service.h
index 5553479..ebbe1c3 100644
--- a/tracing/include/tracing/core/service.h
+++ b/tracing/include/tracing/core/service.h
@@ -25,10 +25,13 @@
namespace perfetto {
+namespace base {
+class TaskRunner;
+} // namespace base
+
class DataSourceConfig;
class DataSourceDescriptor;
class Producer;
-class TaskRunner;
// TODO: for the moment this assumes that all the calls hapen on the same
// thread/sequence. Not sure this will be the case long term in Chrome.
@@ -78,7 +81,7 @@
// Implemented in src/core/service_impl.cc .
static std::unique_ptr<Service> CreateInstance(
std::unique_ptr<SharedMemory::Factory>,
- TaskRunner*);
+ base::TaskRunner*);
virtual ~Service() = default;
diff --git a/tracing/src/core/service_impl.cc b/tracing/src/core/service_impl.cc
index 8fd3a03..08192cc 100644
--- a/tracing/src/core/service_impl.cc
+++ b/tracing/src/core/service_impl.cc
@@ -18,11 +18,11 @@
#include <inttypes.h>
-#include "cpp_common/base.h"
+#include "base/logging.h"
+#include "base/task_runner.h"
#include "tracing/core/data_source_config.h"
#include "tracing/core/producer.h"
#include "tracing/core/shared_memory.h"
-#include "tracing/core/task_runner.h"
namespace perfetto {
@@ -35,15 +35,15 @@
// static
std::unique_ptr<Service> Service::CreateInstance(
std::unique_ptr<SharedMemory::Factory> shm_factory,
- TaskRunner* task_runner) {
+ base::TaskRunner* task_runner) {
return std::unique_ptr<Service>(
new ServiceImpl(std::move(shm_factory), task_runner));
}
ServiceImpl::ServiceImpl(std::unique_ptr<SharedMemory::Factory> shm_factory,
- TaskRunner* task_runner)
+ base::TaskRunner* task_runner)
: shm_factory_(std::move(shm_factory)), task_runner_(task_runner) {
- DCHECK(task_runner_);
+ PERFETTO_DCHECK(task_runner_);
}
ServiceImpl::~ServiceImpl() {
@@ -57,14 +57,14 @@
std::unique_ptr<ProducerEndpointImpl> endpoint(new ProducerEndpointImpl(
id, this, task_runner_, producer, std::move(shared_memory)));
auto it_and_inserted = producers_.emplace(id, endpoint.get());
- DCHECK(it_and_inserted.second);
+ PERFETTO_DCHECK(it_and_inserted.second);
task_runner_->PostTask(std::bind(&Producer::OnConnect, endpoint->producer(),
id, endpoint->shared_memory()));
return std::move(endpoint);
}
void ServiceImpl::DisconnectProducer(ProducerID id) {
- DCHECK(producers_.count(id));
+ PERFETTO_DCHECK(producers_.count(id));
producers_.erase(id);
}
@@ -82,7 +82,7 @@
ServiceImpl::ProducerEndpointImpl::ProducerEndpointImpl(
ProducerID id,
ServiceImpl* service,
- TaskRunner* task_runner,
+ base::TaskRunner* task_runner,
Producer* producer,
std::unique_ptr<SharedMemory> shared_memory)
: id_(id),
@@ -104,33 +104,36 @@
const DataSourceDescriptor&,
RegisterDataSourceCallback callback) {
const DataSourceID dsid = ++last_data_source_id_;
- DLOG("[ServiceImpl] RegisterDataSource from producer %" PRIu64, id_);
+ PERFETTO_DLOG("[ServiceImpl] RegisterDataSource from producer %" PRIu64, id_);
task_runner_->PostTask(std::bind(std::move(callback), dsid));
// TODO implement the bookkeeping logic.
}
void ServiceImpl::ProducerEndpointImpl::UnregisterDataSource(
DataSourceID dsid) {
- DLOG("[ServiceImpl] UnregisterDataSource(%" PRIu64 ") from producer %" PRIu64,
- dsid, id_);
- CHECK(dsid);
+ PERFETTO_DLOG("[ServiceImpl] UnregisterDataSource(%" PRIu64
+ ") from producer %" PRIu64,
+ dsid, id_);
+ PERFETTO_CHECK(dsid);
// TODO implement the bookkeeping logic.
return;
}
void ServiceImpl::ProducerEndpointImpl::NotifyPageAcquired(uint32_t page) {
- DLOG("[ServiceImpl] NotifyPageAcquired(%" PRIu32 ") from producer %" PRIu64,
- page, id_);
+ PERFETTO_DLOG("[ServiceImpl] NotifyPageAcquired(%" PRIu32
+ ") from producer %" PRIu64,
+ page, id_);
// TODO implement the bookkeeping logic.
return;
}
void ServiceImpl::ProducerEndpointImpl::NotifyPageReleased(uint32_t page) {
- DLOG("[ServiceImpl] NotifyPageReleased(%" PRIu32 ") from producer %" PRIu64,
- page, id_);
- DCHECK(shared_memory_);
- DLOG("[ServiceImpl] Reading Shared memory: \"%s\"",
- reinterpret_cast<const char*>(shared_memory_->start()));
+ PERFETTO_DLOG("[ServiceImpl] NotifyPageReleased(%" PRIu32
+ ") from producer %" PRIu64,
+ page, id_);
+ PERFETTO_DCHECK(shared_memory_);
+ PERFETTO_DLOG("[ServiceImpl] Reading Shared memory: \"%s\"",
+ reinterpret_cast<const char*>(shared_memory_->start()));
// TODO implement the bookkeeping logic.
return;
}
diff --git a/tracing/src/core/service_impl.h b/tracing/src/core/service_impl.h
index 0ddad86..ee044e0 100644
--- a/tracing/src/core/service_impl.h
+++ b/tracing/src/core/service_impl.h
@@ -26,15 +26,19 @@
namespace perfetto {
+namespace base {
+class TaskRunner;
+} // namespace base
+
class DataSourceConfig;
class Producer;
class SharedMemory;
-class TaskRunner;
// The tracing service business logic.
class ServiceImpl : public Service {
public:
- explicit ServiceImpl(std::unique_ptr<SharedMemory::Factory>, TaskRunner*);
+ explicit ServiceImpl(std::unique_ptr<SharedMemory::Factory>,
+ base::TaskRunner*);
~ServiceImpl() override;
// Called by the ProducerEndpointImpl dtor.
@@ -54,7 +58,7 @@
public:
ProducerEndpointImpl(ProducerID,
ServiceImpl*,
- TaskRunner*,
+ base::TaskRunner*,
Producer*,
std::unique_ptr<SharedMemory>);
~ProducerEndpointImpl() override;
@@ -77,7 +81,7 @@
ProducerID const id_;
ServiceImpl* const service_;
- TaskRunner* const task_runner_;
+ base::TaskRunner* const task_runner_;
Producer* producer_;
std::unique_ptr<SharedMemory> shared_memory_;
DataSourceID last_data_source_id_ = 0;
@@ -87,7 +91,7 @@
ServiceImpl& operator=(const ServiceImpl&) = delete;
std::unique_ptr<SharedMemory::Factory> shm_factory_;
- TaskRunner* const task_runner_;
+ base::TaskRunner* const task_runner_;
ProducerID last_producer_id_ = 0;
std::map<ProducerID, ProducerEndpointImpl*> producers_;
};
diff --git a/tracing/src/core/service_impl_unittest.cc b/tracing/src/core/service_impl_unittest.cc
index dccf03c..d2def94 100644
--- a/tracing/src/core/service_impl_unittest.cc
+++ b/tracing/src/core/service_impl_unittest.cc
@@ -18,6 +18,7 @@
#include <string.h>
+#include "base/test/test_task_runner.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "tracing/core/data_source_config.h"
@@ -25,7 +26,6 @@
#include "tracing/core/producer.h"
#include "tracing/core/shared_memory.h"
#include "tracing/src/test/test_shared_memory.h"
-#include "tracing/src/test/test_task_runner.h"
namespace perfetto {
namespace {
@@ -47,7 +47,7 @@
};
TEST(ServiceImpl, RegisterAndUnregister) {
- TestTaskRunner task_runner;
+ base::TestTaskRunner task_runner;
auto shm_factory =
std::unique_ptr<SharedMemory::Factory>(new TestSharedMemory::Factory());
std::unique_ptr<ServiceImpl> svc(static_cast<ServiceImpl*>(
diff --git a/tracing/src/test/test_shared_memory.cc b/tracing/src/test/test_shared_memory.cc
index 870ac27..6bda050 100644
--- a/tracing/src/test/test_shared_memory.cc
+++ b/tracing/src/test/test_shared_memory.cc
@@ -18,7 +18,7 @@
#include <string.h>
-#include "cpp_common/base.h"
+#include "base/logging.h"
namespace perfetto {