@@ -7,6 +7,7 @@ use libipt_sys::{
77 pt_event_type_ptev_pwre, pt_event_type_ptev_pwrx, pt_event_type_ptev_stop,
88 pt_event_type_ptev_tick, pt_event_type_ptev_tsx, pt_event_type_ptev_vmcs,
99} ;
10+ use std:: fmt:: { Debug , Formatter } ;
1011
1112mod enabled;
1213pub use enabled:: * ;
@@ -76,9 +77,10 @@ impl From<Event> for EventType {
7677 }
7778}
7879
79- #[ derive( Debug , Clone , Copy ) ]
80+ #[ derive( Clone , Copy ) ]
8081#[ repr( transparent) ]
8182pub struct Event ( pub ( crate ) pt_event ) ;
83+
8284impl Event {
8385 /// A flag indicating that the event IP has been suppressed.
8486 #[ must_use]
@@ -92,17 +94,16 @@ impl Event {
9294 self . 0 . status_update ( ) > 0
9395 }
9496
95- /// A flag indicating that the event has timing information.
96- #[ must_use]
97- pub fn has_tsc ( & self ) -> bool {
98- self . 0 . has_tsc ( ) > 0
99- }
100-
10197 /// The time stamp count of the event.
102- /// This field is only valid if @has_tsc is set.
98+ ///
99+ /// Returns `None` if tsc information is not available
103100 #[ must_use]
104- pub const fn tsc ( & self ) -> u64 {
105- self . 0 . tsc
101+ pub fn tsc ( & self ) -> Option < u64 > {
102+ if self . 0 . has_tsc ( ) > 0 {
103+ Some ( self . 0 . tsc )
104+ } else {
105+ None
106+ }
106107 }
107108
108109 /// The number of lost mtc packets.
@@ -153,6 +154,24 @@ impl Event {
153154 _ => unreachable ! ( ) ,
154155 }
155156 }
157+
158+ pub ( crate ) fn fmt_common_fields ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
159+ write ! (
160+ f,
161+ "ip_suppressed : {:?}, status_update: {:?}, tsc: {:?}, lost_mtc: {:?}, lost_cyc: {:?}," ,
162+ self . ip_suppressed( ) ,
163+ self . status_update( ) ,
164+ self . tsc( ) ,
165+ self . lost_mtc( ) ,
166+ self . lost_cyc( ) ,
167+ )
168+ }
169+ }
170+
171+ impl Debug for Event {
172+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
173+ self . event_type ( ) . fmt ( f)
174+ }
156175}
157176
158177#[ cfg( test) ]
@@ -177,9 +196,8 @@ mod test {
177196 let evt = Event ( evt) ;
178197 assert ! ( evt. ip_suppressed( ) ) ;
179198 assert ! ( !evt. status_update( ) ) ;
180- assert ! ( evt. has_tsc( ) ) ;
181199
182- assert_eq ! ( evt. tsc( ) , 1 ) ;
200+ assert_eq ! ( evt. tsc( ) , Some ( 1 ) ) ;
183201 assert_eq ! ( evt. lost_mtc( ) , 2 ) ;
184202 assert_eq ! ( evt. lost_cyc( ) , 3 ) ;
185203
0 commit comments