From 685bf4a26112617c47df4fa54f62dcbb2f61d299 Mon Sep 17 00:00:00 2001 From: Hailong Liu Date: Wed, 18 May 2022 19:38:00 +0800 Subject: [PATCH] irqoff,nosched,runqslower: Add containerid for jitter Signed-off-by: Hailong Liu --- source/tools/detect/irqoff/irqoff.c | 75 ++++++++++++++++-- source/tools/detect/irqoff/irqoff.h | 3 + source/tools/monitor/sched/nosched/nosched.c | 75 ++++++++++++++++-- .../monitor/sched/nosched/nosched.comm.h | 3 + .../monitor/sched/runqslower/runqslower.c | 77 +++++++++++++++++-- .../monitor/sched/runqslower/runqslower.h | 3 + 6 files changed, 216 insertions(+), 20 deletions(-) diff --git a/source/tools/detect/irqoff/irqoff.c b/source/tools/detect/irqoff/irqoff.c index 9994a5aa..aeb802dd 100644 --- a/source/tools/detect/irqoff/irqoff.c +++ b/source/tools/detect/irqoff/irqoff.c @@ -215,14 +215,65 @@ static int attach_prog_to_perf(struct irqoff_bpf *obj, return ret; } +static int get_container(char *dockerid, int pid) +{ + char *buf; + FILE *fp; + int ret = -1; + char cgroup_path[32] = {0}; + + snprintf(cgroup_path, sizeof(cgroup_path), "/proc/%d/cgroup", pid); + + fp = fopen(cgroup_path, "r"); + if (!fp) + return errno; + + buf = malloc(4096*sizeof(char)); + if (!buf) { + ret = errno; + goto out2; + } + + while(fgets(buf, 4096, fp)) { + int stat = 0; + char *token, *pbuf = buf; + while((token = strsep(&pbuf, "/")) != NULL) { + if (stat == 1) { + stat++; + break; + } + if (!strncmp("docker", token, strlen("docker"))) + stat++; + } + + if (stat == 2) { + strncpy(dockerid, token, CONID_LEN - 1); + ret = 0; + goto out1; + } + } +out1: + free(buf); +out2: + fclose(fp); + return ret; +} + static void update_summary(struct summary* summary, const struct event *e) { int idx; + char buf[CONID_LEN] = {0}; summary->num++; idx = summary->num % CPU_ARRY_LEN; summary->total += e->delay; summary->cpus[idx] = e->cpu; + summary->jitter[idx] = e->delay/1000; + if (get_container(buf, e->pid)) + strncpy(summary->container[idx], "000000000000", sizeof(summary->container[idx])); + else + strncpy(summary->container[idx], buf, sizeof(summary->container[idx])); + if (summary->max.value < e->delay) { summary->max.value = e->delay; summary->max.cpu = e->cpu; @@ -251,13 +302,23 @@ static int record_summary(struct summary *summary, long offset, bool total) p = p+pos; pos = sprintf(p, " %d", summary->cpus[(idx+i)%CPU_ARRY_LEN]); } + for (i = 1; i <= CPU_ARRY_LEN; i++) { + p = p+pos; + pos = sprintf(p, " %5d", summary->jitter[(idx+i)%CPU_ARRY_LEN]); + } + for (i = 1; i <= CPU_ARRY_LEN; i++) { + p = p+pos; + pos = sprintf(p, " %s", summary->container[(idx+i)%CPU_ARRY_LEN]); + } + p = p+pos; + pos = sprintf(p, "\n"); + } else { + p = p+pos; + pos = sprintf(p, " %-4llu %-12llu %-3d %-9d %-15s\n", + summary->max.value/1000, summary->max.stamp/1000, + summary->max.cpu, summary->max.pid, summary->max.comm); } - p = p+pos; - pos = sprintf(p, " %-4llu %-12llu %-3d %-9d %-15s\n", - summary->max.value/1000, summary->max.stamp/1000, - summary->max.cpu, summary->max.pid, summary->max.comm); - if (total) fseek(filep, 0, SEEK_SET); else @@ -308,11 +369,13 @@ void irqoff_handler(int poll_fd, int map_fd) "TIME(irqoff)", "CPU", "COMM", "TID", "LAT(us)"); } else { int i; - char buf[78] = {' '}; + char buf[128] = {' '}; fprintf(filep, "irqoff\n"); for (i = 0; i < nr_cpus; i++) fprintf(filep, "cpu%d %s\n", i, buf); fseek(filep, 0, SEEK_SET); + for (i=0; i < 4; i++) + strncpy(summary.container[i], "000000000000", sizeof(summary.container[i])); } pb_opts.sample_cb = handle_event; diff --git a/source/tools/detect/irqoff/irqoff.h b/source/tools/detect/irqoff/irqoff.h index c39785ca..164e2825 100644 --- a/source/tools/detect/irqoff/irqoff.h +++ b/source/tools/detect/irqoff/irqoff.h @@ -4,6 +4,7 @@ #define TASK_COMM_LEN 16 #define CPU_ARRY_LEN 4 +#define CONID_LEN 13 struct info { __u64 prev_counter; @@ -40,6 +41,8 @@ struct summary { __u64 total; struct max_sum max; int cpus[CPU_ARRY_LEN]; + int jitter[CPU_ARRY_LEN]; + char container[CPU_ARRY_LEN][CONID_LEN]; }; #endif /* __LLCSTAT_H */ diff --git a/source/tools/monitor/sched/nosched/nosched.c b/source/tools/monitor/sched/nosched/nosched.c index 64ce1617..c087970a 100644 --- a/source/tools/monitor/sched/nosched/nosched.c +++ b/source/tools/monitor/sched/nosched/nosched.c @@ -174,14 +174,65 @@ static int prepare_dictory(char *path) return 0; } +static int get_container(char *dockerid, int pid) +{ + char *buf; + FILE *fp; + int ret = -1; + char cgroup_path[32] = {0}; + + snprintf(cgroup_path, sizeof(cgroup_path), "/proc/%d/cgroup", pid); + + fp = fopen(cgroup_path, "r"); + if (!fp) + return errno; + + buf = malloc(4096*sizeof(char)); + if (!buf) { + ret = errno; + goto out2; + } + + while(fgets(buf, 4096, fp)) { + int stat = 0; + char *token, *pbuf = buf; + while((token = strsep(&pbuf, "/")) != NULL) { + if (stat == 1) { + stat++; + break; + } + if (!strncmp("docker", token, strlen("docker"))) + stat++; + } + + if (stat == 2) { + strncpy(dockerid, token, CONID_LEN - 1); + ret = 0; + goto out1; + } + } +out1: + free(buf); +out2: + fclose(fp); + return ret; +} + static void update_summary(struct summary* summary, const struct event *e) { int idx; + char buf[CONID_LEN] = {0}; summary->num++; idx = summary->num % CPU_ARRY_LEN; summary->total += e->delay; summary->cpus[idx] = e->cpu; + summary->jitter[idx] = e->delay/1000; + if (get_container(buf, e->pid)) + strncpy(summary->container[idx], "000000000000", sizeof(summary->container[idx])); + else + strncpy(summary->container[idx], buf, sizeof(summary->container[idx])); + if (summary->max.value < e->delay) { summary->max.value = e->delay; summary->max.cpu = e->cpu; @@ -210,13 +261,23 @@ static int record_summary(struct summary *summary, long offset, bool total) p = p+pos; pos = sprintf(p, " %d", summary->cpus[(idx+i)%CPU_ARRY_LEN]); } + for (i = 1; i <= CPU_ARRY_LEN; i++) { + p = p+pos; + pos = sprintf(p, " %5d", summary->jitter[(idx+i)%CPU_ARRY_LEN]); + } + for (i = 1; i <= CPU_ARRY_LEN; i++) { + p = p+pos; + pos = sprintf(p, " %s", summary->container[(idx+i)%CPU_ARRY_LEN]); + } + p = p+pos; + pos = sprintf(p, "\n"); + } else { + p = p+pos; + pos = sprintf(p, " %-4llu %-12llu %-3d %-9d %-15s\n", + summary->max.value/1000, summary->max.stamp/1000, + summary->max.cpu, summary->max.pid, summary->max.comm); } - p = p+pos; - pos = sprintf(p, " %-4llu %-12llu %-3d %-9d %-15s\n", - summary->max.value/1000, summary->max.stamp/1000, - summary->max.cpu, summary->max.pid, summary->max.comm); - if (total) fseek(filep, 0, SEEK_SET); else @@ -266,11 +327,13 @@ void nosched_handler(int poll_fd) "TIME(nosched)", "CPU", "COMM", "TID", "LAT(us)"); } else { int i; - char buf[78] = {' '}; + char buf[128] = {' '}; fprintf(filep, "nosche\n"); for (i = 0; i < nr_cpus; i++) fprintf(filep, "cpu%d %s\n", i, buf); fseek(filep, 0, SEEK_SET); + for (i=0; i < CPU_ARRY_LEN; i++) + strncpy(summary.container[i], "000000000000", sizeof(summary.container[i])); } pb_opts.sample_cb = handle_event; pb = perf_buffer__new(poll_fd, 64, &pb_opts); diff --git a/source/tools/monitor/sched/nosched/nosched.comm.h b/source/tools/monitor/sched/nosched/nosched.comm.h index 28841b94..b1be4fac 100644 --- a/source/tools/monitor/sched/nosched/nosched.comm.h +++ b/source/tools/monitor/sched/nosched/nosched.comm.h @@ -15,6 +15,7 @@ #endif #define CPU_ARRY_LEN 4 +#define CONID_LEN 13 struct args { int flag; @@ -53,5 +54,7 @@ struct summary { __u64 total; struct max_sum max; int cpus[CPU_ARRY_LEN]; + int jitter[CPU_ARRY_LEN]; + char container[CPU_ARRY_LEN][CONID_LEN]; }; diff --git a/source/tools/monitor/sched/runqslower/runqslower.c b/source/tools/monitor/sched/runqslower/runqslower.c index f1da6c41..0b948182 100644 --- a/source/tools/monitor/sched/runqslower/runqslower.c +++ b/source/tools/monitor/sched/runqslower/runqslower.c @@ -202,14 +202,65 @@ static void sig_int(int signo) exiting = 1; } +static int get_container(char *dockerid, int pid) +{ + char *buf; + FILE *fp; + int ret = -1; + char cgroup_path[32] = {0}; + + snprintf(cgroup_path, sizeof(cgroup_path), "/proc/%d/cgroup", pid); + + fp = fopen(cgroup_path, "r"); + if (!fp) + return errno; + + buf = malloc(4096*sizeof(char)); + if (!buf) { + ret = errno; + goto out2; + } + + while(fgets(buf, 4096, fp)) { + int stat = 0; + char *token, *pbuf = buf; + while((token = strsep(&pbuf, "/")) != NULL) { + if (stat == 1) { + stat++; + break; + } + if (!strncmp("docker", token, strlen("docker"))) + stat++; + } + + if (stat == 2) { + strncpy(dockerid, token, CONID_LEN - 1); + ret = 0; + goto out1; + } + } +out1: + free(buf); +out2: + fclose(fp); + return ret; +} + static void update_summary(struct summary* summary, const struct event *e) { int idx; + char buf[CONID_LEN] = {0}; summary->num++; idx = summary->num % CPU_ARRY_LEN; summary->total += e->delta_us; summary->cpus[idx] = e->cpuid; + summary->jitter[idx] = e->delta_us/1000; + if (get_container(buf, e->pid)) + strncpy(summary->container[idx], "000000000000", sizeof(summary->container[idx])); + else + strncpy(summary->container[idx], buf, sizeof(summary->container[idx])); + if (summary->max.value < e->delta_us) { summary->max.value = e->delta_us; summary->max.cpu = e->cpuid; @@ -238,18 +289,26 @@ static int record_summary(struct summary *summary, long offset, bool total) p = p+pos; pos = sprintf(p, " %d", summary->cpus[(idx+i)%CPU_ARRY_LEN]); } + for (i = 1; i <= CPU_ARRY_LEN; i++) { + p = p+pos; + pos = sprintf(p, " %5d", summary->jitter[(idx+i)%CPU_ARRY_LEN]); + } + for (i = 1; i <= CPU_ARRY_LEN; i++) { + p = p+pos; + pos = sprintf(p, " %s", summary->container[(idx+i)%CPU_ARRY_LEN]); + } + p = p+pos; + pos = sprintf(p, "\n"); + } else { + p = p+pos; + pos = sprintf(p, " %-4llu %-12llu %-3d %-9d %-15s\n", + summary->max.value/1000, summary->max.stamp/1000, + summary->max.cpu, summary->max.pid, summary->max.comm); } - - p = p+pos; - pos = sprintf(p, " %-4llu %-12llu %-3d %-9d %-15s\n", - summary->max.value/1000, summary->max.stamp/1000, - summary->max.cpu, summary->max.pid, summary->max.comm); - if (total) fseek(filep, 0, SEEK_SET); else fseek(filep, (offset)*(p-buf+pos), SEEK_CUR); - fprintf(filep, "%s", buf); return 0; } @@ -350,11 +409,13 @@ int main(int argc, char **argv) "TIME(runslw)", "CPU", "COMM", "TID", "LAT(us)"); } else { int i; - char buf[78] = {' '}; + char buf[128] = {' '}; fprintf(filep, "rqslow\n"); for (i = 0; i < nr_cpus; i++) fprintf(filep, "cpu%d %s\n", i, buf); fseek(filep, 0, SEEK_SET); + for (i=0; i < 4; i++) + strncpy(summary.container[i], "000000000000", sizeof(summary.container[i])); } pb_opts.sample_cb = handle_event; pb = perf_buffer__new(bpf_map__fd(obj->maps.events), 64, &pb_opts); diff --git a/source/tools/monitor/sched/runqslower/runqslower.h b/source/tools/monitor/sched/runqslower/runqslower.h index ca492ab8..8f9253a0 100644 --- a/source/tools/monitor/sched/runqslower/runqslower.h +++ b/source/tools/monitor/sched/runqslower/runqslower.h @@ -4,6 +4,7 @@ #define TASK_COMM_LEN 16 #define CPU_ARRY_LEN 4 +#define CONID_LEN 13 struct event { char task[TASK_COMM_LEN]; @@ -28,6 +29,8 @@ struct summary { __u64 total; struct max_sum max; int cpus[CPU_ARRY_LEN]; + int jitter[CPU_ARRY_LEN]; + char container[CPU_ARRY_LEN][CONID_LEN]; }; struct args { -- Gitee