Skip to content

Commit

Permalink
Live debugger parsing, expression evaluation, sender, redaction and F…
Browse files Browse the repository at this point in the history
…FI (#497)

All stuff for live debugging.
  • Loading branch information
bwoebi authored Oct 2, 2024
1 parent 43c5a39 commit b8a7d2d
Show file tree
Hide file tree
Showing 56 changed files with 6,315 additions and 148 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
shell: bash
run: |
# shellcheck disable=SC2046
cargo clippy --workspace --all-targets --all-features -- -D warnings $([ ${{ matrix.rust_version }} = 1.76.0 ] && echo -Aunknown-lints -Ainvalid_reference_casting)
cargo clippy --workspace --all-targets --all-features -- -D warnings $([ ${{ matrix.rust_version }} = 1.76.0 ] && echo -Aunknown-lints -Ainvalid_reference_casting -Aclippy::redundant-closure-call)
licensecheck:
runs-on: ubuntu-latest
name: "Presence of licence headers"
Expand Down
59 changes: 57 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ members = [
"tools",
"ipc",
"ipc/macros",
"live-debugger",
"live-debugger-ffi",
"remote-config",
"sidecar",
"sidecar/macros",
"sidecar-ffi",
Expand Down
468 changes: 463 additions & 5 deletions LICENSE-3rdparty.yml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions ddcommon-ffi/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ impl<T> Option<T> {
pub fn to_std(self) -> std::option::Option<T> {
self.into()
}

pub fn to_std_ref(&self) -> std::option::Option<&T> {
match self {
Option::Some(ref s) => Some(s),
Option::None => None,
}
}
}

impl<T> From<Option<T>> for std::option::Option<T> {
Expand Down
7 changes: 7 additions & 0 deletions ddcommon-ffi/src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ pub trait AsBytes<'a> {
fn to_utf8_lossy(&self) -> Cow<'a, str> {
String::from_utf8_lossy(self.as_bytes())
}

#[inline]
/// # Safety
/// Must only be used when the underlying data was already confirmed to be utf8.
unsafe fn assume_utf8(&self) -> &'a str {
std::str::from_utf8_unchecked(self.as_bytes())
}
}

impl<'a> AsBytes<'a> for Slice<'a, u8> {
Expand Down
12 changes: 11 additions & 1 deletion ddcommon-ffi/src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use core::ops::Deref;
use std::io::Write;
use std::marker::PhantomData;
use std::mem::ManuallyDrop;
use std::ptr::NonNull;

/// Holds the raw parts of a Rust Vec; it should only be created from Rust,
/// never from C.
Expand Down Expand Up @@ -97,6 +98,15 @@ impl<T> Vec<T> {
pub fn as_slice(&self) -> Slice<T> {
unsafe { Slice::from_raw_parts(self.ptr, self.len) }
}

pub const fn new() -> Self {
Vec {
ptr: NonNull::dangling().as_ptr(),
len: 0,
capacity: 0,
_marker: PhantomData,
}
}
}

impl<T> Deref for Vec<T> {
Expand All @@ -109,7 +119,7 @@ impl<T> Deref for Vec<T> {

impl<T> Default for Vec<T> {
fn default() -> Self {
Self::from(alloc::vec::Vec::new())
Self::new()
}
}

Expand Down
20 changes: 16 additions & 4 deletions ddcommon/src/rate_limiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub trait Limiter {
/// Returns the effective rate per interval.
/// Note: The rate is only guaranteed to be accurate immediately after a call to inc().
fn rate(&self) -> f64;
/// Updates the rate and returns it
fn update_rate(&self) -> f64;
}

/// A thread-safe limiter built on Atomics.
Expand Down Expand Up @@ -83,23 +85,28 @@ impl LocalLimiter {
self.last_limit.store(0, Ordering::Relaxed);
self.granularity = TIME_PER_SECOND * seconds as i64;
}
}

impl Limiter for LocalLimiter {
fn inc(&self, limit: u32) -> bool {
fn update(&self, limit: u32, inc: i64) -> i64 {
let now = now();
let last = self.last_update.swap(now, Ordering::SeqCst);
// Make sure reducing the limit doesn't stall for a long time
let clear_limit = limit.max(self.last_limit.load(Ordering::Relaxed));
let clear_counter = (now as i64 - last as i64) * (clear_limit as i64);
let subtract = clear_counter - self.granularity;
let subtract = clear_counter - inc;
let mut previous_hits = self.hit_count.fetch_sub(subtract, Ordering::SeqCst);
// Handle where the limiter goes below zero
if previous_hits < subtract {
let add = clear_counter - previous_hits.max(0);
self.hit_count.fetch_add(add, Ordering::Acquire);
previous_hits += add - clear_counter;
}
previous_hits
}
}

impl Limiter for LocalLimiter {
fn inc(&self, limit: u32) -> bool {
let previous_hits = self.update(limit, self.granularity);
if previous_hits / self.granularity >= limit as i64 {
self.hit_count
.fetch_sub(self.granularity, Ordering::Acquire);
Expand All @@ -119,6 +126,11 @@ impl Limiter for LocalLimiter {
let hit_count = self.hit_count.load(Ordering::Relaxed);
(hit_count as f64 / (last_limit as i64 * self.granularity) as f64).clamp(0., 1.)
}

fn update_rate(&self) -> f64 {
self.update(0, self.granularity);
self.rate()
}
}

#[cfg(test)]
Expand Down
12 changes: 6 additions & 6 deletions ipc/src/platform/mem_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ impl<T: MemoryHandle> MappedMem<T> {
}
}

impl<T: MemoryHandle> AsRef<[u8]> for MappedMem<T> {
fn as_ref(&self) -> &[u8] {
self.as_slice()
}
}

impl MappedMem<NamedShmHandle> {
pub fn get_path(&self) -> &[u8] {
self.mem.get_path()
Expand Down Expand Up @@ -205,12 +211,6 @@ impl From<ShmHandle> for PlatformHandle<OwnedFileHandle> {
unsafe impl<T> Sync for MappedMem<T> where T: FileBackedHandle {}
unsafe impl<T> Send for MappedMem<T> where T: FileBackedHandle {}

impl AsRef<[u8]> for MappedMem<ShmHandle> {
fn as_ref(&self) -> &[u8] {
self.as_slice()
}
}

#[cfg(feature = "tiny-bytes")]
impl UnderlyingBytes for MappedMem<ShmHandle> {}

Expand Down
Loading

0 comments on commit b8a7d2d

Please sign in to comment.