Skip to content

Commit

Permalink
cleanup panics and atomic orderings
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoh committed May 6, 2023
1 parent acd0afa commit 82c670c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
[Latest Version]: https://img.shields.io/crates/v/tracing-texray.svg
[crates.io]: https://crates.io/crates/tracing-texray

> First, a word of warning: **This is alpha software.** Don't run this in prod or anywhere where a panic would ruin your day.
`tracing-texray` is a [tracing](https://tracing.rs) layer to introspect spans and events in plain text. By `examine`-ing a specific
span, a full tree will be output when that span exits. Using code like the following (actual program elided):

Expand Down
8 changes: 4 additions & 4 deletions src/tracked_spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ impl TrackedSpans {
while attempt < self.size() {
let idx = self.hash(value, attempt);
let atomic = self.els.get(idx).expect("idx guaranteed to be less");
let old_val = atomic.load(Ordering::Relaxed);
let old_val = atomic.load(Ordering::SeqCst);
if old_val == value {
return Ok(InsertResult::AlreadyPresent);
}
if (old_val == 0 || old_val == TOMBSTONE)
&& atomic
.compare_exchange(old_val, value, Ordering::Relaxed, Ordering::Relaxed)
.compare_exchange(old_val, value, Ordering::SeqCst, Ordering::SeqCst)
.is_ok()
{
return Ok(InsertResult::NotPresent);
Expand All @@ -94,7 +94,7 @@ impl TrackedSpans {
while attempt < self.size() {
let idx = self.hash(value, attempt);
let atomic = self.els.get(idx).expect("idx guaranteed to be less");
let stored_value = atomic.load(Ordering::SeqCst);
let stored_value = atomic.load(Ordering::Acquire);
match stored_value {
0 => return None,
v if v == value => return Some(idx),
Expand All @@ -112,7 +112,7 @@ impl TrackedSpans {
_ => TOMBSTONE,
};
self.els[idx]
.compare_exchange(value.get(), new_value, Ordering::Relaxed, Ordering::Relaxed)
.compare_exchange(value.get(), new_value, Ordering::AcqRel, Ordering::Acquire)
.is_ok()
} else {
false
Expand Down
15 changes: 9 additions & 6 deletions src/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,9 @@ impl SpanInfo {
let offset = width(
render_conf.chart_width(),
render_conf.total(),
match ev_start_ts.duration_since(render_conf.start_ts) {
Ok(dur) => dur,
Err(_) => return Ok(()),
},
ev_start_ts
.duration_since(render_conf.start_ts)
.unwrap_or_default(),
);
write!(out, "{}", " ".repeat(offset))?;
let interval_width = width(render_conf.chart_width(), render_conf.total(), span_len);
Expand Down Expand Up @@ -407,7 +406,9 @@ impl InterestTracker {
let event_offset = (width(
render_conf.chart_width(),
render_conf.total(),
ev.timestamp.duration_since(span_info.start).unwrap(),
ev.timestamp
.duration_since(span_info.start)
.unwrap_or_default(),
) as i32)
- 1;
write!(out, "{}", " ".repeat(DURATION_WIDTH + 2))?;
Expand All @@ -434,11 +435,13 @@ impl RootTracker {
}

pub(crate) fn register_interest(&self, id: Id, settings: SpanSettings) {
// put the insertion into examined_spans inside the critical block
let mut span_guard = self.span_metadata.write();
if self.examined_spans.insert(id.into_non_zero_u64()).is_err() {
tracing::warn!("map is full, too many spans. this span will not be tracked");
return;
}
self.span_metadata.write().insert(
span_guard.insert(
id.clone(),
InterestTracker::new(id, settings.render, settings.fields, settings.out),
);
Expand Down

0 comments on commit 82c670c

Please sign in to comment.