Skip to content

Commit

Permalink
lots of cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoh committed Apr 30, 2023
1 parent 583a769 commit 5fce994
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/hashset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::num::NonZeroU64;

use std::sync::atomic::{AtomicU64, Ordering};

/// Lock-free hashset that can hold a fixed number of U64s
pub(crate) struct TrackedSpans {
els: Vec<AtomicU64>,
}
Expand Down
26 changes: 10 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![doc = include_str ! ("../README.md")]
#![doc = include_str!("../README.md")]
#![warn(
missing_docs,
rustdoc::missing_crate_level_docs,
Expand Down Expand Up @@ -608,8 +608,7 @@ impl InterestTracker {
width: settings.width,
};
let mut ordered = self.children.iter().collect::<Vec<_>>();
ordered
.sort_by_key(|(key, _)| sort_key(&self.children, key.as_slice()).collect::<Vec<_>>());
ordered.sort_by_key(|(key, _)| sort_key(&self.children, key.as_slice()));

for (key, track) in ordered.iter() {
let offset = NESTED_EVENT_OFFSET * (key.len() - 1);
Expand Down Expand Up @@ -716,19 +715,14 @@ impl RootTracker {
}
}

fn sort_key(
map: &HashMap<Vec<Id>, SpanTracker>,
target: &[Id],
) -> impl Iterator<Item = SystemTime> {
if target.is_empty() {
Box::new(std::iter::empty()) as Box<dyn Iterator<Item = SystemTime>>
} else {
let span = map.get(target).expect("missing");
Box::new(
std::iter::once(span.info.as_ref().unwrap().start)
.chain(sort_key(map, &target[..target.len() - 1])),
)
}
fn sort_key<'a>(map: &'a HashMap<Vec<Id>, SpanTracker>, target: &'a [Id]) -> Vec<SystemTime> {
(1..=target.len())
.rev()
.map(move |idx| {
let span = map.get(&target[..idx]).expect("must exist");
span.info.as_ref().expect("span must have opened").start
})
.collect::<Vec<_>>()
}

#[derive(Debug)]
Expand Down
7 changes: 3 additions & 4 deletions tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::test_util::CaptureWriter;
use std::time::Duration;
use tracing::{info_span, trace_span};
use tracing::info_span;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::EnvFilter;
use tracing_texray::TeXRayLayer;

//#[tokio::test]
Expand All @@ -15,7 +14,7 @@ fn test_me() {
.enable_events()
.update_settings(|s| s.writer(capture_writer.clone()));
let registry = tracing_subscriber::registry()
.with(EnvFilter::from_default_env())
//.with(EnvFilter::from_default_env())
.with(layer);
tracing::subscriber::set_global_default(registry).expect("failed to install subscriber");
tracing_texray::examine(info_span!("load_data")).in_scope(|| {
Expand Down Expand Up @@ -63,7 +62,7 @@ fn somewhere_deep_in_my_program() {
}

fn some_other_function(id: usize) {
trace_span!("inner_task", id = %id).in_scope(|| tracing::info!("buzz"));
info_span!("inner_task", id = %id).in_scope(|| tracing::info!("buzz"));
// ...
}

Expand Down

0 comments on commit 5fce994

Please sign in to comment.