Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

[PROF-4780] Breaking change: Change FFI File struct to contain a Buffer instead of a ByteSlice #33

Merged
merged 5 commits into from
Mar 11, 2022

Commits on Mar 9, 2022

  1. [PROF-4780] Breaking change: Change FFI File struct to contain a Buff…

    …er instead of a ByteSlice
    
    In #30 we added the `ddprof_ffi_Buffer_from_byte_slice` function to
    allow FFI users to provide their own data to be reported using
    the `ProfileExporterV3` (via `ddprof_ffi_ProfileExporterV3_build`).
    
    Thus, if one wanted to report some data, it first converted it
    from a `ByteSlice` into a `Buffer`, and then invoke `libddprof` with
    it.
    
    Here's a (simplified) example from the Ruby profiler:
    
    ```c
      ddprof_ffi_File files[1];
      ddprof_ffi_Slice_file slice_files = {.ptr = files, .len = 1};
    
      ddprof_ffi_Buffer *pprof_buffer =
        ddprof_ffi_Buffer_from_byte_slice((ddprof_ffi_ByteSlice) {
          .ptr = /* byte array with data we want to send */,
          .len = /* ... */
        });
    
      files[0] = (ddprof_ffi_File) {.name = /* ... */, .file = pprof_buffer};
    
      ddprof_ffi_Request *request =
        ddprof_ffi_ProfileExporterV3_build(exporter, start, finish, slice_files, timeout_milliseconds);
    
      ddprof_ffi_Buffer_free(pprof_buffer);
    ```
    
    This approach had a few downsides:
    
    1. It copied the data to be reported twice. It would be first
      copied into a `Buffer`, and then inside
      `ddprof_ffi_ProfileExporterV3_build` it would be copied again.
    
    2. **Callers manually needed to clean up the `Buffer` afterwards
      using `ddprof_ffi_Buffer_free`**.
    
    After discussing this with @morrisonlevi, we decided to go the
    other way: change the `File` to contain a `ByteSlice` directly.
    
    This avoids the extra copy in (1.), as well as the caller needing
    to manage the `Buffer` objects manually in (2.).
    
    This is a breaking API change for libddprof FFI users.
    ivoanjo committed Mar 9, 2022
    Configuration menu
    Copy the full SHA
    71b339a View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    d36f699 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    812d950 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    03e3bc5 View commit details
    Browse the repository at this point in the history

Commits on Mar 10, 2022

  1. Update examples/ffi/exporter.cpp

    Minor cleanup as suggested during review.
    
    Co-authored-by: Nicolas Savoire <nicolas.savoire@datadoghq.com>
    ivoanjo and nsavoire authored Mar 10, 2022
    Configuration menu
    Copy the full SHA
    693c29b View commit details
    Browse the repository at this point in the history