ebpf icon indicating copy to clipboard operation
ebpf copied to clipboard

perf: Add support for overwritable buffer.

Open eiffel-fl opened this issue 2 years ago • 2 comments

Hi.

This PR supersedes #814. Compared to conventionnal perf buffer, an overwritable perf buffer never stops writing. Instead, the oldest data are overwritten by the newest.

As a consequence, the ReaderOptions was modified to add a new boolean to indicate if perf buffer is overwritable. To read these buffers, a new function ReadCallback() was introduced. This function reads the buffer from the current head until it wraps the buffer (or there are no more data to read). For each read record, the callback is called.

This PR also adds test which validates the new function is working. You can also find an example of this feature usage in Inspektor Gadget code (not upstreamed at the moment).

If you see any way to improve this contribution, feel free to share.

Best regards and thank you in advance.

eiffel-fl avatar Nov 21 '22 13:11 eiffel-fl

Converted to draft as it looks like some discussion will be needed. I haven't followed the previous discussion in detail, but wouldn't it be better to agree on an approach up front over Slack or a call?

ti-mo avatar Nov 23 '22 14:11 ti-mo

wouldn't it be better to agree on an approach up front over Slack or a call?

Why not, the only thing I would like to have your opinion is about the API as I think this will not be possible to use existing Read() and ReadInto():

  1. Either we define a function which takes a callback and calls it for each record (this is the current implementation). Note that this behavior mimics libbpf.
  2. Or we define a function which returns an array of Record which contains all the Records which were read.

eiffel-fl avatar Nov 23 '22 15:11 eiffel-fl

Oh damn! I went faster than the music! I will open a new PR, GitHub does not make cross collaboration easy!

eiffel-fl avatar Feb 28 '23 10:02 eiffel-fl