Expose bytes written to TraceWriter to client API.
This will be used to be more clever about splitting in perfetto_hprof.
Bug: 143874090
Bug: 149378918
Change-Id: Id11c03bd51b3b333117f018883f73bb9ead7297b
diff --git a/include/perfetto/ext/tracing/core/trace_writer.h b/include/perfetto/ext/tracing/core/trace_writer.h
index 99662b2..9be44ff 100644
--- a/include/perfetto/ext/tracing/core/trace_writer.h
+++ b/include/perfetto/ext/tracing/core/trace_writer.h
@@ -79,7 +79,7 @@
virtual WriterID writer_id() const = 0;
// Bytes written since creation. Is not reset when new chunks are acquired.
- virtual uint64_t written() const = 0;
+ virtual uint64_t written() const override = 0;
// Set the id of the first chunk the writer will emit. Returns |false| if not
// implemented or if the first chunk was already emitted by the writer.
diff --git a/include/perfetto/tracing/data_source.h b/include/perfetto/tracing/data_source.h
index 1a2f57e..2e8dc4e 100644
--- a/include/perfetto/tracing/data_source.h
+++ b/include/perfetto/tracing/data_source.h
@@ -188,6 +188,11 @@
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.
diff --git a/include/perfetto/tracing/trace_writer_base.h b/include/perfetto/tracing/trace_writer_base.h
index 2d95668..824be1a 100644
--- a/include/perfetto/tracing/trace_writer_base.h
+++ b/include/perfetto/tracing/trace_writer_base.h
@@ -38,6 +38,7 @@
NewTracePacket() = 0;
virtual void Flush(std::function<void()> callback = {}) = 0;
+ virtual uint64_t written() const = 0;
};
} // namespace perfetto