@@ -654,8 +654,7 @@ int stats_poll_handler()
654654{
655655	int  map_fd  =  bpf_object__find_map_fd_by_name (trace_ctx .obj , "m_stats" );
656656	char  buf [128 ], * header , * unit ;
657- 	__u64  count [16 ];
658- 	
657+ 	__u64  count [MAX_STATS_BUCKETS ] =  {};
659658	int  i ;
660659
661660	if  (!map_fd ) {
@@ -675,34 +674,42 @@ int stats_poll_handler()
675674		int  start  =  0 , j ;
676675		__u64  total  =  0 ;
677676
678- 		for  (i  =  0 ; i  <  16 ; i ++ ) {
677+ 		for  (i  =  0 ; i  <  ARRAY_SIZE ( count ) ; i ++ ) {
679678			bpf_map_lookup_elem (map_fd , & i , count  +  i );
680679			total  +=  count [i ];
681680		}
682681
683682		pr_info ("%-34s%llu\n" , header , total );
684- 		for  (i  =  0 ; i  <  16 ; i ++ ) {
683+ 		for  (i  =  0 ; i  <  ARRAY_SIZE ( count ) ; i ++ ) {
685684			bool  has_count  =  false;
686685			int  p  =  0 , t  =  0 ;
687686
688- 			for  (j  =  i ; j  <  16 ; j ++ ) {
689- 				if  (count [j ])
687+ 			/* check if there is data in the next bucket, used to terminate the output early */ 
688+ 			for  (j  =  i ; j  <  ARRAY_SIZE (count ); j ++ ) {
689+ 				if  (count [j ]) {
690690					has_count  =  true;
691+ 					break ;
692+ 				}
691693			}
692694
693695			if  (!has_count  &&  i  >  8 )
694696				break ;
695697
696- 			start  =  1  << i ;
697- 			sprintf (buf , "%d - %5d%s" , start  ==  1  ? 0  : start ,
698- 				(start  << 1 ) -  1 , unit );
698+ 			if  (i  ==  LAST_STATS_BUCKET ) {
699+ 				snprintf (buf , sizeof (buf ), ">= 65536%s" , unit );
700+ 			} else  {
701+ 				start  =  1  << i ;
702+ 				snprintf (buf , sizeof (buf ), "%d - %5d%s" ,
703+ 				         start  ==  1  ? 0  : start ,
704+ 				         (start  << 1 ) -  1 , unit );
705+ 			}
706+ 
699707			if  (total ) {
700708				p  =  count [i ] / total ;
701709				t  =  (count [i ] % total ) *  10000  / total ;
702710			}
703711
704- 			pr_info ("%32s: %-8llu %d.%04d\n" , buf , count [i ],
705- 				p , t );
712+ 			pr_info ("%32s: %-8llu %d.%04d\n" , buf , count [i ], p , t );
706713		}
707714		sleep (1 );
708715	}
0 commit comments