Commit 60dfcf2f authored by Stephen Nusko's avatar Stephen Nusko Committed by Commit Bot

Add fake typed TRACE_EVENT macros for IOS and NACL builds.

This allows users to not care if tracing is supported on their system.

Bug: 916074
Change-Id: I69aa8178bb19f1a65186a2aba4f08699b6ba6ee3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1953210Reviewed-by: default avatarStephen Nusko <nuskos@chromium.org>
Reviewed-by: default avatarEric Seckler <eseckler@chromium.org>
Commit-Queue: Stephen Nusko <nuskos@chromium.org>
Auto-Submit: Stephen Nusko <nuskos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#731514}
parent 83853c21
...@@ -17,14 +17,42 @@ source_set("traced_process") { ...@@ -17,14 +17,42 @@ source_set("traced_process") {
public_deps = [ "//services/tracing/public/mojom" ] public_deps = [ "//services/tracing/public/mojom" ]
if (!is_nacl && !is_ios) { deps = [ ":cpp" ]
deps = [ ":cpp" ]
}
} }
# On IOS and NACL we don't support tracing so we only include the minimum needed
# to support a fake typed TRACE_EVENT macro. However this means we don't have
# any .cc files and thus on iOS and NaCl it needs to be a source_set and not a
# component. |tracing_lib_type| decides which version to build.
if (!is_nacl && !is_ios) { if (!is_nacl && !is_ios) {
component("cpp") { tracing_lib_type = "component"
sources = [ } else {
tracing_lib_type = "source_set"
}
target(tracing_lib_type, "cpp") {
sources = [
"perfetto/event_context.h",
"perfetto/macros.h",
"perfetto/macros_internal.h",
]
defines = [ "IS_TRACING_CPP_IMPL" ]
output_name = "tracing_cpp"
configs += [ "//build/config/compiler:wexit_time_destructors" ]
public_deps = [
"//base",
"//third_party/perfetto:libperfetto",
]
deps = [ "//third_party/perfetto/include/perfetto/protozero" ]
all_dependent_configs = [ "//third_party/perfetto/gn:public_config" ]
if (!is_nacl && !is_ios) {
sources += [
"base_agent.cc", "base_agent.cc",
"base_agent.h", "base_agent.h",
"perfetto/dummy_producer.cc", "perfetto/dummy_producer.cc",
...@@ -40,9 +68,7 @@ if (!is_nacl && !is_ios) { ...@@ -40,9 +68,7 @@ if (!is_nacl && !is_ios) {
"perfetto/java_heap_profiler/hprof_parser_android.h", "perfetto/java_heap_profiler/hprof_parser_android.h",
"perfetto/java_heap_profiler/java_heap_profiler_android.cc", "perfetto/java_heap_profiler/java_heap_profiler_android.cc",
"perfetto/java_heap_profiler/java_heap_profiler_android.h", "perfetto/java_heap_profiler/java_heap_profiler_android.h",
"perfetto/macros.h",
"perfetto/macros_internal.cc", "perfetto/macros_internal.cc",
"perfetto/macros_internal.h",
"perfetto/perfetto_config.cc", "perfetto/perfetto_config.cc",
"perfetto/perfetto_config.h", "perfetto/perfetto_config.h",
"perfetto/perfetto_producer.cc", "perfetto/perfetto_producer.cc",
...@@ -79,24 +105,14 @@ if (!is_nacl && !is_ios) { ...@@ -79,24 +105,14 @@ if (!is_nacl && !is_ios) {
"tracing_features.h", "tracing_features.h",
] ]
defines = [ "IS_TRACING_CPP_IMPL" ] public_deps += [
output_name = "tracing_cpp"
configs += [ "//build/config/compiler:wexit_time_destructors" ]
public_deps = [
"//base",
"//components/tracing:startup_tracing", "//components/tracing:startup_tracing",
"//mojo/public/cpp/bindings", "//mojo/public/cpp/bindings",
"//services/tracing/public/mojom", "//services/tracing/public/mojom",
"//third_party/perfetto:libperfetto",
] ]
all_dependent_configs = [ "//third_party/perfetto/gn:public_config" ] deps += [
deps = [
"//build:chromecast_buildflags", "//build:chromecast_buildflags",
"//third_party/perfetto/include/perfetto/protozero",
"//third_party/perfetto/protos/perfetto/trace/chrome:minimal_complete_lite", "//third_party/perfetto/protos/perfetto/trace/chrome:minimal_complete_lite",
] ]
...@@ -122,5 +138,5 @@ if (!is_nacl && !is_ios) { ...@@ -122,5 +138,5 @@ if (!is_nacl && !is_ios) {
# stack_unwinder_android.cc overrides the dl_unwind_find_exidx function. # stack_unwinder_android.cc overrides the dl_unwind_find_exidx function.
all_dependent_configs += [ ":wrap_find_exidx" ] all_dependent_configs += [ ":wrap_find_exidx" ]
} }
} } # !is_ios && !is_nacl
} # !is_nacl && !is_ios }
...@@ -8,6 +8,11 @@ ...@@ -8,6 +8,11 @@
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "services/tracing/public/cpp/perfetto/macros_internal.h" #include "services/tracing/public/cpp/perfetto/macros_internal.h"
// Needed not for this file but for every user of the TRACE_EVENT macros for the
// lambda definition. So included here for convenience.
#include "services/tracing/public/cpp/perfetto/event_context.h"
#include "third_party/perfetto/protos/perfetto/trace/track_event/track_event.pbzero.h"
#if defined(TRACE_EVENT_BEGIN) #if defined(TRACE_EVENT_BEGIN)
#error "Another copy of perfetto tracing macros have been included" #error "Another copy of perfetto tracing macros have been included"
#endif #endif
......
...@@ -5,14 +5,18 @@ ...@@ -5,14 +5,18 @@
#ifndef SERVICES_TRACING_PUBLIC_CPP_PERFETTO_MACROS_INTERNAL_H_ #ifndef SERVICES_TRACING_PUBLIC_CPP_PERFETTO_MACROS_INTERNAL_H_
#define SERVICES_TRACING_PUBLIC_CPP_PERFETTO_MACROS_INTERNAL_H_ #define SERVICES_TRACING_PUBLIC_CPP_PERFETTO_MACROS_INTERNAL_H_
#include "base/component_export.h" #include "build/build_config.h"
#include "base/trace_event/trace_event.h"
#include "services/tracing/public/cpp/perfetto/trace_event_data_source.h"
namespace perfetto { namespace perfetto {
class TrackEventContext; class EventContext;
} }
#if !defined(OS_IOS) && !defined(OS_NACL)
#include "base/component_export.h"
#include "base/trace_event/trace_event.h"
#include "services/tracing/public/cpp/perfetto/trace_event_data_source.h"
namespace tracing { namespace tracing {
namespace internal { namespace internal {
base::Optional<base::trace_event::TraceEvent> COMPONENT_EXPORT(TRACING_CPP) base::Optional<base::trace_event::TraceEvent> COMPONENT_EXPORT(TRACING_CPP)
...@@ -24,7 +28,7 @@ base::Optional<base::trace_event::TraceEvent> COMPONENT_EXPORT(TRACING_CPP) ...@@ -24,7 +28,7 @@ base::Optional<base::trace_event::TraceEvent> COMPONENT_EXPORT(TRACING_CPP)
// A simple function that will add the TraceEvent requested and will call the // A simple function that will add the TraceEvent requested and will call the
// |argument_func| after the track_event has been filled in. // |argument_func| after the track_event has been filled in.
template < template <
typename TrackEventArgumentFunction = void (*)(perfetto::TrackEventContext)> typename TrackEventArgumentFunction = void (*)(perfetto::EventContext)>
static inline base::trace_event::TraceEventHandle AddTraceEvent( static inline base::trace_event::TraceEventHandle AddTraceEvent(
char phase, char phase,
const unsigned char* category_group_enabled, const unsigned char* category_group_enabled,
...@@ -87,4 +91,33 @@ static inline base::trace_event::TraceEventHandle AddTraceEvent( ...@@ -87,4 +91,33 @@ static inline base::trace_event::TraceEventHandle AddTraceEvent(
return 0; \ return 0; \
}()}; }()};
#else // !defined(OS_IOS) && !defined(OS_NACL)
// Tracing isn't supported on IOS or NACL so we just black hole all the
// parameters into a function that doesn't do anything. This ensures that no
// warnings about unused parameters are generated.
namespace tracing {
namespace internal {
template <
typename TrackEventArgumentFunction = void (*)(perfetto::EventContext)>
static inline base::trace_event::TraceEventHandle AddTraceEvent(
char,
const unsigned char*,
const char*,
unsigned int,
TrackEventArgumentFunction) {
return {0, 0, 0};
}
} // namespace internal
} // namespace tracing
#define TRACING_INTERNAL_ADD_TRACE_EVENT(phase, category, name, flags, ...) \
tracing::internal::AddTraceEvent(phase, nullptr, name, flags, ##__VA_ARGS__);
#define TRACING_INTERNAL_SCOPED_ADD_TRACE_EVENT(category, name, ...) \
TRACING_INTERNAL_ADD_TRACE_EVENT('B', category, name, TRACE_EVENT_FLAG_NONE, \
##__VA_ARGS__);
#endif // else of !defined(OS_IOS) && !defined(OS_NACL)
#endif // SERVICES_TRACING_PUBLIC_CPP_PERFETTO_MACROS_INTERNAL_H_ #endif // SERVICES_TRACING_PUBLIC_CPP_PERFETTO_MACROS_INTERNAL_H_
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