Closed Bug 1566706 Opened 5 years ago Closed 5 years ago

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

Categories

(Core :: Gecko Profiler, task, P2)

task

Tracking

()

RESOLVED FIXED
mozilla70
Tracking Status
firefox70 --- fixed

People

(Reporter: mozbugz, Assigned: mozbugz)

References

Details

Attachments

(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
    ModuloBuffer/BlocksRingBuffer.

BlocksRingBuffer can pass along these new options to its underlying
ModuloBuffer.

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 gsquelart@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/0dac048b774a
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)
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla70
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: