Closed Bug 1566706 Opened 1 year ago Closed 1 year ago

Allow ModuloBuffer and BlockRingBuffer to be used over an existing byte buffer


(Core :: Gecko Profiler, task, P2)




Tracking Status
firefox70 --- fixed


(Reporter: gerald, Assigned: gerald)




(1 file)

In some cases it would be useful for BlocksRingBuffer (and its underlying ModuloBuffer) to work over an existing byte buffer.
So we could use an array of bytes on the stack, e.g.:

constexpr auto size = MakePowerOfTwo32<8192>;
uint8_t buffer[size.Value()];
BlocksRingBuffer brb(buffer, size);

This saves having to do a heap allocation.

Sometimes a small ProfileBuffer (where BlocksRingBuffer will eventually be used) is created to sample a stack, so this will help remove another allocation there. And it could be useful during the transition of markers to use BlocksRingBuffer (TBC).

Finally, this will help with testing, by creating a pre-filled buffer, testing a ModuloBuffer or BlocksRingBuffer in the middle, and verifying that nothing around it was unexpectedly modified.

By default ModuloBuffer allocates its own buffer on the heap.
Now ModuloBuffer adds two alternatives:

  • Take ownership of a pre-allocated UniquePtr<uint8_t> buffer.
  • Work over an unowned uint8_t* array. The caller is responsible for
    ownership, and ensuring that the array lives at least as long as the

BlocksRingBuffer can pass along these new options to its underlying

The main use will be for small on-stack BlocksRingBuffer that can store a
stack trace, or to more easily collect data (without allocating anything on the
heap) that can then go into the upcoming ProfileBuffer's BlocksRingBuffer.

Pushed by
ModuloBuffer and BlocksRingBuffer can be given a external underlying buffer - r=gregtatum

I'd say that's not possible, as ModuloBuffer and BlocksRingBuffer are not used yet in Firefox!
(They're only used in the cppunittest TestBaseProfiler.cpp, which I would hope should not influence mochitests.)

Flags: needinfo?(gsquelart)
Blocks: 1567461
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla70
You need to log in before you can comment on or make changes to this bug.