32
32
#include <linux/time64.h>
33
33
#include <linux/zalloc.h>
34
34
35
+ static int64_t hist_entry__cmp (struct hist_entry * left , struct hist_entry * right );
36
+ static int64_t hist_entry__collapse (struct hist_entry * left , struct hist_entry * right );
37
+
35
38
static bool hists__filter_entry_by_dso (struct hists * hists ,
36
39
struct hist_entry * he );
37
40
static bool hists__filter_entry_by_thread (struct hists * hists ,
@@ -1292,19 +1295,26 @@ int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al,
1292
1295
return err ;
1293
1296
}
1294
1297
1295
- int64_t
1296
- hist_entry__cmp (struct hist_entry * left , struct hist_entry * right )
1298
+ static int64_t
1299
+ hist_entry__cmp_impl (struct perf_hpp_list * hpp_list , struct hist_entry * left ,
1300
+ struct hist_entry * right , unsigned long fn_offset ,
1301
+ bool ignore_dynamic , bool ignore_skipped )
1297
1302
{
1298
1303
struct hists * hists = left -> hists ;
1299
1304
struct perf_hpp_fmt * fmt ;
1305
+ perf_hpp_fmt_cmp_t * fn ;
1300
1306
int64_t cmp = 0 ;
1301
1307
1302
- hists__for_each_sort_list ( hists , fmt ) {
1303
- if (perf_hpp__is_dynamic_entry (fmt ) &&
1308
+ perf_hpp_list__for_each_sort_list ( hpp_list , fmt ) {
1309
+ if (ignore_dynamic && perf_hpp__is_dynamic_entry (fmt ) &&
1304
1310
!perf_hpp__defined_dynamic_entry (fmt , hists ))
1305
1311
continue ;
1306
1312
1307
- cmp = fmt -> cmp (fmt , left , right );
1313
+ if (ignore_skipped && perf_hpp__should_skip (fmt , hists ))
1314
+ continue ;
1315
+
1316
+ fn = (void * )fmt + fn_offset ;
1317
+ cmp = (* fn )(fmt , left , right );
1308
1318
if (cmp )
1309
1319
break ;
1310
1320
}
@@ -1313,23 +1323,33 @@ hist_entry__cmp(struct hist_entry *left, struct hist_entry *right)
1313
1323
}
1314
1324
1315
1325
int64_t
1316
- hist_entry__collapse (struct hist_entry * left , struct hist_entry * right )
1326
+ hist_entry__cmp (struct hist_entry * left , struct hist_entry * right )
1317
1327
{
1318
- struct hists * hists = left -> hists ;
1319
- struct perf_hpp_fmt * fmt ;
1320
- int64_t cmp = 0 ;
1328
+ return hist_entry__cmp_impl ( left -> hists -> hpp_list , left , right ,
1329
+ offsetof( struct perf_hpp_fmt , cmp ), true, false) ;
1330
+ }
1321
1331
1322
- hists__for_each_sort_list (hists , fmt ) {
1323
- if (perf_hpp__is_dynamic_entry (fmt ) &&
1324
- !perf_hpp__defined_dynamic_entry (fmt , hists ))
1325
- continue ;
1332
+ static int64_t
1333
+ hist_entry__sort (struct hist_entry * left , struct hist_entry * right )
1334
+ {
1335
+ return hist_entry__cmp_impl (left -> hists -> hpp_list , left , right ,
1336
+ offsetof(struct perf_hpp_fmt , sort ), false, true);
1337
+ }
1326
1338
1327
- cmp = fmt -> collapse (fmt , left , right );
1328
- if (cmp )
1329
- break ;
1330
- }
1339
+ int64_t
1340
+ hist_entry__collapse (struct hist_entry * left , struct hist_entry * right )
1341
+ {
1342
+ return hist_entry__cmp_impl (left -> hists -> hpp_list , left , right ,
1343
+ offsetof(struct perf_hpp_fmt , collapse ), true, false);
1344
+ }
1331
1345
1332
- return cmp ;
1346
+ static int64_t
1347
+ hist_entry__collapse_hierarchy (struct perf_hpp_list * hpp_list ,
1348
+ struct hist_entry * left ,
1349
+ struct hist_entry * right )
1350
+ {
1351
+ return hist_entry__cmp_impl (hpp_list , left , right ,
1352
+ offsetof(struct perf_hpp_fmt , collapse ), false, false);
1333
1353
}
1334
1354
1335
1355
void hist_entry__delete (struct hist_entry * he )
@@ -1503,14 +1523,7 @@ static struct hist_entry *hierarchy_insert_entry(struct hists *hists,
1503
1523
while (* p != NULL ) {
1504
1524
parent = * p ;
1505
1525
iter = rb_entry (parent , struct hist_entry , rb_node_in );
1506
-
1507
- cmp = 0 ;
1508
- perf_hpp_list__for_each_sort_list (hpp_list , fmt ) {
1509
- cmp = fmt -> collapse (fmt , iter , he );
1510
- if (cmp )
1511
- break ;
1512
- }
1513
-
1526
+ cmp = hist_entry__collapse_hierarchy (hpp_list , iter , he );
1514
1527
if (!cmp ) {
1515
1528
he_stat__add_stat (& iter -> stat , & he -> stat );
1516
1529
return iter ;
@@ -1730,24 +1743,6 @@ int hists__collapse_resort(struct hists *hists, struct ui_progress *prog)
1730
1743
return 0 ;
1731
1744
}
1732
1745
1733
- static int64_t hist_entry__sort (struct hist_entry * a , struct hist_entry * b )
1734
- {
1735
- struct hists * hists = a -> hists ;
1736
- struct perf_hpp_fmt * fmt ;
1737
- int64_t cmp = 0 ;
1738
-
1739
- hists__for_each_sort_list (hists , fmt ) {
1740
- if (perf_hpp__should_skip (fmt , a -> hists ))
1741
- continue ;
1742
-
1743
- cmp = fmt -> sort (fmt , a , b );
1744
- if (cmp )
1745
- break ;
1746
- }
1747
-
1748
- return cmp ;
1749
- }
1750
-
1751
1746
static void hists__reset_filter_stats (struct hists * hists )
1752
1747
{
1753
1748
hists -> nr_non_filtered_entries = 0 ;
@@ -2449,21 +2444,15 @@ static struct hist_entry *add_dummy_hierarchy_entry(struct hists *hists,
2449
2444
struct rb_node * * p ;
2450
2445
struct rb_node * parent = NULL ;
2451
2446
struct hist_entry * he ;
2452
- struct perf_hpp_fmt * fmt ;
2453
2447
bool leftmost = true;
2454
2448
2455
2449
p = & root -> rb_root .rb_node ;
2456
2450
while (* p != NULL ) {
2457
- int64_t cmp = 0 ;
2451
+ int64_t cmp ;
2458
2452
2459
2453
parent = * p ;
2460
2454
he = rb_entry (parent , struct hist_entry , rb_node_in );
2461
-
2462
- perf_hpp_list__for_each_sort_list (he -> hpp_list , fmt ) {
2463
- cmp = fmt -> collapse (fmt , he , pair );
2464
- if (cmp )
2465
- break ;
2466
- }
2455
+ cmp = hist_entry__collapse_hierarchy (he -> hpp_list , he , pair );
2467
2456
if (!cmp )
2468
2457
goto out ;
2469
2458
@@ -2521,16 +2510,10 @@ static struct hist_entry *hists__find_hierarchy_entry(struct rb_root_cached *roo
2521
2510
2522
2511
while (n ) {
2523
2512
struct hist_entry * iter ;
2524
- struct perf_hpp_fmt * fmt ;
2525
- int64_t cmp = 0 ;
2513
+ int64_t cmp ;
2526
2514
2527
2515
iter = rb_entry (n , struct hist_entry , rb_node_in );
2528
- perf_hpp_list__for_each_sort_list (he -> hpp_list , fmt ) {
2529
- cmp = fmt -> collapse (fmt , iter , he );
2530
- if (cmp )
2531
- break ;
2532
- }
2533
-
2516
+ cmp = hist_entry__collapse_hierarchy (he -> hpp_list , iter , he );
2534
2517
if (cmp < 0 )
2535
2518
n = n -> rb_left ;
2536
2519
else if (cmp > 0 )
0 commit comments