shared_lib: Split consumer ABI by backend
Separate ABIs are used for in process and system backend so that when
static linking, dead code elimination can remove unused code.
Bug: 184929776
Change-Id: I9537873c25e0a65aabf2d2594310299066f75cb8
diff --git a/include/perfetto/public/abi/tracing_session_abi.h b/include/perfetto/public/abi/tracing_session_abi.h
index bb044d9..6055ad0 100644
--- a/include/perfetto/public/abi/tracing_session_abi.h
+++ b/include/perfetto/public/abi/tracing_session_abi.h
@@ -21,7 +21,6 @@
#include <stddef.h>
#include <stdint.h>
-#include "perfetto/public/abi/backend_type.h"
#include "perfetto/public/abi/export.h"
#ifdef __cplusplus
@@ -32,7 +31,10 @@
struct PerfettoTracingSessionImpl;
PERFETTO_SDK_EXPORT struct PerfettoTracingSessionImpl*
-PerfettoTracingSessionCreate(PerfettoBackendTypes backend);
+PerfettoTracingSessionSystemCreate(void);
+
+PERFETTO_SDK_EXPORT struct PerfettoTracingSessionImpl*
+PerfettoTracingSessionInProcessCreate(void);
PERFETTO_SDK_EXPORT void PerfettoTracingSessionSetup(
struct PerfettoTracingSessionImpl*,
diff --git a/include/perfetto/public/tracing_session.h b/include/perfetto/public/tracing_session.h
new file mode 100644
index 0000000..9b8b69b
--- /dev/null
+++ b/include/perfetto/public/tracing_session.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2023 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 INCLUDE_PERFETTO_PUBLIC_TRACING_SESSION_H_
+#define INCLUDE_PERFETTO_PUBLIC_TRACING_SESSION_H_
+
+#include "perfetto/public/abi/backend_type.h"
+#include "perfetto/public/abi/tracing_session_abi.h"
+
+static inline struct PerfettoTracingSessionImpl* PerfettoTracingSessionCreate(
+ PerfettoBackendTypes backend) {
+ if (backend == PERFETTO_BACKEND_IN_PROCESS) {
+ return PerfettoTracingSessionInProcessCreate();
+ }
+ if (backend == PERFETTO_BACKEND_SYSTEM) {
+ return PerfettoTracingSessionSystemCreate();
+ }
+ return nullptr;
+}
+
+#endif // INCLUDE_PERFETTO_PUBLIC_TRACING_SESSION_H_
diff --git a/src/shared_lib/tracing_session.cc b/src/shared_lib/tracing_session.cc
index 313a88d..a77477f 100644
--- a/src/shared_lib/tracing_session.cc
+++ b/src/shared_lib/tracing_session.cc
@@ -19,22 +19,19 @@
#include <condition_variable>
#include <mutex>
-#include "perfetto/tracing/backend_type.h"
#include "perfetto/tracing/tracing.h"
#include "protos/perfetto/config/trace_config.gen.h"
-struct PerfettoTracingSessionImpl* PerfettoTracingSessionCreate(
- PerfettoBackendTypes backend) {
- uint32_t backend_type = 0;
- if (backend & PERFETTO_BACKEND_IN_PROCESS) {
- backend_type |= perfetto::kInProcessBackend;
- }
- if (backend & PERFETTO_BACKEND_SYSTEM) {
- backend_type |= perfetto::kSystemBackend;
- }
+struct PerfettoTracingSessionImpl* PerfettoTracingSessionSystemCreate() {
std::unique_ptr<perfetto::TracingSession> tracing_session =
- perfetto::Tracing::NewTrace(
- static_cast<perfetto::BackendType>(backend_type));
+ perfetto::Tracing::NewTrace(perfetto::kSystemBackend);
+ return reinterpret_cast<struct PerfettoTracingSessionImpl*>(
+ tracing_session.release());
+}
+
+struct PerfettoTracingSessionImpl* PerfettoTracingSessionInProcessCreate() {
+ std::unique_ptr<perfetto::TracingSession> tracing_session =
+ perfetto::Tracing::NewTrace(perfetto::kInProcessBackend);
return reinterpret_cast<struct PerfettoTracingSessionImpl*>(
tracing_session.release());
}