0

[mojo] Prevent BigBuffers from being copied into traces

BigBuffers can be, well, big. However, since they support iteration,
their content end up being copied byte by byte into traces. This has
several drawbacks:
- Slow down production code when tracing is enabled
- Create enormous traces
- Crashes the UI when selecting such a slice

To avoid that, specialize trace value serialization for BigBuffer to
only provide the size.

Change-Id: Ib023a7674ba030e2b3499541a06fe08c188d8fa4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6429688
Commit-Queue: Benoit Lize <lizeb@chromium.org>
Reviewed-by: Andrea Orru <andreaorru@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1444013}
This commit is contained in:
Benoît Lizé
2025-04-08 02:09:10 -07:00
committed by Chromium LUCI CQ
parent 985b83dca9
commit c409e7c132
2 changed files with 9 additions and 0 deletions
mojo/public/cpp/base

@ -15,6 +15,7 @@
#include "base/check.h"
#include "base/containers/heap_array.h"
#include "base/notreached.h"
#include "third_party/perfetto/include/perfetto/tracing/traced_value.h"
namespace mojo_base {
@ -141,6 +142,12 @@ size_t BigBuffer::size() const {
}
}
void BigBuffer::WriteIntoTrace(perfetto::TracedValue context) const {
// Don't write the data, otherwise traces become enormous, and crash the UI.
auto dict = std::move(context).WriteDictionary();
perfetto::WriteIntoTracedValue(dict.AddItem("size"), size());
}
BigBufferView::BigBufferView() = default;
BigBufferView::BigBufferView(BigBufferView&& other) = default;

@ -175,6 +175,8 @@ class COMPONENT_EXPORT(MOJO_BASE) BigBuffer {
const_iterator cend() const { return end(); }
void WriteIntoTrace(perfetto::TracedValue context) const;
private:
friend class BigBufferView;