Skip to content

Commit

Permalink
Merge pull request #944 from Monkey857/develop
Browse files Browse the repository at this point in the history
kvm_watcher:加入容器系统调用延迟统计,并适配Magic可视化
  • Loading branch information
nanshuaibo authored Dec 2, 2024
2 parents 52b1c62 + 351aeaa commit 5197447
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 24 deletions.
23 changes: 15 additions & 8 deletions MagicEyes/src/backend/hypervisor/kvm_watcher/src/kvm_watcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "trace_helpers.h"
#include "uprobe_helpers.h"
#include "hypervisor/kvm_watcher/kvm_watcher.skel.h"

//可视化调整输出格式
int is_first = 1;
// 创建并打开临时文件
Expand Down Expand Up @@ -563,10 +562,15 @@ static int handle_event(void *ctx, void *data, size_t data_sz) {
break;
}
case CONTAINER_SYSCALL: {
printf("%-8u %-22s %-10lld %-10lld %-16s\n", e->syscall_data.pid,
if(env.show){
printf("%-10lld %-10lld\n",e->syscall_data.delay,e->syscall_data.syscall_id);
break;
}else{
printf("%-8u %-22s %-10lld %-10lld %-16s\n", e->syscall_data.pid,
e->syscall_data.container_id, e->syscall_data.delay,
e->syscall_data.syscall_id, e->syscall_data.comm);
break;
break;
}
}
case HALT_POLL: {
// 使用 e->halt_poll_data 访问 HALT_POLL 特有成员
Expand Down Expand Up @@ -779,8 +783,12 @@ static int print_event_head(struct env *env) {
"VAILD?");
break;
case CONTAINER_SYSCALL:
printf("%-8s %-22s %-9s %10s %-16s\n", "PID", "CONTAINER_ID",
"DELAY(us)", "SYSCALLID", "COMM");
if(env->show){
printf("%-9s %10s\n", "DELAY(us)","SYSCALLID");
}else{
printf("%-8s %-22s %-9s %10s %-16s\n", "PID", "CONTAINER_ID",
"DELAY(us)", "SYSCALLID", "COMM");
}
break;
case EXIT:
//可视化调整输出格式
Expand Down Expand Up @@ -1242,7 +1250,7 @@ void print_map_and_check_error(int (*print_func)(struct kvm_watcher_bpf *),
void print_logo() {
char *logo = LOGO_STRING;
char command[512];
sprintf(command, "echo \"%s\" | /usr/games/lolcat", logo);
sprintf(command, "bash -c 'echo \"%s\" | /usr/games/lolcat'", logo);
system(command);
}

Expand Down Expand Up @@ -1316,9 +1324,8 @@ int main(int argc, char **argv) {
fprintf(stderr, "Please specify an option using %s.\n", OPTIONS_LIST);
goto cleanup;
}
err = ring_buffer__poll(rb, RING_BUFFER_TIMEOUT_MS /* timeout, ms */);
while (!exiting) {
//err = ring_buffer__poll(rb, RING_BUFFER_TIMEOUT_MS /* timeout, ms */);
err = ring_buffer__poll(rb, RING_BUFFER_TIMEOUT_MS /* timeout, ms */);
if (env.execute_hypercall) {
print_map_and_check_error(print_hc_map, skel, "hypercall", err);
}
Expand Down
107 changes: 96 additions & 11 deletions MagicEyes/src/visualization/vscode_ext/panels/kvm_watcher.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,94 @@
},
"gridPos": {
"h": 8,
"w": 10,
"w": 12,
"x": 0,
"y": 0
},
"id": 24,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "single"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "CzHV6L_Ik"
},
"exemplar": true,
"expr": "bpf_metrics{bpf_out_data=\"DELAY(us)\"}",
"interval": "",
"legendFormat": "",
"refId": "A"
}
],
"title": "container_syscall_delay",
"type": "timeseries"
},
{
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 0,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 10,
"x": 0,
"y": 8
},
"id": 10,
"options": {
"legend": {
Expand Down Expand Up @@ -164,7 +248,7 @@
"h": 8,
"w": 11,
"x": 10,
"y": 0
"y": 8
},
"id": 8,
"options": {
Expand Down Expand Up @@ -233,7 +317,8 @@
"mode": "absolute",
"steps": [
{
"color": "green"
"color": "green",
"value": null
},
{
"color": "red",
Expand All @@ -248,7 +333,7 @@
"h": 7,
"w": 10,
"x": 0,
"y": 8
"y": 16
},
"id": 6,
"libraryPanel": {
Expand Down Expand Up @@ -354,7 +439,7 @@
"h": 7,
"w": 11,
"x": 10,
"y": 8
"y": 16
},
"id": 4,
"options": {
Expand Down Expand Up @@ -446,7 +531,7 @@
"h": 7,
"w": 10,
"x": 0,
"y": 15
"y": 23
},
"id": 12,
"options": {
Expand Down Expand Up @@ -530,7 +615,7 @@
"h": 7,
"w": 11,
"x": 10,
"y": 15
"y": 23
},
"id": 14,
"options": {
Expand Down Expand Up @@ -614,7 +699,7 @@
"h": 7,
"w": 10,
"x": 0,
"y": 22
"y": 30
},
"id": 16,
"options": {
Expand Down Expand Up @@ -698,7 +783,7 @@
"h": 7,
"w": 11,
"x": 10,
"y": 22
"y": 30
},
"id": 18,
"options": {
Expand Down Expand Up @@ -782,7 +867,7 @@
"h": 7,
"w": 10,
"x": 0,
"y": 29
"y": 37
},
"id": 20,
"options": {
Expand Down Expand Up @@ -867,7 +952,7 @@
"h": 7,
"w": 11,
"x": 10,
"y": 29
"y": 37
},
"id": 22,
"options": {
Expand Down
19 changes: 14 additions & 5 deletions eBPF_Supermarket/kvm_watcher/src/kvm_watcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,15 @@ static int handle_event(void *ctx, void *data, size_t data_sz) {
break;
}
case CONTAINER_SYSCALL: {
printf("%-8u %-22s %-10lld %-10lld %-16s\n", e->syscall_data.pid,
if(env.show){
printf("%-10lld %-10lld\n",e->syscall_data.delay,e->syscall_data.syscall_id);
break;
}else{
printf("%-8u %-22s %-10lld %-10lld %-16s\n", e->syscall_data.pid,
e->syscall_data.container_id, e->syscall_data.delay,
e->syscall_data.syscall_id, e->syscall_data.comm);
break;
break;
}
}
case HALT_POLL: {
// 使用 e->halt_poll_data 访问 HALT_POLL 特有成员
Expand Down Expand Up @@ -779,8 +784,12 @@ static int print_event_head(struct env *env) {
"VAILD?");
break;
case CONTAINER_SYSCALL:
printf("%-8s %-22s %-9s %10s %-16s\n", "PID", "CONTAINER_ID",
"DELAY(us)", "SYSCALLID", "COMM");
if(env->show){
printf("%-9s %10s\n", "DELAY(us)","SYSCALLID");
}else{
printf("%-8s %-22s %-9s %10s %-16s\n", "PID", "CONTAINER_ID",
"DELAY(us)", "SYSCALLID", "COMM");
}
break;
case EXIT:
//可视化调整输出格式
Expand Down Expand Up @@ -1242,7 +1251,7 @@ void print_map_and_check_error(int (*print_func)(struct kvm_watcher_bpf *),
void print_logo() {
char *logo = LOGO_STRING;
char command[512];
sprintf(command, "echo \"%s\" | /usr/games/lolcat", logo);
sprintf(command, "bash -c 'echo \"%s\" | /usr/games/lolcat'", logo);
system(command);
}

Expand Down

0 comments on commit 5197447

Please sign in to comment.