iovisor / iovisor/bcc

Is there some mechanism for "sampling" tables at a periodic rate?

Open
#4,930 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
22.7k
Forks
4.1k
Avg merge
5d 13h
Merged PRs (30d)
3

Description

usecase: writing BPF programs that track how many of an event happens per second over time

I started down this path (code incomplete as i realised that this probably isn't the best way partway through):
```
#include
#include

BPF_HASH(counts, u32);
BPF_ARRAY_OF_MAPS(last_ten_counts, "counts", 10);

BPF_ARRAY(probing_start_time, u64, 1);
BPF_ARRAY(current_count, u64, 1);

static int count_wakeup(struct bpf_raw_tracepoint_args *ctx, struct task_struct *process) {
int key = 0;
u64* pst = probing_start_time.lookup(&key);
u64* cc = current_count.lookup(&key);
if (pst == 0 || cc == 0) {
return 0;
}
if (process->flags & PF_KTHREAD) {
return 0;
}
u32 taskID = process->tgid;
counts.atomic_increment(taskID);
u64 now = bpf_ktime_get_ns();
if (*pst == -1) {
*pst = now;
} else {
if ((now - *pst) >= 1000000000) {
*pst = now;

// copy counts to last_ten_counts[*cc]

*cc++;
if (cc >= 10) {
*cc = 0;
}
}
}
return 0;
}

RAW_TRACEPOINT_PROBE(sched_wakeup)
{
struct task_struct *p = (struct task_struct *)ctx->args[0];
return count_wakeup(ctx, p);
}
```

but then realised that this Seems rather unwieldy for what is seemingly a pretty basic profiling thing

is there some obvious solution i'm missing to track "rates" of stuff over time?

Contributor guide

No contributing guide indexed for this repository

Research direction

No repository file or test is named. Start with the sched_wakeup RAW_TRACEPOINT_PROBE example and its BPF_HASH and BPF_ARRAY maps; first clarify whether the request is for a reusable BCC mechanism or guidance, then define how periodic samples over time should be represented and verified.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, linux
Domain
observability-sre, operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.