aboutsummaryrefslogtreecommitdiff
path: root/include/perfetto/tracing/data_source.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/perfetto/tracing/data_source.h')
-rw-r--r--include/perfetto/tracing/data_source.h48
1 files changed, 38 insertions, 10 deletions
diff --git a/include/perfetto/tracing/data_source.h b/include/perfetto/tracing/data_source.h
index 1a2f57e2d..77804067d 100644
--- a/include/perfetto/tracing/data_source.h
+++ b/include/perfetto/tracing/data_source.h
@@ -45,6 +45,14 @@
#include "protos/perfetto/trace/trace_packet.pbzero.h"
+// PERFETTO_COMPONENT_EXPORT is used to mark symbols in Perfetto's headers
+// (typically templates) that are defined by the user outside of Perfetto and
+// should be made visible outside the current module. (e.g., in Chrome's
+// component build).
+#if !defined(PERFETTO_COMPONENT_EXPORT)
+#define PERFETTO_COMPONENT_EXPORT
+#endif
+
namespace perfetto {
namespace internal {
class TracingMuxerImpl;
@@ -188,6 +196,11 @@ class DataSource : public DataSourceBase {
tls_inst_->trace_writer->Flush(cb);
}
+ // Returns the number of bytes written on the current thread by the current
+ // data-source since its creation.
+ // This can be useful for splitting protos that might grow very large.
+ uint64_t written() { return tls_inst_->trace_writer->written(); }
+
// Returns a RAII handle to access the data source instance, guaranteeing
// that it won't be deleted on another thread (because of trace stopping)
// while accessing it from within the Trace() lambda.
@@ -370,7 +383,8 @@ class DataSource : public DataSourceBase {
// tracing is enabled and the data source is selected.
// This must be called after Tracing::Initialize().
// Can return false to signal failure if attemping to register more than
- // kMaxDataSources (32) data sources types.
+ // kMaxDataSources (32) data sources types or if tracing hasn't been
+ // initialized.
static bool Register(const DataSourceDescriptor& descriptor) {
// Silences -Wunused-variable warning in case the trace method is not used
// by the translation unit that declares the data source.
@@ -381,6 +395,8 @@ class DataSource : public DataSourceBase {
return std::unique_ptr<DataSourceBase>(new DataSourceType());
};
auto* tracing_impl = internal::TracingMuxer::Get();
+ if (!tracing_impl)
+ return false;
return tracing_impl->RegisterDataSource(descriptor, factory,
&static_state_);
}
@@ -459,14 +475,26 @@ thread_local internal::DataSourceThreadLocalState* DataSource<T, D>::tls_state_;
#define PERFETTO_INTERNAL_SWALLOW_SEMICOLON() \
extern int perfetto_internal_unused
-// Not needed -- only here for backwards compatibility.
-// TODO(skyostil): Remove this macro.
-#define PERFETTO_DECLARE_DATA_SOURCE_STATIC_MEMBERS(...) \
- PERFETTO_INTERNAL_SWALLOW_SEMICOLON()
-
-// Not needed -- only here for backwards compatibility.
-// TODO(skyostil): Remove this macro.
-#define PERFETTO_DEFINE_DATA_SOURCE_STATIC_MEMBERS(...) \
- PERFETTO_INTERNAL_SWALLOW_SEMICOLON()
+// This macro must be used once for each data source next to the data source's
+// declaration.
+#define PERFETTO_DECLARE_DATA_SOURCE_STATIC_MEMBERS(...) \
+ template <> \
+ PERFETTO_COMPONENT_EXPORT perfetto::internal::DataSourceStaticState \
+ perfetto::DataSource<__VA_ARGS__>::static_state_; \
+ template <> \
+ PERFETTO_COMPONENT_EXPORT thread_local perfetto::internal:: \
+ DataSourceThreadLocalState* \
+ perfetto::DataSource<__VA_ARGS__>::tls_state_
+
+// This macro must be used once for each data source in one source file to
+// allocate static storage for the data source's static state.
+#define PERFETTO_DEFINE_DATA_SOURCE_STATIC_MEMBERS(...) \
+ template <> \
+ PERFETTO_COMPONENT_EXPORT perfetto::internal::DataSourceStaticState \
+ perfetto::DataSource<__VA_ARGS__>::static_state_{}; \
+ template <> \
+ PERFETTO_COMPONENT_EXPORT thread_local perfetto::internal:: \
+ DataSourceThreadLocalState* \
+ perfetto::DataSource<__VA_ARGS__>::tls_state_ = nullptr
#endif // INCLUDE_PERFETTO_TRACING_DATA_SOURCE_H_