@@ -110,7 +110,7 @@ int __hpp__fmt_acc(struct perf_hpp *hpp, struct hist_entry *he,
110110{
111111 if (!symbol_conf .cumulate_callchain ) {
112112 return snprintf (hpp -> buf , hpp -> size , "%*s" ,
113- fmt_percent ? 8 : 12 , "N/A" );
113+ fmt_percent ? len + 2 : len + 1 , "N/A" );
114114 }
115115
116116 return __hpp__fmt (hpp , he , get_field , fmt , len , print_fn , fmt_percent );
@@ -190,32 +190,31 @@ static int __hpp__sort_acc(struct hist_entry *a, struct hist_entry *b,
190190 return ret ;
191191}
192192
193- #define __HPP_HEADER_FN (_type , _str , _min_width , _unit_width ) \
194- static int hpp__header_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \
195- struct perf_hpp *hpp, \
196- struct perf_evsel *evsel) \
197- { \
198- int len = _min_width; \
199- \
200- if (symbol_conf.event_group) \
201- len = max(len, evsel->nr_members * _unit_width); \
202- \
203- return scnprintf(hpp->buf, hpp->size, "%*s", len, _str); \
204- }
205-
206- #define __HPP_WIDTH_FN (_type , _min_width , _unit_width ) \
207- static int hpp__width_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \
193+ #define __HPP_WIDTH_FN (_type , _str ) \
194+ static int hpp__width_##_type(struct perf_hpp_fmt *fmt, \
208195 struct perf_hpp *hpp __maybe_unused, \
209196 struct perf_evsel *evsel) \
210197{ \
211- int len = _min_width ; \
198+ int len = fmt->len ; \
212199 \
213200 if (symbol_conf.event_group) \
214- len = max(len, evsel->nr_members * _unit_width); \
201+ len = max(len, evsel->nr_members * len); \
202+ \
203+ if (len < (int)strlen(_str)) \
204+ len = strlen(_str); \
215205 \
216206 return len; \
217207}
218208
209+ #define __HPP_HEADER_FN (_type , _str ) \
210+ static int hpp__header_##_type(struct perf_hpp_fmt *fmt, \
211+ struct perf_hpp *hpp, \
212+ struct perf_evsel *evsel) \
213+ { \
214+ int len = hpp__width_##_type(fmt, hpp, evsel); \
215+ return scnprintf(hpp->buf, hpp->size, "%*s", len, _str); \
216+ }
217+
219218static int hpp_color_scnprintf (struct perf_hpp * hpp , const char * fmt , ...)
220219{
221220 va_list args ;
@@ -251,18 +250,19 @@ static u64 he_get_##_field(struct hist_entry *he) \
251250 return he->stat._field; \
252251} \
253252 \
254- static int hpp__color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \
253+ static int hpp__color_##_type(struct perf_hpp_fmt *fmt, \
255254 struct perf_hpp *hpp, struct hist_entry *he) \
256255{ \
257- return __hpp__fmt(hpp, he, he_get_##_field, " %*.2f%%", 6, \
256+ int len = fmt->len - 2; /* 2 for a space and a % sign */ \
257+ return __hpp__fmt (hpp , he , he_get_ ##_field , " %*.2f%%" , len , \
258258 hpp_color_scnprintf , true); \
259259}
260260
261261#define __HPP_ENTRY_PERCENT_FN (_type , _field ) \
262- static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \
262+ static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \
263263 struct perf_hpp *hpp, struct hist_entry *he) \
264264{ \
265- int len = symbol_conf.field_sep ? 1 : 6; \
265+ int len = symbol_conf.field_sep ? 1 : fmt->len - 2; \
266266 return __hpp__fmt(hpp, he, he_get_##_field, " %*.2f%%", len, \
267267 hpp_entry_scnprintf, true); \
268268}
@@ -279,18 +279,19 @@ static u64 he_get_acc_##_field(struct hist_entry *he) \
279279 return he->stat_acc->_field; \
280280} \
281281 \
282- static int hpp__color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \
282+ static int hpp__color_##_type(struct perf_hpp_fmt *fmt, \
283283 struct perf_hpp *hpp, struct hist_entry *he) \
284284{ \
285- return __hpp__fmt_acc(hpp, he, he_get_acc_##_field, " %*.2f%%", 6, \
285+ int len = fmt->len - 2; /* 2 for a space and a % sign */ \
286+ return __hpp__fmt_acc (hpp , he , he_get_acc_ ##_field , " %*.2f%%" , len , \
286287 hpp_color_scnprintf , true); \
287288}
288289
289290#define __HPP_ENTRY_ACC_PERCENT_FN (_type , _field ) \
290- static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \
291+ static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \
291292 struct perf_hpp *hpp, struct hist_entry *he) \
292293{ \
293- int len = symbol_conf.field_sep ? 1 : 6; \
294+ int len = symbol_conf.field_sep ? 1 : fmt->len - 2; \
294295 return __hpp__fmt_acc(hpp, he, he_get_##_field, " %*.2f%%", len, \
295296 hpp_entry_scnprintf, true); \
296297}
@@ -307,10 +308,10 @@ static u64 he_get_raw_##_field(struct hist_entry *he) \
307308 return he->stat._field; \
308309} \
309310 \
310- static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \
311+ static int hpp__entry_##_type(struct perf_hpp_fmt *fmt, \
311312 struct perf_hpp *hpp, struct hist_entry *he) \
312313{ \
313- int len = symbol_conf.field_sep ? 1 : 11; \
314+ int len = symbol_conf.field_sep ? 1 : fmt->len - 1; \
314315 return __hpp__fmt(hpp, he, he_get_raw_##_field, " %*"PRIu64, len, \
315316 hpp_entry_scnprintf, false); \
316317}
@@ -322,37 +323,38 @@ static int64_t hpp__sort_##_type(struct hist_entry *a, struct hist_entry *b) \
322323}
323324
324325
325- #define HPP_PERCENT_FNS (_type , _str , _field , _min_width , _unit_width ) \
326- __HPP_HEADER_FN (_type, _str, _min_width, _unit_width) \
327- __HPP_WIDTH_FN (_type, _min_width, _unit_width) \
326+ #define HPP_PERCENT_FNS (_type , _str , _field ) \
327+ __HPP_WIDTH_FN (_type, _str) \
328+ __HPP_HEADER_FN (_type, _str) \
328329__HPP_COLOR_PERCENT_FN(_type, _field) \
329330__HPP_ENTRY_PERCENT_FN(_type, _field) \
330331__HPP_SORT_FN(_type, _field)
331332
332- #define HPP_PERCENT_ACC_FNS (_type , _str , _field , _min_width , _unit_width ) \
333- __HPP_HEADER_FN (_type, _str, _min_width, _unit_width) \
334- __HPP_WIDTH_FN (_type, _min_width, _unit_width) \
333+ #define HPP_PERCENT_ACC_FNS (_type , _str , _field ) \
334+ __HPP_WIDTH_FN (_type, _str) \
335+ __HPP_HEADER_FN (_type, _str) \
335336__HPP_COLOR_ACC_PERCENT_FN(_type, _field) \
336337__HPP_ENTRY_ACC_PERCENT_FN(_type, _field) \
337338__HPP_SORT_ACC_FN(_type, _field)
338339
339- #define HPP_RAW_FNS (_type , _str , _field , _min_width , _unit_width ) \
340- __HPP_HEADER_FN (_type, _str, _min_width, _unit_width) \
341- __HPP_WIDTH_FN (_type, _min_width, _unit_width) \
340+ #define HPP_RAW_FNS (_type , _str , _field ) \
341+ __HPP_WIDTH_FN (_type, _str) \
342+ __HPP_HEADER_FN (_type, _str) \
342343__HPP_ENTRY_RAW_FN(_type, _field) \
343344__HPP_SORT_RAW_FN(_type, _field)
344345
345- __HPP_HEADER_FN (overhead_self , "Self" , 8 , 8 )
346+ __HPP_WIDTH_FN (overhead_self , "Self" )
347+ __HPP_HEADER_FN (overhead_self , "Self" )
346348
347- HPP_PERCENT_FNS (overhead , "Overhead" , period , 8 , 8 )
348- HPP_PERCENT_FNS (overhead_sys , "sys" , period_sys , 8 , 8 )
349- HPP_PERCENT_FNS (overhead_us , "usr" , period_us , 8 , 8 )
350- HPP_PERCENT_FNS (overhead_guest_sys , "guest sys" , period_guest_sys , 9 , 8 )
351- HPP_PERCENT_FNS (overhead_guest_us , "guest usr" , period_guest_us , 9 , 8 )
352- HPP_PERCENT_ACC_FNS (overhead_acc , "Children" , period , 8 , 8 )
349+ HPP_PERCENT_FNS (overhead , "Overhead" , period )
350+ HPP_PERCENT_FNS (overhead_sys , "sys" , period_sys )
351+ HPP_PERCENT_FNS (overhead_us , "usr" , period_us )
352+ HPP_PERCENT_FNS (overhead_guest_sys , "guest sys" , period_guest_sys )
353+ HPP_PERCENT_FNS (overhead_guest_us , "guest usr" , period_guest_us )
354+ HPP_PERCENT_ACC_FNS (overhead_acc , "Children" , period )
353355
354- HPP_RAW_FNS (samples , "Samples" , nr_events , 12 , 12 )
355- HPP_RAW_FNS (period , "Period" , period , 12 , 12 )
356+ HPP_RAW_FNS (samples , "Samples" , nr_events )
357+ HPP_RAW_FNS (period , "Period" , period )
356358
357359static int64_t hpp__nop_cmp (struct hist_entry * a __maybe_unused ,
358360 struct hist_entry * b __maybe_unused )
@@ -453,6 +455,8 @@ void perf_hpp__init(void)
453455
454456 perf_hpp__format [PERF_HPP__OVERHEAD ].header =
455457 hpp__header_overhead_self ;
458+ perf_hpp__format [PERF_HPP__OVERHEAD ].width =
459+ hpp__width_overhead_self ;
456460 }
457461
458462 perf_hpp__column_enable (PERF_HPP__OVERHEAD );
@@ -519,6 +523,7 @@ void perf_hpp__cancel_cumulate(void)
519523
520524 perf_hpp__column_disable (PERF_HPP__OVERHEAD_ACC );
521525 perf_hpp__format [PERF_HPP__OVERHEAD ].header = hpp__header_overhead ;
526+ perf_hpp__format [PERF_HPP__OVERHEAD ].width = hpp__width_overhead ;
522527}
523528
524529void perf_hpp__setup_output_field (void )
@@ -623,3 +628,41 @@ unsigned int hists__sort_list_width(struct hists *hists)
623628
624629 return ret ;
625630}
631+
632+ void perf_hpp__reset_width (struct perf_hpp_fmt * fmt , struct hists * hists )
633+ {
634+ int idx ;
635+
636+ if (perf_hpp__is_sort_entry (fmt ))
637+ return perf_hpp__reset_sort_width (fmt , hists );
638+
639+ for (idx = 0 ; idx < PERF_HPP__MAX_INDEX ; idx ++ ) {
640+ if (fmt == & perf_hpp__format [idx ])
641+ break ;
642+ }
643+
644+ if (idx == PERF_HPP__MAX_INDEX )
645+ return ;
646+
647+ switch (idx ) {
648+ case PERF_HPP__OVERHEAD :
649+ case PERF_HPP__OVERHEAD_SYS :
650+ case PERF_HPP__OVERHEAD_US :
651+ case PERF_HPP__OVERHEAD_ACC :
652+ fmt -> len = 8 ;
653+ break ;
654+
655+ case PERF_HPP__OVERHEAD_GUEST_SYS :
656+ case PERF_HPP__OVERHEAD_GUEST_US :
657+ fmt -> len = 9 ;
658+ break ;
659+
660+ case PERF_HPP__SAMPLES :
661+ case PERF_HPP__PERIOD :
662+ fmt -> len = 12 ;
663+ break ;
664+
665+ default :
666+ break ;
667+ }
668+ }
0 commit comments