Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
sundy-li committed Sep 23, 2024
1 parent 4727d0d commit 9ac29ba
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 82 deletions.
6 changes: 2 additions & 4 deletions fastrace-futures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ pin_project! {
}

impl<T> Stream for InSpan<T>
where
T: Stream,
where T: Stream
{
type Item = T::Item;

Expand All @@ -128,8 +127,7 @@ where
}

impl<T, I> Sink<I> for InSpan<T>
where
T: Sink<I>,
where T: Sink<I>
{
type Error = T::Error;

Expand Down
4 changes: 1 addition & 3 deletions fastrace/examples/unit_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ mod test_util {
use super::*;

pub fn setup_fastrace<F>(test: F)
where
F: FnOnce() -> Result<()> + 'static,
{
where F: FnOnce() -> Result<()> + 'static {
fastrace::set_reporter(ConsoleReporter, Config::default());
{
let root = Span::root(closure_name::<F>(), SpanContext::random());
Expand Down
18 changes: 10 additions & 8 deletions fastrace/src/collector/global_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,16 @@ impl GlobalCollector {
{
std::thread::Builder::new()
.name("fastrace-global-collector".to_string())
.spawn(move || loop {
let begin_instant = Instant::now();
GLOBAL_COLLECTOR.lock().as_mut().unwrap().handle_commands();
std::thread::sleep(
config
.report_interval
.saturating_sub(begin_instant.elapsed()),
);
.spawn(move || {
loop {
let begin_instant = Instant::now();
GLOBAL_COLLECTOR.lock().as_mut().unwrap().handle_commands();
std::thread::sleep(
config
.report_interval
.saturating_sub(begin_instant.elapsed()),
);
}
})
.unwrap();
}
Expand Down
35 changes: 16 additions & 19 deletions fastrace/src/local/local_span_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,25 +172,22 @@ span1 []
let span = span_line.start_span("span").unwrap();
let current_token = span_line.current_collect_token().unwrap();
assert_eq!(current_token.len(), 2);
assert_eq!(
current_token.as_slice(),
&[
CollectTokenItem {
trace_id: TraceId(1234),
parent_id: span_line.span_queue.current_parent_id().unwrap(),
collect_id: 42,
is_root: false,
is_sampled: true,
},
CollectTokenItem {
trace_id: TraceId(1235),
parent_id: span_line.span_queue.current_parent_id().unwrap(),
collect_id: 43,
is_root: false,
is_sampled: true,
}
]
);
assert_eq!(current_token.as_slice(), &[
CollectTokenItem {
trace_id: TraceId(1234),
parent_id: span_line.span_queue.current_parent_id().unwrap(),
collect_id: 42,
is_root: false,
is_sampled: true,
},
CollectTokenItem {
trace_id: TraceId(1235),
parent_id: span_line.span_queue.current_parent_id().unwrap(),
collect_id: 43,
is_root: false,
is_sampled: true,
}
]);
span_line.finish_span(span);

let current_token = span_line.current_collect_token().unwrap();
Expand Down
80 changes: 40 additions & 40 deletions fastrace/src/local/local_span_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,37 +238,41 @@ span1 []
{
let span_line4 = span_stack.register_span_line(None).unwrap();
{
assert!(span_stack
.register_span_line(Some(
CollectTokenItem {
trace_id: TraceId(1235),
parent_id: SpanId::default(),
collect_id: 43,
is_root: false,
is_sampled: true,
}
.into()
))
.is_none());
assert!(
span_stack
.register_span_line(Some(
CollectTokenItem {
trace_id: TraceId(1235),
parent_id: SpanId::default(),
collect_id: 43,
is_root: false,
is_sampled: true,
}
.into()
))
.is_none()
);
assert!(span_stack.register_span_line(None).is_none());
}
let _ = span_stack.unregister_and_collect(span_line4).unwrap();
}
{
let span_line5 = span_stack.register_span_line(None).unwrap();
{
assert!(span_stack
.register_span_line(Some(
CollectTokenItem {
trace_id: TraceId(1236),
parent_id: SpanId::default(),
collect_id: 44,
is_root: false,
is_sampled: true,
}
.into()
))
.is_none());
assert!(
span_stack
.register_span_line(Some(
CollectTokenItem {
trace_id: TraceId(1236),
parent_id: SpanId::default(),
collect_id: 44,
is_root: false,
is_sampled: true,
}
.into()
))
.is_none()
);
assert!(span_stack.register_span_line(None).is_none());
}
let _ = span_stack.unregister_and_collect(span_line5).unwrap();
Expand All @@ -292,10 +296,9 @@ span1 []
is_sampled: true,
};
let span_line1 = span_stack.register_span_line(Some(token1.into())).unwrap();
assert_eq!(
span_stack.current_collect_token().unwrap().as_slice(),
&[token1]
);
assert_eq!(span_stack.current_collect_token().unwrap().as_slice(), &[
token1
]);
{
let span_line2 = span_stack.register_span_line(None).unwrap();
assert!(span_stack.current_collect_token().is_none());
Expand All @@ -308,10 +311,9 @@ span1 []
is_sampled: true,
};
let span_line3 = span_stack.register_span_line(Some(token3.into())).unwrap();
assert_eq!(
span_stack.current_collect_token().unwrap().as_slice(),
&[token3]
);
assert_eq!(span_stack.current_collect_token().unwrap().as_slice(), &[
token3
]);
let _ = span_stack.unregister_and_collect(span_line3).unwrap();
}
assert!(span_stack.current_collect_token().is_none());
Expand All @@ -325,16 +327,14 @@ span1 []
is_sampled: true,
};
let span_line4 = span_stack.register_span_line(Some(token4.into())).unwrap();
assert_eq!(
span_stack.current_collect_token().unwrap().as_slice(),
&[token4]
);
assert_eq!(span_stack.current_collect_token().unwrap().as_slice(), &[
token4
]);
let _ = span_stack.unregister_and_collect(span_line4).unwrap();
}
assert_eq!(
span_stack.current_collect_token().unwrap().as_slice(),
&[token1]
);
assert_eq!(span_stack.current_collect_token().unwrap().as_slice(), &[
token1
]);
let _ = span_stack.unregister_and_collect(span_line1).unwrap();
assert!(span_stack.current_collect_token().is_none());
}
Expand Down
7 changes: 3 additions & 4 deletions fastrace/src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,10 +725,9 @@ root []
let parent4 = Span::root("parent4", parent_ctx);
let parent5 = Span::root("parent5", parent_ctx);
let child1 = Span::enter_with_parent("child1", &parent5);
let child2 = Span::enter_with_parents(
"child2",
[&parent1, &parent2, &parent3, &parent4, &parent5, &child1],
)
let child2 = Span::enter_with_parents("child2", [
&parent1, &parent2, &parent3, &parent4, &parent5, &child1,
])
.with_property(|| ("k1", "v1"));

crossbeam::scope(move |scope| {
Expand Down
6 changes: 2 additions & 4 deletions fastrace/src/util/object_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,15 @@ impl<'a, T> Reusable<'a, T> {
}

impl<'a, T> std::fmt::Debug for Reusable<'a, T>
where
T: std::fmt::Debug,
where T: std::fmt::Debug
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.obj.fmt(f)
}
}

impl<'a, T> std::cmp::PartialEq for Reusable<'a, T>
where
T: std::cmp::PartialEq,
where T: std::cmp::PartialEq
{
fn eq(&self, other: &Self) -> bool {
T::eq(self, other)
Expand Down

0 comments on commit 9ac29ba

Please sign in to comment.