tracing-prof 0.3.0

Experimental library for profiling tracing spans.
Documentation
use tracing::span;

use crate::{
    allocator::GroupAllocationStatistics,
    reporter::{SpanCpuTime, SpanMetadata, SpanWallTime},
};
use crossbeam_queue::SegQueue;

pub struct SpanEvent {
    pub(crate) span_id: span::Id,
    pub(crate) kind: SpanEventKind,
}

pub(crate) enum SpanEventKind {
    Created(SpanMetadata),
    Cpu(SpanCpuTime),
    Wall(SpanWallTime),
}

pub struct SpanClosedEvent {
    pub(crate) span_id: span::Id,
}

pub struct SpanMemoryUpdateEvent {
    pub(crate) span_id: span::Id,
    pub(crate) stats: GroupAllocationStatistics,
}

pub(crate) struct EventQueue<T> {
    inner: SegQueue<T>,
}

impl<T> EventQueue<T> {
    pub(crate) fn new() -> Self {
        Self {
            inner: SegQueue::default(),
        }
    }

    /// Try to push an item into the queue, if it fails, drop the item.
    pub(crate) fn push(&self, item: T) {
        self.inner.push(item);
    }

    pub(crate) fn pop(&self) -> Option<T> {
        self.inner.pop()
    }
}