Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 414bd78e authored by Pablo Gamito's avatar Pablo Gamito
Browse files

Add option to provide ProtoOutputStream chunk size in newTracePacket

This is to avoid always allocating 8kb of memory on every single newTracePacket call, especially when we know the trace packet will be much smaller than this.

Bug: 372285118
Bug: 400413040
Flag: EXEMPT very minor bug fix
Change-Id: If7e1c4b3b241e2d4ffee66bf549faa8d2715cd77
parent e9f9bbf3
Loading
Loading
Loading
Loading
+16 −1
Original line number Original line Diff line number Diff line
@@ -53,7 +53,22 @@ public class TracingContext<DataSourceInstanceType extends DataSourceInstance, T
     * @return A proto output stream to write a trace packet proto to
     * @return A proto output stream to write a trace packet proto to
     */
     */
    public ProtoOutputStream newTracePacket() {
    public ProtoOutputStream newTracePacket() {
        final ProtoOutputStream os = new ProtoOutputStream(0);
        return newTracePacket(0);
    }

    /**
     * Creates a new output stream to be used to write a trace packet to. The output stream will be
     * encoded to the proto binary representation when the callback trace function finishes and
     * send over to the native side to be included in the proto buffer.
     *
     * @param estimatedPacketSizeInBytes The estimated size of the trace packet. This will help
     *                                   avoid over allocating memory. We allocate an initial buffer
     *                                   of this size on trace packet creation.
     *                                   If set to 0 8kb is used.
     * @return A proto output stream to write a trace packet proto to
     */
    public ProtoOutputStream newTracePacket(int estimatedPacketSizeInBytes) {
        final ProtoOutputStream os = new ProtoOutputStream(estimatedPacketSizeInBytes);
        mTracePackets.add(os);
        mTracePackets.add(os);
        return os;
        return os;
    }
    }