add usefull information to trace
This commit is contained in:
parent
fa6da96f53
commit
349b37edda
1 changed files with 38 additions and 3 deletions
41
src/lib.rs
41
src/lib.rs
|
|
@ -10,7 +10,7 @@ mod perfetto {
|
||||||
|
|
||||||
use perfetto::DebugAnnotation;
|
use perfetto::DebugAnnotation;
|
||||||
use prost::Message;
|
use prost::Message;
|
||||||
use tracing::{field::Visit, span, Dispatch, Level, Subscriber};
|
use tracing::{field::Visit, span, Dispatch, Level, Metadata, Subscriber};
|
||||||
|
|
||||||
pub fn install_perfetto_subscriber() {
|
pub fn install_perfetto_subscriber() {
|
||||||
let subscriber = PerfettoSubscriber::new();
|
let subscriber = PerfettoSubscriber::new();
|
||||||
|
|
@ -49,6 +49,31 @@ struct DebugAnnotationVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DebugAnnotationVisitor {
|
impl DebugAnnotationVisitor {
|
||||||
|
fn new_with_metadata(metadata: &'static Metadata<'static>) -> Self {
|
||||||
|
Self {
|
||||||
|
data: vec![
|
||||||
|
DebugAnnotation {
|
||||||
|
name_field: Some(perfetto::debug_annotation::NameField::Name(String::from(
|
||||||
|
"module_path",
|
||||||
|
))),
|
||||||
|
value: metadata
|
||||||
|
.module_path()
|
||||||
|
.map(|m| perfetto::debug_annotation::Value::StringValue(m.to_owned())),
|
||||||
|
},
|
||||||
|
DebugAnnotation {
|
||||||
|
name_field: Some(perfetto::debug_annotation::NameField::Name(String::from(
|
||||||
|
"location",
|
||||||
|
))),
|
||||||
|
value: Some(perfetto::debug_annotation::Value::StringValue(format!(
|
||||||
|
"{}: {}",
|
||||||
|
metadata.file().unwrap_or(""),
|
||||||
|
metadata.line().unwrap_or(0)
|
||||||
|
))),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self { data: Vec::new() }
|
Self { data: Vec::new() }
|
||||||
}
|
}
|
||||||
|
|
@ -188,7 +213,7 @@ impl Subscriber for PerfettoSubscriber {
|
||||||
.id_counter
|
.id_counter
|
||||||
.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
||||||
|
|
||||||
let mut debug_annotations = DebugAnnotationVisitor::new();
|
let mut debug_annotations = DebugAnnotationVisitor::new_with_metadata(span.metadata());
|
||||||
span.record(&mut debug_annotations);
|
span.record(&mut debug_annotations);
|
||||||
|
|
||||||
let mut inner = self.inner.lock().unwrap();
|
let mut inner = self.inner.lock().unwrap();
|
||||||
|
|
@ -205,6 +230,16 @@ impl Subscriber for PerfettoSubscriber {
|
||||||
|
|
||||||
fn record(&self, span: &span::Id, values: &span::Record<'_>) {
|
fn record(&self, span: &span::Id, values: &span::Record<'_>) {
|
||||||
// println!("record {:?} {:?}", span, values);
|
// println!("record {:?} {:?}", span, values);
|
||||||
|
let mut debug_annotations = DebugAnnotationVisitor::new();
|
||||||
|
values.record(&mut debug_annotations);
|
||||||
|
|
||||||
|
let mut inner = self.inner.lock().unwrap();
|
||||||
|
inner
|
||||||
|
.spans
|
||||||
|
.get_mut(&span.into_u64())
|
||||||
|
.unwrap()
|
||||||
|
.debug_annotations
|
||||||
|
.append(&mut debug_annotations.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn record_follows_from(&self, span: &span::Id, follows: &span::Id) {
|
fn record_follows_from(&self, span: &span::Id, follows: &span::Id) {
|
||||||
|
|
@ -217,7 +252,7 @@ impl Subscriber for PerfettoSubscriber {
|
||||||
let time = self.start_time.elapsed().as_nanos() as u64;
|
let time = self.start_time.elapsed().as_nanos() as u64;
|
||||||
let mut inner = self.inner.lock().unwrap();
|
let mut inner = self.inner.lock().unwrap();
|
||||||
|
|
||||||
let mut debug_annotations = DebugAnnotationVisitor::new();
|
let mut debug_annotations = DebugAnnotationVisitor::new_with_metadata(event.metadata());
|
||||||
event.record(&mut debug_annotations);
|
event.record(&mut debug_annotations);
|
||||||
|
|
||||||
inner.buffer.push(perfetto::TracePacket {
|
inner.buffer.push(perfetto::TracePacket {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue