@@ -181,21 +181,29 @@ static int block_column_width(struct perf_hpp_fmt *fmt,
181
181
return block_fmt -> width ;
182
182
}
183
183
184
+ static int color_pct (struct perf_hpp * hpp , int width , double pct )
185
+ {
186
+ #ifdef HAVE_SLANG_SUPPORT
187
+ if (use_browser ) {
188
+ return __hpp__slsmg_color_printf (hpp , "%*.2f%%" ,
189
+ width - 1 , pct );
190
+ }
191
+ #endif
192
+ return hpp_color_scnprintf (hpp , "%*.2f%%" , width - 1 , pct );
193
+ }
194
+
184
195
static int block_total_cycles_pct_entry (struct perf_hpp_fmt * fmt ,
185
196
struct perf_hpp * hpp ,
186
197
struct hist_entry * he )
187
198
{
188
199
struct block_fmt * block_fmt = container_of (fmt , struct block_fmt , fmt );
189
200
struct block_info * bi = he -> block_info ;
190
201
double ratio = 0.0 ;
191
- char buf [16 ];
192
202
193
203
if (block_fmt -> total_cycles )
194
204
ratio = (double )bi -> cycles / (double )block_fmt -> total_cycles ;
195
205
196
- sprintf (buf , "%.2f%%" , 100.0 * ratio );
197
-
198
- return scnprintf (hpp -> buf , hpp -> size , "%*s" , block_fmt -> width , buf );
206
+ return color_pct (hpp , block_fmt -> width , 100.0 * ratio );
199
207
}
200
208
201
209
static int64_t block_total_cycles_pct_sort (struct perf_hpp_fmt * fmt ,
@@ -248,16 +256,13 @@ static int block_cycles_pct_entry(struct perf_hpp_fmt *fmt,
248
256
struct block_info * bi = he -> block_info ;
249
257
double ratio = 0.0 ;
250
258
u64 avg ;
251
- char buf [16 ];
252
259
253
260
if (block_fmt -> block_cycles && bi -> num_aggr ) {
254
261
avg = bi -> cycles_aggr / bi -> num_aggr ;
255
262
ratio = (double )avg / (double )block_fmt -> block_cycles ;
256
263
}
257
264
258
- sprintf (buf , "%.2f%%" , 100.0 * ratio );
259
-
260
- return scnprintf (hpp -> buf , hpp -> size , "%*s" , block_fmt -> width , buf );
265
+ return color_pct (hpp , block_fmt -> width , 100.0 * ratio );
261
266
}
262
267
263
268
static int block_avg_cycles_entry (struct perf_hpp_fmt * fmt ,
@@ -345,15 +350,15 @@ static void hpp_register(struct block_fmt *block_fmt, int idx,
345
350
346
351
switch (idx ) {
347
352
case PERF_HPP_REPORT__BLOCK_TOTAL_CYCLES_PCT :
348
- fmt -> entry = block_total_cycles_pct_entry ;
353
+ fmt -> color = block_total_cycles_pct_entry ;
349
354
fmt -> cmp = block_info__cmp ;
350
355
fmt -> sort = block_total_cycles_pct_sort ;
351
356
break ;
352
357
case PERF_HPP_REPORT__BLOCK_LBR_CYCLES :
353
358
fmt -> entry = block_cycles_lbr_entry ;
354
359
break ;
355
360
case PERF_HPP_REPORT__BLOCK_CYCLES_PCT :
356
- fmt -> entry = block_cycles_pct_entry ;
361
+ fmt -> color = block_cycles_pct_entry ;
357
362
break ;
358
363
case PERF_HPP_REPORT__BLOCK_AVG_CYCLES :
359
364
fmt -> entry = block_avg_cycles_entry ;
0 commit comments