Skip to content

Commit a7c2051

Browse files
mykyta5anakryiko
authored andcommitted
veristat: Fix top source line stat collection
Fix comparator implementation to return most popular source code lines instead of least. Introduce min/max macro for building veristat outside of Linux repository. Signed-off-by: Mykyta Yatsenko <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 58ecb3a commit a7c2051

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

tools/testing/selftests/bpf/veristat.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@
2626
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
2727
#endif
2828

29+
#ifndef max
30+
#define max(a, b) ((a) > (b) ? (a) : (b))
31+
#endif
32+
33+
#ifndef min
34+
#define min(a, b) ((a) < (b) ? (a) : (b))
35+
#endif
36+
2937
enum stat_id {
3038
VERDICT,
3139
DURATION,
@@ -904,7 +912,7 @@ static int line_cnt_cmp(const void *a, const void *b)
904912
const struct line_cnt *b_cnt = (const struct line_cnt *)b;
905913

906914
if (a_cnt->cnt != b_cnt->cnt)
907-
return a_cnt->cnt < b_cnt->cnt ? -1 : 1;
915+
return a_cnt->cnt > b_cnt->cnt ? -1 : 1;
908916
return strcmp(a_cnt->line, b_cnt->line);
909917
}
910918

0 commit comments

Comments
 (0)