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
xiaozhangchannel authored Jul 22, 2024
2 parents 963444c + 135f40a commit dea1666
Show file tree
Hide file tree
Showing 58 changed files with 3,276 additions and 832 deletions.
17 changes: 11 additions & 6 deletions .github/workflows/ebpf_cpu_watcher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,23 @@ jobs:
- name: Install dependencies
run: |
sudo apt update
sudo apt install libbpf-dev clang llvm libelf-dev libpcap-dev gcc-multilib build-essential
sudo apt install -y libbpf-dev clang llvm libelf-dev libpcap-dev gcc-multilib build-essential
git submodule update --init --recursive
- name: Run cpu_watcher
- name: Build cpu_watcher
run: |
cd eBPF_Supermarket/CPU_Subsystem/cpu_watcher/
make
sudo ./cpu_watcher
- name: Run test_cpuwatcher

- name: Run cpu_watcher
run: |
sudo ./eBPF_Supermarket/CPU_Subsystem/cpu_watcher/cpu_watcher
- name: Build test_cpuwatcher
run: |
cd eBPF_Supermarket/CPU_Subsystem/cpu_watcher/test
make
./test_cpuwatcher
- name: Run test_cpuwatcher
run: |
./eBPF_Supermarket/CPU_Subsystem/cpu_watcher/test/test_cpuwatcher
2 changes: 1 addition & 1 deletion .github/workflows/ebpf_mem_watcher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ jobs:
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
sudo ./mem_watcher -f -i 10
85 changes: 82 additions & 3 deletions MagicEyes/src/visualization/vscode_ext/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,29 @@

![](./images/lmp_vscode_ext.gif)

### 2. 相关提示
### 2. 安装与使用

设置可视化面板存放路径
#### 2.1 导入插件

![import_vscode_ext](./images/import_vscode_ext.png)

安装成功如下:

![lmp_ext_install_success](./images/lmp_ext_install_success.png)

#### 2.2 设置

- 启动grafana(可以在docker中启动),启动prometheus与BPF后端采集程序可以看到数据呈现
- 设置IP地址与端口,默认端口是`localhost:3000`
- 设置token

![create_token](./images/create_token.png)

> [grafana官方_创建token](https://grafana.com/docs/grafana/latest/administration/service-accounts/#create-a-service-account-in-grafana)
![set_token](./images/set_token.png)

- 设置可视化面板存放路径

> 注意:别忘记面板路径后面加 "/"
Expand All @@ -20,7 +40,59 @@

![](./images/error_info.png)

### 3. 开发注意事项
- 设置工具配置文件

请将配置文件路径输入在设置中,如`/home/fzy/lmp_tool_ext_config.json`,输入完成后,敲击enter键,程序将根据配置文件中的子系统与工具,生成左侧侧边栏的按钮。

配置文件写法参照 `.../MagicEyes/src/visualization/vscode_ext/tool_config_sample/lmp_tool_ext_config.json`

#### 2.3 如何增加工具

配置文件如下。假如有一个工具,名为 mem_checker,输入 memory子系统,则 subsystem_list 不用修改,只需要在内存子系统处增加即可。如果有一个工具,名为 V4L2_tracer,属于 media子系统,则需要在subsystem_list中增加 media 子系统,并在 subsystem 下相应增加,不再赘述。

```json
{
"name" : "lmp_tool_vscode_extension_config",
"version" : "0.0.1",
"subsystem_list" : [
"CPU",
"memory",
"fs",
"network",
"system_diagnosis",
"hypervisor"
],
"subsystem" : [
{
"description" : "Linux CPU子系统观测工具集",
"tools" : [......]
},
{
"description" : "Linux 内存子系统观测工具集",
"tools" : [
{
"name": "mem_watcher",
"description" : "内存观测"
},
{
"name": "mem_checker",
"description" : "内存检查"
}
]
}
}
```


### 3. 插件开发

#### 3.1 开发

安装yarn并且通过`yarn install`安装所需依赖

> tips: 按 F5 开启调试

#### 3.2 开发注意事项

1. yo code生成的框架,vscode最小版本是1.90,需要修改为1.74,不然我当前的版本。1.89无法运行插件
2. tsconfig
Expand All @@ -42,5 +114,12 @@
}
```

3. 打包vsix

```bash
# 进入插件开发文件夹
vsce package
```



Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@
"default": "/home/fzy/Desktop/panels/",
"description": "the default panels search path",
"order": 4
}
},
"grafana-vscode.default_tool_config_file": {
"type": "string",
"default": "/home/fzy/lmp_tool_ext_config.json",
"description": "the default tool config file",
"order": 5
}
}
},
"viewsContainers": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import { setVersion } from "./util";
import * as fs from 'fs' // fzy: 为了检查面板文件是否存在


let default_panel_path = "/home/fzy/Desktop/panels/" // fzy: 为了检查面板文件是否存在
let default_panel_path = "/home/fzy/Desktop/panels/"; // fzy: 为了检查面板文件是否存在
let default_tool_config_file = "/home/fzy/lmp_tool_ext_config.json";
let sub_key = 0; // 子系统计数,用于与element.label进行匹配


// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed
Expand Down Expand Up @@ -71,7 +74,14 @@ export async function activate(ctx: vscode.ExtensionContext) {
default_panel_path = String(settings.get("default_panel_path"));
//console.log("path = ", default_panel_path);
}

// fzy, 让用户可以在设置中修改json配置文件放置路径及配置文件名字
if (event.affectsConfiguration("grafana-vscode.default_tool_config_file")) {
const settings = vscode.workspace.getConfiguration("grafana-vscode");
default_tool_config_file = String(settings.get("default_tool_config_file"));
//console.log("file = ", default_tool_config_file);
sub_key = 0; // 全局变量先清零,不然 subsystem无法匹配
TreeViewProvider.initTreeViewItem();
}
});

vscode.commands.registerCommand('grafana-vscode.setPassword', async () => {
Expand All @@ -97,6 +107,7 @@ export function deactivate() {
// ---------------------------------------------------------------------------------
// fzy
import { CancellationToken, Event, ProviderResult, TreeDataProvider, TreeItem, TreeItemCollapsibleState, window} from "vscode";
import { json } from "stream/consumers";

// 扩展 TreeItem
/*
Expand Down Expand Up @@ -126,15 +137,26 @@ export class TreeItemNode extends TreeItem {
*/

export class TreeViewProvider implements TreeDataProvider<TreeItem> {

onDidChangeTreeData?: Event<void | TreeItem | TreeItem[] | null | undefined> | undefined;

getTreeItem(element: TreeItem): TreeItem | Thenable<TreeItem> {
return element;
}
getChildren(element?: TreeItem | undefined): ProviderResult<TreeItem[]> {
let jsonData: any; // 保存 json 数据
jsonData = readLmpConfig(); // 读取json配置文件信息


let arr: TreeItem[] = new Array();
// treeview 根节点
if (element == undefined) {
for (const key in jsonData.subsystem_list) {
let item: TreeItem = new TreeItem(jsonData.subsystem_list[key], TreeItemCollapsibleState.Expanded);
item.description = jsonData.subsystem[key].description;
arr.push(item);
}
/*
let item1: TreeItem = new TreeItem("CPU", TreeItemCollapsibleState.Expanded);
item1.description = "Linux CPU子系统观测工具集";
arr.push(item1);
Expand All @@ -154,11 +176,41 @@ export class TreeViewProvider implements TreeDataProvider<TreeItem> {
let item5: TreeItem = new TreeItem("hypervisior", TreeItemCollapsibleState.Expanded);
item5.description = "Linux 虚拟化子系统工具集";
arr.push(item5);
*/

return arr;
}
// treeview 子节点
else {
//for (let sub_key = 0; sub_key <= 5; sub_key++) {
if (element.label == jsonData.subsystem_list[sub_key]) { // 遍历所有子系统
//console.log("jsonData.subsystem_list[key] = ", jsonData.subsystem_list[sub_key]);
for (const tool_num in jsonData.subsystem[sub_key].tools) { // 遍历子系统下的所有工具
let tool_name = jsonData.subsystem[sub_key].tools[tool_num].name;
let tool_description = jsonData.subsystem[sub_key].tools[tool_num].description;
let item1:TreeItem = new TreeItem(tool_name, TreeItemCollapsibleState.None);
item1.description = tool_description;
let tool_command = {
title: tool_name,
command: 'itemClick',
tooltip: "点击将呈现工具的grafana可视化面板",
arguments: [
tool_name
]
}
item1.command = tool_command;
arr.push(item1);
}
sub_key++; // key + 1, 匹配下一个子系统
//console.log("sub_key = ", sub_key);
return arr;
}
else {
return null;
}
}
}
/*
if (element.label == 'CPU') {
// *****************************************************************************
//let item1: TreeItem = new TreeItem("cpu_watcher", TreeItemCollapsibleState.None);
Expand All @@ -168,7 +220,7 @@ export class TreeViewProvider implements TreeDataProvider<TreeItem> {
let command_cpu_watcher = {
title: cpu_watcher_label,
command: 'itemClick',
tooltip: "点击将呈现net_watcher的grafana的可视化面板",
tooltip: "点击将呈现cpu_watcher的grafana的可视化面板",
arguments: [
cpu_watcher_label
]
Expand All @@ -182,7 +234,7 @@ export class TreeViewProvider implements TreeDataProvider<TreeItem> {
let command_proc_image = {
title: proc_iamge_label,
command: 'itemClick',
tooltip: "点击将呈现net_watcher的grafana的可视化面板",
tooltip: "点击将呈现proc_image的grafana的可视化面板",
arguments: [
proc_iamge_label
]
Expand Down Expand Up @@ -214,7 +266,7 @@ export class TreeViewProvider implements TreeDataProvider<TreeItem> {
let command_net_manager = {
title: net_manager_label,
command: 'itemClick',
tooltip: "点击将呈现net_watcher的grafana的可视化面板",
tooltip: "点击将呈现net_manager的grafana的可视化面板",
arguments: [
net_manager_label
]
Expand All @@ -231,7 +283,7 @@ export class TreeViewProvider implements TreeDataProvider<TreeItem> {
let command_mem_watcher = {
title: mem_watcher_label,
command: 'itemClick',
tooltip: "点击将呈现net_watcher的grafana的可视化面板",
tooltip: "点击将呈现mem_watcher的grafana的可视化面板",
arguments: [
mem_watcher_label
]
Expand All @@ -248,7 +300,7 @@ export class TreeViewProvider implements TreeDataProvider<TreeItem> {
let command_stack_analyzer = {
title: stack_analyzer_label,
command: 'itemClick',
tooltip: "点击将呈现net_watcher的grafana的可视化面板",
tooltip: "点击将呈现stack_analyzer的grafana的可视化面板",
arguments: [
stack_analyzer_label
]
Expand All @@ -265,7 +317,7 @@ export class TreeViewProvider implements TreeDataProvider<TreeItem> {
let command_kvm_watcher = {
title: kvm_watcher_label,
command: 'itemClick',
tooltip: "点击将呈现net_watcher的grafana的可视化面板",
tooltip: "点击将呈现kvm_watcher的grafana的可视化面板",
arguments: [
kvm_watcher_label
]
Expand All @@ -278,14 +330,42 @@ export class TreeViewProvider implements TreeDataProvider<TreeItem> {
else {
return null;
}
}
}
*/
public static initTreeViewItem(){
const treeViewProvider = new TreeViewProvider();
window.registerTreeDataProvider('lmp_visualization.panel',treeViewProvider);
}

}


export function readLmpConfig() {
let data:any;
if (fs.existsSync(default_tool_config_file)) //判断是否存在此文件
{
try {
//读取文件内容,并转化为Json对象

data = JSON.parse(fs.readFileSync(default_tool_config_file, "utf8"));
// console.log(jsonData);
//获取Json里key为data的数据
//const data = userBugsJson['data'];
}
catch (error){
console.error('Error parsing JSON:', error);
}
}
else {
console.error("no config file");
let config_search_info =" json配置文件不存在,请检查!"
vscode.window.showErrorMessage(config_search_info);
}
return data;
}

// fzy end
// ---------------------------------------------------------------------------------

Expand Down Expand Up @@ -390,4 +470,4 @@ export class TreeViewProvider implements TreeDataProvider<TreeItem> {
}
}
*/
*/
Loading

0 comments on commit dea1666

Please sign in to comment.