From 9216ecefa02a1e0f3058312d8b1c8375ac1fb459 Mon Sep 17 00:00:00 2001 From: Hailong Liu Date: Wed, 24 May 2023 05:10:02 +0000 Subject: [PATCH] unity_nosched: Limit the output times to 2 Signed-off-by: Hailong Liu --- .../unity/collector/plugin/unity_nosched/stacktrace.c | 4 ++-- .../collector/plugin/unity_nosched/unity_nosched.bpf.c | 6 ++++-- .../unity/collector/plugin/unity_nosched/unity_nosched.c | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/source/tools/monitor/unity/collector/plugin/unity_nosched/stacktrace.c b/source/tools/monitor/unity/collector/plugin/unity_nosched/stacktrace.c index 70b7b2ae..02927eee 100644 --- a/source/tools/monitor/unity/collector/plugin/unity_nosched/stacktrace.c +++ b/source/tools/monitor/unity/collector/plugin/unity_nosched/stacktrace.c @@ -14,7 +14,7 @@ //#include "unity_nosched.h" #define MAX_SYMS 300000 -#define PERF_MAX_STACK_DEPTH 32 +#define PERF_MAX_STACK_DEPTH 127 struct ksym { long addr; char *name; @@ -122,7 +122,7 @@ void print_stack(int fd, __u32 ret, struct ksym *syms, FILE *filep) if (!filep) filep = stdout; if (bpf_map_lookup_elem(fd, &ret, &ip) == 0) { - for (i = 0; i < PERF_MAX_STACK_DEPTH - 1; i++) + for (i = 1; i < PERF_MAX_STACK_DEPTH - 1; i++) print_ksym(ip[i], syms, filep); } else { if ((int)(ret) < 0) diff --git a/source/tools/monitor/unity/collector/plugin/unity_nosched/unity_nosched.bpf.c b/source/tools/monitor/unity/collector/plugin/unity_nosched/unity_nosched.bpf.c index 323d2097..1b3ca4dd 100644 --- a/source/tools/monitor/unity/collector/plugin/unity_nosched/unity_nosched.bpf.c +++ b/source/tools/monitor/unity/collector/plugin/unity_nosched/unity_nosched.bpf.c @@ -126,6 +126,7 @@ int BPF_KPROBE(account_process_tick, struct task_struct *p, int user_tick) latp->last_seen_need_resched_ns = now; latp->ticks_without_resched = 0; latp->last_perf_event = now; + latp->recorded = 0; } else { latp->ticks_without_resched++; resched_latency = now - latp->last_perf_event; @@ -138,10 +139,10 @@ int BPF_KPROBE(account_process_tick, struct task_struct *p, int user_tick) bpf_get_current_comm(&event.comm, sizeof(event.comm)); event.ret = bpf_get_stackid(ctx, &stackmap, KERN_STACKID_FLAGS); latp->last_perf_event = now; - if (latp->recorded == 0) { + if (latp->recorded < 2) { bpf_perf_event_output(ctx, &events, BPF_F_CURRENT_CPU, &event, sizeof(event)); - latp->recorded = 1; + latp->recorded = latp->recorded + 1; } } } @@ -149,6 +150,7 @@ int BPF_KPROBE(account_process_tick, struct task_struct *p, int user_tick) __builtin_memset(&lati, 0, sizeof(struct latinfo)); lati.last_seen_need_resched_ns = now; lati.last_perf_event = now; + lati.recorded = 0; bpf_map_update_elem(&info_map, &cpuid, &lati, BPF_ANY); } diff --git a/source/tools/monitor/unity/collector/plugin/unity_nosched/unity_nosched.c b/source/tools/monitor/unity/collector/plugin/unity_nosched/unity_nosched.c index b06e06c7..444e5b3f 100644 --- a/source/tools/monitor/unity/collector/plugin/unity_nosched/unity_nosched.c +++ b/source/tools/monitor/unity/collector/plugin/unity_nosched/unity_nosched.c @@ -125,8 +125,8 @@ void handle_event(void *ctx, int cpu, void *data, __u32 data_sz) e.delay = e.delay/(1000*1000); if (e.cpu > nr_cpus - 1) return; - if (e.delay > 200) { /* we use 100ms to control the frequency of output */ - printf("delay=%lld\n", e.delay); + if (e.delay > 100) { /* we use 100ms to control the frequency of output */ + printf("%s[%d] delay=%lld\n", e.comm, e.pid, e.delay); record_stack(&e); } if (e.exit != 0) -- Gitee