Add encoding profiling to aos logger
The diagnostic data logger compression uses a significant amount
of CPU. To help profile the system, this change will record the
encode time for each message.
When profiling is enabled (through constructor argument) the encode
times will be collected in a log along with the event loop
monotonic clock time stamps.
Add a python script to create a graph of the encode_times from
the logger.
Change-Id: If1cc19fbffe0ff31f63e5789f610c4ca40a9d47a
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/events/logging/buffer_encoder.h b/aos/events/logging/buffer_encoder.h
index a155bb5..db09d32 100644
--- a/aos/events/logging/buffer_encoder.h
+++ b/aos/events/logging/buffer_encoder.h
@@ -7,6 +7,7 @@
#include "aos/containers/resizeable_buffer.h"
#include "aos/events/logging/logger_generated.h"
+#include "aos/time/time.h"
namespace aos::logger {
@@ -65,14 +66,19 @@
// Encodes and enqueues the given data encoder. Starts at the start byte
// (which must be a multiple of 8 bytes), and goes as far as it can. Returns
- // the amount encoded.
- virtual size_t Encode(Copier *copy, size_t start_byte) = 0;
+ // the amount encoded. The `encode_duration` is optional, when provided it
+ // will be set to the amount of time spent by the encoder during this call.
+ virtual size_t Encode(
+ Copier *copy, size_t start_byte,
+ std::chrono::nanoseconds *encode_duration = nullptr) = 0;
// Finalizes the encoding process. After this, queue_size() represents the
// full extent of data which will be written to this file.
- //
- // Encode may not be called after this method.
- virtual void Finish() = 0;
+ // This function may invoke the encoder to encode any remaining data remaining
+ // in the queue. The `encode_duration` is optional, when provided it will be
+ // set to the amount of time spent by the encoder during this call. Do not
+ // call Encode after calling this method.
+ virtual void Finish(std::chrono::nanoseconds *encode_duration = nullptr) = 0;
// Clears the first n encoded buffers from the queue.
virtual void Clear(int n) = 0;
@@ -105,8 +111,11 @@
bool HasSpace(size_t request) const final;
size_t space() const final;
- size_t Encode(Copier *copy, size_t start_byte) final;
- void Finish() final {}
+
+ // See base class for commments.
+ size_t Encode(Copier *copy, size_t start_byte,
+ std::chrono::nanoseconds *encode_duration = nullptr) final;
+ void Finish(std::chrono::nanoseconds * /*encode_duration*/ = nullptr) final {}
void Clear(int n) final;
absl::Span<const absl::Span<const uint8_t>> queue() final;
size_t queued_bytes() const final;