@@ -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' },
@@ -511,7 +511,7 @@ static bool flow_timeout(void *key_ptr, void *val_ptr, __u64 now)
511511 fe .flow_event_type = FLOW_EVENT_CLOSING ;
512512 fe .reason = EVENT_REASON_FLOW_TIMEOUT ;
513513 fe .source = EVENT_SOURCE_USERSPACE ;
514- print_event_func (NULL , 0 , & fe , sizeof ( fe ) );
514+ print_event_func (( union pping_event * ) & fe );
515515 }
516516 return true;
517517 }
@@ -722,11 +722,8 @@ static void print_ns_datetime(FILE *stream, __u64 monotonic_ns)
722722 fprintf (stream , "%s.%09llu" , timestr , ts % NS_PER_SECOND );
723723}
724724
725- static void print_event_standard (void * ctx , int cpu , void * data ,
726- __u32 data_size )
725+ static void print_event_standard (const union pping_event * e )
727726{
728- const union pping_event * e = data ;
729-
730727 if (e -> event_type == EVENT_TYPE_RTT ) {
731728 print_ns_datetime (stdout , e -> rtt_event .timestamp );
732729 printf (" %llu.%06llu ms %llu.%06llu ms %s " ,
@@ -748,19 +745,19 @@ static void print_event_standard(void *ctx, int cpu, void *data,
748745 }
749746}
750747
751- static void print_event_ppviz (void * ctx , int cpu , void * data , __u32 data_size )
748+ static void print_event_ppviz (const union pping_event * e )
752749{
753- const struct rtt_event * e = data ;
754- __u64 time = convert_monotonic_to_realtime (e -> timestamp );
755-
756750 // ppviz format does not support flow events
757751 if (e -> event_type != EVENT_TYPE_RTT )
758752 return ;
759753
754+ const struct rtt_event * re = & e -> rtt_event ;
755+ __u64 time = convert_monotonic_to_realtime (re -> timestamp );
756+
760757 printf ("%llu.%09llu %llu.%09llu %llu.%09llu " , time / NS_PER_SECOND ,
761- time % NS_PER_SECOND , e -> rtt / NS_PER_SECOND ,
762- e -> rtt % NS_PER_SECOND , e -> min_rtt / NS_PER_SECOND , e -> min_rtt );
763- print_flow_ppvizformat (stdout , & e -> flow );
758+ time % NS_PER_SECOND , re -> rtt / NS_PER_SECOND ,
759+ re -> rtt % NS_PER_SECOND , re -> min_rtt / NS_PER_SECOND , re -> min_rtt );
760+ print_flow_ppvizformat (stdout , & re -> flow );
764761 printf ("\n" );
765762}
766763
@@ -805,10 +802,8 @@ static void print_flowevent_fields_json(json_writer_t *ctx,
805802 jsonw_string_field (ctx , "triggered_by" , eventsource_to_str (fe -> source ));
806803}
807804
808- static void print_event_json (void * ctx , int cpu , void * data , __u32 data_size )
805+ static void print_event_json (const union pping_event * e )
809806{
810- const union pping_event * e = data ;
811-
812807 if (e -> event_type != EVENT_TYPE_RTT && e -> event_type != EVENT_TYPE_FLOW )
813808 return ;
814809
@@ -826,9 +821,27 @@ static void print_event_json(void *ctx, int cpu, void *data, __u32 data_size)
826821 jsonw_end_object (json_ctx );
827822}
828823
829- static void handle_missed_rtt_event (void * ctx , int cpu , __u64 lost_cnt )
824+ static void handle_event (void * ctx , int cpu , void * data , __u32 data_size )
825+ {
826+ const union pping_event * e = data ;
827+
828+ if (data_size < sizeof (e -> event_type ))
829+ return ;
830+
831+ switch (e -> event_type ) {
832+ case EVENT_TYPE_RTT :
833+ case EVENT_TYPE_FLOW :
834+ print_event_func (e );
835+ break ;
836+ default :
837+ fprintf (stderr , "Warning: Unknown event type %llu\n" ,
838+ e -> event_type );
839+ };
840+ }
841+
842+ static void handle_missed_events (void * ctx , int cpu , __u64 lost_cnt )
830843{
831- fprintf (stderr , "Lost %llu RTT events on CPU %d\n" , lost_cnt , cpu );
844+ fprintf (stderr , "Lost %llu events on CPU %d\n" , lost_cnt , cpu );
832845}
833846
834847/*
@@ -1081,8 +1094,8 @@ int main(int argc, char *argv[])
10811094 // Set up perf buffer
10821095 pb = perf_buffer__new (bpf_object__find_map_fd_by_name (obj ,
10831096 config .event_map ),
1084- PERF_BUFFER_PAGES , print_event_func ,
1085- handle_missed_rtt_event , NULL , NULL );
1097+ PERF_BUFFER_PAGES , handle_event ,
1098+ handle_missed_events , NULL , NULL );
10861099 err = libbpf_get_error (pb );
10871100 if (err ) {
10881101 fprintf (stderr , "Failed to open perf buffer %s: %s\n" ,
0 commit comments