Skip to content

Commit

Permalink
Merge branch 'linuxkerneltravel:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
vvzxy authored Apr 16, 2024
2 parents 07ba774 + 73c9794 commit ad627df
Show file tree
Hide file tree
Showing 41 changed files with 1,573 additions and 365 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/eBPF_proc_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ jobs:
- name: Run proc_image
run: |
cd eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image
make proc_image
sudo ./proc_image -a -p 1 -t 1
make
sudo ./proc_image -a &
sudo ./controller -f
- name: Run test_proc
run: |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ebpf_mem_watcher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ on:
- "*"
paths:
- 'eBPF_Supermarket/Memory_Subsystem/mem_watcher/**'
- '.github/workflows/Memory_Subsystem__mem_watcher.yml'
- '.github/workflows/ebpf_mem_watcher.yml'
pull_request:
branches:
- "*"
paths:
- 'eBPF_Supermarket/Memory_Subsystem/mem_watcher/**'
- '.github/workflows/Memory_Subsystem__mem_watcher.yml'
- '.github/workflows/ebpf_mem_watcher.yml'

jobs:
libbpf-project-build-and-test:
mem_watcher-project-build-and-test:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
Expand All @@ -29,7 +29,7 @@ jobs:
- name: Run mem_watcher
continue-on-error: true
run: |
cd eBPF_Supermarket/Memory_Subsystem//mem_watcher/
cd eBPF_Supermarket/Memory_Subsystem/mem_watcher/
bpftool btf dump file /sys/kernel/btf/vmlinux format c > vmlinux.h
make
sudo timeout 20 ./mem_watcher
23 changes: 3 additions & 20 deletions .github/workflows/old_project_cpu_subsystem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ on:
- "*"
paths:
- 'eBPF_Supermarket/CPU_Subsystem/**'
- '.github/workflows/system_cpu.yml'
- '.github/workflows/old_project_cpu_subsystem.yml'
pull_request:
branches:
- "*"
paths:
- 'eBPF_Supermarket/CPU_Subsystem/**'
- '.github/workflows/system_cpu.yml'
- '.github/workflows/old_project_cpu_subsystem.yml'

jobs:
CPU-Subsystem-build-and-test:
Expand Down Expand Up @@ -82,21 +82,4 @@ jobs:
cd program
chmod +x run.sh
uname -r
./run.sh
cpu_watcher-project-build-and-test:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3

- name: Install dependencies and Init Env
run: |
sudo apt update
sudo apt install libbpf-dev clang llvm libelf-dev libpcap-dev gcc-multilib build-essential
git submodule update --init --recursive
- name: Run cpu_watcher
run: |
cd eBPF_Supermarket/CPU_Subsystem/cpu_watcher
make
sudo ./cpu_watcher
./run.sh
4 changes: 2 additions & 2 deletions .github/workflows/old_project_memory_subsystem.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: paf
name: Memory_Subsystem

on:
push:
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
bpftool btf dump file /sys/kernel/btf/vmlinux format c > vmlinux.h
sudo make procstat
sudo timeout 20 ./procstat
sysstat-project-build-and-test:
runs-on: ubuntu-20.04
steps:
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/old_project_net_subsystem.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: dns_cache
name: Network_Subsystem

on:
push:
branches:
- "*"
paths:
- 'eBPF_Supermarket/Network_Subsystem/old_project/ebpf_dns_cache/**'
- '.github/workflows/dns_cache.yml'
- 'eBPF_Supermarket/Network_Subsystem/old_project/**'
- '.github/workflows/old_project_net_subsystem.yml'
pull_request:
branches:
- "*"
paths:
- 'eBPF_Supermarket/Network_Subsystem/old_project/ebpf_dns_cache/**'
- '.github/workflows/dns_cache.yml'
- 'eBPF_Supermarket/Network_Subsystem/old_project/**'
- '.github/workflows/old_project_net_subsystem.yml'

jobs:
ebpf_dns_cache_build-and-test:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ eBPF_Supermarket/kvm_watcher/**/temp*
eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/.output/*
eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/proc_image
eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/test/test_proc
eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/controller

# libbpf_bootstrap
.output
Expand Down
3 changes: 2 additions & 1 deletion MagicEyes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,5 @@ if (NOT BpfObject_FOUND)
endif ()

add_subdirectory(src/backend)
add_subdirectory(src/bridge)
add_subdirectory(src/bridge)
add_subdirectory(src/magic_eyes_cli)
17 changes: 17 additions & 0 deletions MagicEyes/src/magic_eyes_cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
set(MAGIC_EYES_CLI_INSTALL_DIR magic_eyes_cli)

# 安装 MagicEyesCli 到 <intsall_dir>/sbin/

# 安装magic_eyes_cli文件夹到 <install_dir>/sbin/

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
DESTINATION ${MAGIC_EYES_CLI_INSTALL_DIR}
)

install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/magic_eyes_cli
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ WORLD_READ WORLD_EXECUTE
DESTINATION ${MAGIC_EYES_CLI_INSTALL_DIR})

install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/before_running.sh
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ WORLD_READ WORLD_EXECUTE
DESTINATION ${MAGIC_EYES_CLI_INSTALL_DIR})
72 changes: 72 additions & 0 deletions MagicEyes/src/magic_eyes_cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
## magic_eyes_cli 命令行前端

### 1. 简述

将所有的后端工具统一到一个命令行前端,并且具备自动补全功能。

Tips:**记得Tab**

### 2. 使用之前

```bash
mkdir build && cd build
cmake .. && make && make install
cd ./install/magic_eyes_cli
# 运行前置条件脚本
source ./before_running.sh
```

### 3. 使用

```bash
(venv) $ ./magic_eyes_cli -h
/home/fzy/Downloads/04_bcc_ebpf/MagicEyes
usage: magic_eyes_cli [-h] [-l | -c] {net,memory,system_diagnosis,process} ...

magic_eyes_cli: command tools for Linux kernel diagnosis and optimization

positional arguments:
{net,memory,system_diagnosis,process}
net tool for Linux net subsystem
memory tool for Linux memory subsystem
system_diagnosis tool for Linux system_diagnosis subsystem
process tool for Linux process subsystem

optional arguments:
-h, --help show this help message and exit

all of common options:
-l list all avaliable tools
-c check all tools dependency, and whether it can be run in current platform

eg: magic_eyes_cli -l
```

**固定命令**

magic_eyes_cli具有2个固定命令, 即

```bash
-l : 即list, 列出所有可用的后端命令
-c : 即check, 检查所有运行依赖项(暂未实现)
```

**动态命令**

{net,memory,system_diagnosis,process}为动态命令,会根据backend文件夹下的情况动态调整。

### 4. 例程

```bash
magic_eyes_cli process cpu_watcher -h
# <------------------ 自动补全 | 非自动补全
```

### 5.其他

```bash
# 生成requirements.txt
pip3 freeze > requirements.txt
# 安装
pip3 install -r requiredments.txt
```
7 changes: 7 additions & 0 deletions MagicEyes/src/magic_eyes_cli/backend_tool_modules/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## 后端工具描述脚本存放文件夹

1. 每个后端工具均有一个后端工具描述脚本
1. 描述后端工具名称
2. 描述后端工具依赖项,如内核配置选项,某些需要下载的依赖等
3. 原始文件请存放在各自工具文件夹的scripts中,在此文件夹创建软链接

19 changes: 19 additions & 0 deletions MagicEyes/src/magic_eyes_cli/backend_tool_modules/cpu_watcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
方案2: 采用后端工具描述文件,后续读取该文件,尤其是其中的依赖项,
并使用 magic_eyes_cli check 进行运行环境检查
描述:
1. 工具名,所属子系统
2. 工具的简要描述
3. 是否具有运行依赖项,依赖项是什么?
"""

class CpuWatcher():
def __init__(self):
self.tool_name = "cpu_watcher"
self.belong_to_subsystem = "process"
self.description = "A tool for analyzing CPU running status"
self.dependencies = {
""" 工具运行的依赖项 """
}

Empty file.
Empty file.
56 changes: 56 additions & 0 deletions MagicEyes/src/magic_eyes_cli/before_running.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/sh

MAGIC_EYES_CLI_INSTALL_DIR=$(dirname $(realpath $0))

check_conditions() {
# 判断python3是否存在
if /usr/bin/env python3 -V > /dev/null; then
echo "python 已安装"
else
echo "python 未安装"
return 1
fi
# 进入python venv环境
if . ./venv/bin/activate; then
echo "成功进入venv环境"
else
echo "进入venv环境失败"
return 1
fi
# 使用pip列出所有已安装的包,并搜索argcomplete,判断是否argcomplete是否存在
if pip list --verbose | grep -q "argcomplete"; then
echo "argcomplete 已经安装."
else
echo "argcomplete 未安装."
echo "尝试安装argcomplete"
pip3 install -r ./requirements.txt
if pip list --verbose | grep -q "argcomplete"; then
echo "argcomplete安装完成"
else
return 1
fi
fi
# 注册 magic_eyes_cli
if eval "$(register-python-argcomplete ./magic_eyes_cli)"; then
echo "magic_eyes_cli注册成功"
else
echo "magic_eyes_cli注册失败"
return 1
fi
return 0
}

# 调用函数并获取返回值
check_conditions
exit_status=$?
# 根据返回值输出最终结果
if [ $exit_status -eq 0 ]; then
echo "OK"
else
echo "条件不满足"
fi





Empty file.
Loading

0 comments on commit ad627df

Please sign in to comment.