Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MagicEyes:统一可视化功能的实现 #963

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
1 change: 1 addition & 0 deletions MagicEyes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,4 @@ endif ()
add_subdirectory(src/backend)
add_subdirectory(src/bridge)
add_subdirectory(src/magic_eyes_cli)
add_subdirectory(src/visualization)
74 changes: 74 additions & 0 deletions MagicEyes/src/visualization/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# 设置最低 CMake 版本要求
cmake_minimum_required(VERSION 3.10)

# 定义项目名称
project(DataVisual LANGUAGES NONE)
#目标目录,install/visualization
set(VISUALIZATION_INSTALL_DIR visualization)
# 定义变量 A
set(EBPF_PROMETHEUS ${CMAKE_CURRENT_SOURCE_DIR}/eBPF_prometheus)


# 直接执行命令:go mod tidy
execute_process(
COMMAND go mod tidy
WORKING_DIRECTORY ${EBPF_PROMETHEUS}
RESULT_VARIABLE GO_MOD_TIDY_RESULT
OUTPUT_VARIABLE GO_MOD_TIDY_OUTPUT
ERROR_VARIABLE GO_MOD_TIDY_ERROR
)
if(NOT GO_MOD_TIDY_RESULT EQUAL 0)
message(FATAL_ERROR "Failed to run 'go mod tidy': ${GO_MOD_TIDY_ERROR}")
endif()

# 直接执行命令:go build
execute_process(
COMMAND go build -o ${EBPF_PROMETHEUS}/data-visual main.go
WORKING_DIRECTORY ${EBPF_PROMETHEUS}
RESULT_VARIABLE GO_BUILD_RESULT
OUTPUT_VARIABLE GO_BUILD_OUTPUT
ERROR_VARIABLE GO_BUILD_ERROR
)
if(NOT GO_BUILD_RESULT EQUAL 0)
message(FATAL_ERROR "Failed to build 'data-visual': ${GO_BUILD_ERROR}")
endif()
#将生成的data-visual可执行文件 安装到install/visualization目录下
install(PROGRAMS ${EBPF_PROMETHEUS}/data-visual
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ WORLD_READ WORLD_EXECUTE
DESTINATION ${VISUALIZATION_INSTALL_DIR}
)
#将checker,collector,dao,prom_core安装到安装到install/visualization目录下
install(DIRECTORY ${EBPF_PROMETHEUS}/checker
${EBPF_PROMETHEUS}/dao
${EBPF_PROMETHEUS}/prom_core
DESTINATION ${VISUALIZATION_INSTALL_DIR}
)
# 创建目录并生成文件
file(MAKE_DIRECTORY ${VISUALIZATION_INSTALL_DIR}/.output/data)
file(WRITE ${VISUALIZATION_INSTALL_DIR}/.output/data/offcpu_stack.txt "")


# 安装脚本文件 runimages.sh 到指定目录,并设置安装后的权限
install(PROGRAMS ${EBPF_PROMETHEUS}/runimages.sh
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ WORLD_READ WORLD_EXECUTE
DESTINATION ${VISUALIZATION_INSTALL_DIR}
)
# 执行脚本:runimages.sh
execute_process(
COMMAND ./runimages.sh
WORKING_DIRECTORY ${VISUALIZATION_INSTALL_DIR}
RESULT_VARIABLE RUNIMAGES_RESULT
OUTPUT_VARIABLE RUNIMAGES_OUTPUT
ERROR_VARIABLE RUNIMAGES_ERROR
)
# 将vis.sh安装到目标目录
install(PROGRAMS ${EBPF_PROMETHEUS}/vis.sh
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ WORLD_READ WORLD_EXECUTE
DESTINATION ${VISUALIZATION_INSTALL_DIR}
)

# 清理目标:可选
add_custom_target(clean_data
COMMAND ${CMAKE_COMMAND} -E rm -rf ${EBPF_PROMETHEUS}/dao/data.db ${EBPF_PROMETHEUS}/r/.output/data
COMMENT "Cleaning up generated data and files"
)
1 change: 1 addition & 0 deletions MagicEyes/src/visualization/eBPF_prometheus
40 changes: 0 additions & 40 deletions MagicEyes/src/visualization/run_images.sh

This file was deleted.

10 changes: 8 additions & 2 deletions eBPF_Supermarket/CPU_Subsystem/cpu_watcher/cpu_watcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ static int print_all()
return 0;
}

int count[25]={0};//定义一个count数组,用于汇总schedul()调度时间,以log2(时间间隔)为统计依据;
int count[25]={0} , cs_flag=0;//定义一个count数组,用于汇总schedul()调度时间,以log2(时间间隔)为统计依据;
static int handle_event(void *ctx, void *data,unsigned long data_sz)
{
const struct event *e = data;
Expand All @@ -449,6 +449,8 @@ static int handle_event(void *ctx, void *data,unsigned long data_sz)
i ++;
}
count[i]++;
if(!cs_flag)
cs_flag = 1;
return 0;
}
static int print_hstgram(int i,int max,int per_len)
Expand Down Expand Up @@ -1101,7 +1103,11 @@ int main(int argc, char **argv)
printf("Error polling perf buffer: %d\n", err);
break;
}
histogram();
struct cs_ctrl *cs_ctrl;
int ctrl_key = 0 ;
if(cs_flag){
histogram();
}
}
else if(env.SYSCALL_DELAY){
err = ring_buffer__poll(rb, 100 /* timeout, ms */); //ring_buffer__poll(),轮询打开ringbuf缓冲区。如果有事件,handle_event函数会执行
Expand Down
26 changes: 26 additions & 0 deletions eBPF_Visualization/eBPF_prometheus/vis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# 检查参数数量是否足够
if [ $# -lt 4 ]; then
echo "Usage: $0 <param1> <param2> <param3> <param4> [other_args...]"
exit 1
fi

# 获取传递的参数
PARAM1=$1
PARAM2=$2
PARAM3=$3
PARAM4=$4
OTHER_ARGS=${@:5} # 从第5个参数开始的所有额外参数

# 构建路径
TARGET_DIR="../backend/${PARAM1}/${PARAM2}/bin"

# 构建命令
COMMAND="sudo ./data-visual collect ${TARGET_DIR}/${PARAM3} ${PARAM4} ${OTHER_ARGS}"

# 显示即将执行的命令(可选)
echo "Executing command: ${COMMAND}"

# 执行命令
eval "${COMMAND}"