From 3827223866ea21db1f2ba94cfb881dee802e1484 Mon Sep 17 00:00:00 2001 From: Hailong Liu Date: Thu, 10 Mar 2022 16:55:28 +0800 Subject: [PATCH] nosched: Format the output of nosched Aligin the outputs of schedule monitor, prepare for sysom. Signed-off-by: Hailong Liu --- .../monitor/sched/nosched/bpf/nosched.bpf.c | 6 ++-- source/tools/monitor/sched/nosched/nosched.c | 31 +++++++++++++++---- .../monitor/sched/nosched/nosched.comm.h | 4 +-- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/source/tools/monitor/sched/nosched/bpf/nosched.bpf.c b/source/tools/monitor/sched/nosched/bpf/nosched.bpf.c index 9cba4a19..38769d31 100644 --- a/source/tools/monitor/sched/nosched/bpf/nosched.bpf.c +++ b/source/tools/monitor/sched/nosched/bpf/nosched.bpf.c @@ -91,15 +91,13 @@ int BPF_KPROBE(account_process_tick, struct task_struct *p, int user_tick) struct latinfo lati, *latp; struct args args, *argsp; - __builtin_memset(&args_key, 0, sizeof(int)); argsp = bpf_map_lookup_elem(&args_map, &args_key); if (!argsp) return 0; if(!test_tsk_need_resched(p, _(argsp->flag))) - //||system_state == SYSTEM_BOOTING) - return 0; + return 0; now = bpf_ktime_get_ns(); @@ -128,6 +126,8 @@ int BPF_KPROBE(account_process_tick, struct task_struct *p, int user_tick) bpf_get_current_comm(&ext_val.comm, sizeof(ext_val.comm)); ext_val.pid = bpf_get_current_pid_tgid(); ext_val.nosched_ticks = latp->ticks_without_resched; + ext_val.cpu = cpuid; + ext_val.stamp = latp->last_seen_need_resched_ns; bpf_map_update_elem(&stackmap_ext, &ext_key, &ext_val, BPF_ANY); bpf_printk("%s :lat is %ld us, %d ticks\n", ext_val.comm, resched_latency/1000, latp->ticks_without_resched); diff --git a/source/tools/monitor/sched/nosched/nosched.c b/source/tools/monitor/sched/nosched/nosched.c index 6573ac8f..423660c9 100644 --- a/source/tools/monitor/sched/nosched/nosched.c +++ b/source/tools/monitor/sched/nosched/nosched.c @@ -7,14 +7,15 @@ #include #include #include +#include #include #include #include #include #include /* bpf_obj_pin */ #include -#include "nosched.comm.h" #include "bpf/nosched.skel.h" +#include "nosched.comm.h" #define MAX_SYMS 300000 static struct ksym syms[MAX_SYMS]; @@ -139,18 +140,36 @@ static void print_stack(int fd, struct ext_key *key) } } +#define SEC_TO_NS (1000*1000*1000) +static void stamp_to_date(__u64 stamp, char dt[], int len) +{ + time_t t, diff, last; + struct tm *tm; + struct timespec ts; + + clock_gettime(CLOCK_MONOTONIC, &ts); + time(&t); + diff = ts.tv_sec*SEC_TO_NS + ts.tv_nsec - stamp; + diff = diff/SEC_TO_NS; + + last = t - diff; + tm = localtime(&last); + strftime(dt, len, "%F_%H:%M:%S", tm); +} + static void print_stacks(int fd, int ext_fd) { + char dt[64] = {0}; struct ext_key ext_key = {}, next_key; struct ext_val value; - printf("***********************************\n"); + fprintf(stdout, "%-21s %-6s %-16s %-8s %-10s\n", "TIME", "CPU", "COMM", "TID", "LAT(us)"); while (bpf_map_get_next_key(ext_fd, &ext_key, &next_key) == 0) { bpf_map_lookup_elem(ext_fd, &next_key, &value); - printf("%s<%d> [%lld.%lld]: lat=%lldus, lat_tick=%d\n", - value.comm, value.pid, next_key.stamp/(1000000000), - next_key.stamp%(1000000000), value.lat_us, - value.nosched_ticks); + memset(dt, 0, sizeof(dt)); + stamp_to_date(value.stamp, dt, sizeof(dt)); + fprintf(stdout, "%-21s %-6d %-16s %-8d %-10llu\n", + dt, value.cpu, value.comm, value.pid, value.lat_us); print_stack(fd, &next_key); printf("----------------------\n"); bpf_map_delete_elem(ext_fd, &next_key); diff --git a/source/tools/monitor/sched/nosched/nosched.comm.h b/source/tools/monitor/sched/nosched/nosched.comm.h index d6c4acda..77d26388 100644 --- a/source/tools/monitor/sched/nosched/nosched.comm.h +++ b/source/tools/monitor/sched/nosched/nosched.comm.h @@ -34,9 +34,9 @@ struct ext_key { }; struct ext_val { - int pid; + int pid, cpu; int nosched_ticks; - __u64 lat_us; + __u64 lat_us, stamp; char comm[TASK_COMM_LEN]; }; -- Gitee