@@ -91,7 +91,7 @@ struct pping_config {
9191
9292static  volatile  int  keep_running  =  1 ;
9393static  json_writer_t  * json_ctx  =  NULL ;
94- static  void  (* print_event_func )(void   * ,  int ,  void   * ,  __u32 ) =  NULL ;
94+ static  void  (* print_event_func )(const   union   pping_event   * ) =  NULL ;
9595
9696static  const  struct  option  long_options [] =  {
9797	{ "help" ,             no_argument ,       NULL , 'h'  },
@@ -499,7 +499,7 @@ static bool flow_timeout(void *key_ptr, void *val_ptr, __u64 now)
499499			fe .flow_event_type  =  FLOW_EVENT_CLOSING ;
500500			fe .reason  =  EVENT_REASON_FLOW_TIMEOUT ;
501501			fe .source  =  EVENT_SOURCE_USERSPACE ;
502- 			print_event_func (NULL ,  0 ,  & fe ,  sizeof ( fe ) );
502+ 			print_event_func (( union   pping_event   * ) & fe );
503503		}
504504		return  true;
505505	}
@@ -710,11 +710,8 @@ static void print_ns_datetime(FILE *stream, __u64 monotonic_ns)
710710	fprintf (stream , "%s.%09llu" , timestr , ts  % NS_PER_SECOND );
711711}
712712
713- static  void  print_event_standard (void  * ctx , int  cpu , void  * data ,
714- 				 __u32  data_size )
713+ static  void  print_event_standard (const  union  pping_event  * e )
715714{
716- 	const  union  pping_event  * e  =  data ;
717- 
718715	if  (e -> event_type  ==  EVENT_TYPE_RTT ) {
719716		print_ns_datetime (stdout , e -> rtt_event .timestamp );
720717		printf (" %llu.%06llu ms %llu.%06llu ms %s " ,
@@ -736,19 +733,19 @@ static void print_event_standard(void *ctx, int cpu, void *data,
736733	}
737734}
738735
739- static  void  print_event_ppviz (void   * ctx ,  int   cpu ,  void   * data ,  __u32   data_size )
736+ static  void  print_event_ppviz (const   union   pping_event   * e )
740737{
741- 	const  struct  rtt_event  * e  =  data ;
742- 	__u64  time  =  convert_monotonic_to_realtime (e -> timestamp );
743- 
744738	// ppviz format does not support flow events 
745739	if  (e -> event_type  !=  EVENT_TYPE_RTT )
746740		return ;
747741
742+ 	const  struct  rtt_event  * re  =  & e -> rtt_event ;
743+ 	__u64  time  =  convert_monotonic_to_realtime (re -> timestamp );
744+ 
748745	printf ("%llu.%09llu %llu.%09llu %llu.%09llu " , time  / NS_PER_SECOND ,
749- 	       time  % NS_PER_SECOND , e -> rtt  / NS_PER_SECOND ,
750- 	       e -> rtt  % NS_PER_SECOND , e -> min_rtt  / NS_PER_SECOND , e -> min_rtt );
751- 	print_flow_ppvizformat (stdout , & e -> flow );
746+ 	       time  % NS_PER_SECOND , re -> rtt  / NS_PER_SECOND ,
747+ 	       re -> rtt  % NS_PER_SECOND , re -> min_rtt  / NS_PER_SECOND , re -> min_rtt );
748+ 	print_flow_ppvizformat (stdout , & re -> flow );
752749	printf ("\n" );
753750}
754751
@@ -793,10 +790,8 @@ static void print_flowevent_fields_json(json_writer_t *ctx,
793790	jsonw_string_field (ctx , "triggered_by" , eventsource_to_str (fe -> source ));
794791}
795792
796- static  void  print_event_json (void   * ctx ,  int   cpu ,  void   * data ,  __u32   data_size )
793+ static  void  print_event_json (const   union   pping_event   * e )
797794{
798- 	const  union  pping_event  * e  =  data ;
799- 
800795	if  (e -> event_type  !=  EVENT_TYPE_RTT  &&  e -> event_type  !=  EVENT_TYPE_FLOW )
801796		return ;
802797
@@ -814,9 +809,27 @@ static void print_event_json(void *ctx, int cpu, void *data, __u32 data_size)
814809	jsonw_end_object (json_ctx );
815810}
816811
817- static  void  handle_missed_rtt_event (void  * ctx , int  cpu , __u64  lost_cnt )
812+ static  void  handle_event (void  * ctx , int  cpu , void  * data , __u32  data_size )
813+ {
814+ 	const  union  pping_event  * e  =  data ;
815+ 
816+ 	if  (data_size  <  sizeof (e -> event_type ))
817+ 		return ;
818+ 
819+ 	switch  (e -> event_type ) {
820+ 	case  EVENT_TYPE_RTT :
821+ 	case  EVENT_TYPE_FLOW :
822+ 		print_event_func (e );
823+ 		break ;
824+ 	default :
825+ 		fprintf (stderr , "Warning: Unknown event type %llu\n" ,
826+ 			e -> event_type );
827+ 	};
828+ }
829+ 
830+ static  void  handle_missed_events (void  * ctx , int  cpu , __u64  lost_cnt )
818831{
819- 	fprintf (stderr , "Lost %llu RTT  events on CPU %d\n" , lost_cnt , cpu );
832+ 	fprintf (stderr , "Lost %llu events on CPU %d\n" , lost_cnt , cpu );
820833}
821834
822835/* 
@@ -1067,8 +1080,8 @@ int main(int argc, char *argv[])
10671080	// Set up perf buffer 
10681081	pb  =  perf_buffer__new (bpf_object__find_map_fd_by_name (obj ,
10691082							      config .event_map ),
1070- 			      PERF_BUFFER_PAGES , print_event_func ,
1071- 			      handle_missed_rtt_event , NULL , NULL );
1083+ 			      PERF_BUFFER_PAGES , handle_event ,
1084+ 			      handle_missed_events , NULL , NULL );
10721085	err  =  libbpf_get_error (pb );
10731086	if  (err ) {
10741087		fprintf (stderr , "Failed to open perf buffer %s: %s\n" ,
0 commit comments