@@ -36,17 +36,7 @@ use tracing_perfetto_sdk_schema::track_event::CounterValueField;
3636use tracing_perfetto_sdk_schema:: track_event:: Timestamp ;
3737use tracing_perfetto_sdk_schema:: track_event:: Type as TrackEventType ;
3838
39- #[ derive(
40- Deserialize ,
41- Serialize ,
42- Debug ,
43- Clone ,
44- Default ,
45- PartialEq ,
46- Eq ,
47- Hash ,
48- valuable:: Valuable
49- ) ]
39+ #[ derive( Deserialize , Serialize , Debug , Clone , Default ) ]
5040pub struct RawEvent {
5141 pub time : u64 ,
5242 pub time_us : u64 ,
@@ -63,8 +53,35 @@ pub struct RawEvent {
6353 pub target : String ,
6454 pub err : Option < String > ,
6555 pub stacktrace : Option < String > ,
56+ pub thread_name : Option < String > ,
57+ #[ serde( flatten) ]
58+ #[ serde( default ) ]
59+ pub extra_fields : HashMap < String , serde_json:: Value > ,
6660}
6761
62+ impl PartialEq for RawEvent {
63+ fn eq ( & self , other : & Self ) -> bool {
64+ self . time == other. time
65+ && self . time_us == other. time_us
66+ && self . span_id == other. span_id
67+ && self . parent_span_id == other. parent_span_id
68+ && self . name == other. name
69+ && self . event_type == other. event_type
70+ && self . message == other. message
71+ && self . actor_id == other. actor_id
72+ && self . file == other. file
73+ && self . lineno == other. lineno
74+ && self . os_pid == other. os_pid
75+ && self . tokio_task_id == other. tokio_task_id
76+ && self . target == other. target
77+ && self . err == other. err
78+ && self . stacktrace == other. stacktrace
79+ && self . thread_name == other. thread_name
80+ }
81+ }
82+
83+ impl Eq for RawEvent { }
84+
6885impl PartialOrd for RawEvent {
6986 fn partial_cmp ( & self , other : & Self ) -> Option < std:: cmp:: Ordering > {
7087 Some ( self . cmp ( other) )
@@ -204,21 +221,31 @@ pub struct TimeUs(u64);
204221
205222impl From < TimeUs > for Timestamp {
206223 fn from ( value : TimeUs ) -> Self {
207- Timestamp :: TimestampAbsoluteUs ( value. 0 as i64 )
224+ Timestamp :: TimestampAbsoluteUs ( ( value. 0 * 1000 ) as i64 )
208225 }
209226}
210227
211228impl From < TimeUs > for u64 {
212229 fn from ( value : TimeUs ) -> Self {
213- value. 0
230+ value. 0 * 1000
214231 }
215232}
216233impl From < TimeUs > for Option < u64 > {
217234 fn from ( value : TimeUs ) -> Self {
218- Some ( value. 0 )
235+ Some ( value. 0 * 1000 )
219236 }
220237}
221238
239+ /// Trait for types that can be named
240+ pub trait Nameable {
241+ fn name ( self , name : & str ) -> Self ;
242+ }
243+
244+ /// Trait for types that can have annotations added
245+ pub trait Annotable {
246+ fn add_annotation ( self , key : & str , value : & serde_json:: Value ) -> Self ;
247+ }
248+
222249pub struct Instant < ' a , T : Sink > {
223250 event : TrackEvent ,
224251 ts : TimeUs ,
@@ -239,6 +266,13 @@ impl<'a, T: Sink> Instant<'a, T> {
239266 self
240267 }
241268
269+ pub fn add_annotation ( mut self , name : & str , value : & serde_json:: Value ) -> Self {
270+ self . event
271+ . debug_annotations
272+ . push ( self . ctx . debug_annotation ( name, value) ) ;
273+ self
274+ }
275+
242276 pub fn consume ( self ) {
243277 let event = self . event ;
244278 let tp = TracePacket {
@@ -250,6 +284,18 @@ impl<'a, T: Sink> Instant<'a, T> {
250284 }
251285}
252286
287+ impl < ' a , T : Sink > Nameable for Instant < ' a , T > {
288+ fn name ( self , name : & str ) -> Self {
289+ self . name ( name)
290+ }
291+ }
292+
293+ impl < ' a , T : Sink > Annotable for Instant < ' a , T > {
294+ fn add_annotation ( self , key : & str , value : & serde_json:: Value ) -> Self {
295+ self . add_annotation ( key, value)
296+ }
297+ }
298+
253299pub struct Counter < ' a , T : Sink > {
254300 event : TrackEvent ,
255301 ts : TimeUs ,
@@ -315,6 +361,13 @@ impl<'a, T: Sink> StartSlice<'a, T> {
315361 self
316362 }
317363
364+ pub fn add_annotation ( mut self , name : & str , value : & serde_json:: Value ) -> Self {
365+ self . event
366+ . debug_annotations
367+ . push ( self . ctx . debug_annotation ( name, value) ) ;
368+ self
369+ }
370+
318371 pub fn consume ( self ) {
319372 let mut event = self . event ;
320373 event. r#type = Some ( TrackEventType :: SliceBegin as i32 ) ;
@@ -326,6 +379,19 @@ impl<'a, T: Sink> StartSlice<'a, T> {
326379 self . ctx . consume ( tp) ;
327380 }
328381}
382+
383+ impl < ' a , T : Sink > Nameable for StartSlice < ' a , T > {
384+ fn name ( self , name : & str ) -> Self {
385+ self . name ( name)
386+ }
387+ }
388+
389+ impl < ' a , T : Sink > Annotable for StartSlice < ' a , T > {
390+ fn add_annotation ( self , key : & str , value : & serde_json:: Value ) -> Self {
391+ self . add_annotation ( key, value)
392+ }
393+ }
394+
329395pub struct EndSlice < ' a , T : Sink > {
330396 event : TrackEvent ,
331397 ts : TimeUs ,
@@ -579,7 +645,7 @@ impl<T: Sink> Ctx<T> {
579645 . debug_annotation_names
580646 . push ( debug_annotation_name) ;
581647 }
582- for ( val, id) in self . debug_annotation_names . to_flush ( ) {
648+ for ( val, id) in self . debug_annotation_strings . to_flush ( ) {
583649 let ii = InternedString {
584650 iid : Some ( * id) ,
585651 str : Some ( val. clone ( ) . into_bytes ( ) . into ( ) ) ,
0 commit comments