Skip to content

Commit 2367f70

Browse files
committed
add extra histogram bucket for values more than 65536
1 parent 804e0a8 commit 2367f70

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

src/analysis.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/progs/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ static __always_inline void update_stats_log(u32 val)
174174
{
175175
u32 key = 0, i = 0, tmp = 2;
176176

177-
#pragma clang loop unroll_count(16)
178-
for (; i < 16; i++) {
177+
#pragma clang loop unroll_count(LAST_STATS_BUCKET)
178+
for (; i < LAST_STATS_BUCKET; i++) {
179179
if (val < tmp)
180180
break;
181181
tmp <<= 1;

src/progs/shared.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ enum rule_type {
199199
};
200200

201201
#define MAX_RULE_COUNT 8
202+
#define MAX_STATS_BUCKETS 17
203+
#define LAST_STATS_BUCKET (MAX_STATS_BUCKETS - 1)
202204
typedef struct {
203205
int expected[MAX_RULE_COUNT];
204206
int op[MAX_RULE_COUNT];

0 commit comments

Comments
 (0)