Skip to content

Commit

Permalink
合并CPU、内存、文件系统子系统监测程序; 整理目录结构;wakeup程序添加新的指标 (linuxkerneltravel#364)
Browse files Browse the repository at this point in the history
* 合并CPU、内存、文件系统子系统监测程序; 整理目录结构;wakeup程序添加新的指标

* 更新CI和go程序,以通过CI

* 小修改,测试CI

* 修改CI

* 补充Supermarket文档

Co-authored-by: zrp <[email protected]>
Co-authored-by: helight <[email protected]>
  • Loading branch information
3 people authored Sep 26, 2022
1 parent 4152c8c commit c10e2d5
Show file tree
Hide file tree
Showing 141 changed files with 7,471 additions and 16,558 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/system_cpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ jobs:

- name: Run BCC_sar
run: |
cd eBPF_Supermarket/CPU_Subsystem/BCC_sar/src
cd eBPF_Supermarket/CPU_Subsystem/BCC_sar/src/sar
sudo python3 sar.py -h
sudo python3 sar.py -t time -c 3
sudo python3 sar.py -t percent -c 5
sudo python3 sar.py -t percent -c 3 -i 2
- name: Run BCC_sar(Per Process)
run: |
cd eBPF_Supermarket/CPU_Subsystem/BCC_sar/src
cd eBPF_Supermarket/CPU_Subsystem/BCC_sar/src/sar
# find the process which runs for the longest time
TARGET=$(ps -eo pid --sort -time | sed -n "2p" | awk '{print $1}')
echo target=$TARGET
Expand Down
3 changes: 2 additions & 1 deletion eBPF_Supermarket/CPU_Subsystem/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ temp_data/
*/test/process
*/test/pthread

*/temp
*/temp
**/event.txt
108 changes: 108 additions & 0 deletions eBPF_Supermarket/CPU_Subsystem/BCC_sar/src/area-time-axis.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<!--
此示例下载自 https://echarts.apache.org/examples/zh/editor.html?c=area-time-axis
-->
<!DOCTYPE html>
<html lang="zh-CN" style="height: 100%">
<head>
<meta charset="utf-8">
</head>
<body style="height: 100%; margin: 0">
<div id="container" style="height: 100%"></div>


<script type="text/javascript" src="https://fastly.jsdelivr.net/npm/[email protected]/dist/echarts.min.js"></script>
<!-- Uncomment this line if you want to dataTool extension
<script type="text/javascript" src="https://fastly.jsdelivr.net/npm/[email protected]/dist/extension/dataTool.min.js"></script>
-->
<!-- Uncomment this line if you want to use gl extension
<script type="text/javascript" src="https://fastly.jsdelivr.net/npm/echarts-gl@2/dist/echarts-gl.min.js"></script>
-->
<!-- Uncomment this line if you want to echarts-stat extension
<script type="text/javascript" src="https://fastly.jsdelivr.net/npm/echarts-stat@latest/dist/ecStat.min.js"></script>
-->
<!-- Uncomment this line if you want to use map
<script type="text/javascript" src="https://fastly.jsdelivr.net/npm/[email protected]/map/js/china.js"></script>
<script type="text/javascript" src="https://fastly.jsdelivr.net/npm/[email protected]/map/js/world.js"></script>
-->
<!-- Uncomment these two lines if you want to use bmap extension
<script type="text/javascript" src="https://api.map.baidu.com/api?v=3.0&ak=YOUR_API_KEY"></script>
<script type="text/javascript" src="https://fastly.jsdelivr.net/npm/[email protected]/dist/extension/bmap.min.js"></script>
-->

<script type="text/javascript">
var dom = document.getElementById('container');
var myChart = echarts.init(dom, null, {
renderer: 'canvas',
useDirtyRect: false
});
var app = {};

var option;

let base = +new Date(1988, 9, 3);
let oneDay = 24 * 3600 * 1000;
let data = [[base, Math.random() * 300]];
for (let i = 1; i < 20000; i++) {
let now = new Date((base += oneDay));
data.push([+now, Math.round((Math.random() - 0.5) * 20 + data[i - 1][1])]);
}

option = {
tooltip: {
trigger: 'axis',
position: function (pt) {
return [pt[0], '10%'];
}
},
title: {
left: 'center',
text: 'Large Ara Chart'
},
toolbox: {
feature: {
dataZoom: {
yAxisIndex: 'none'
},
restore: {},
saveAsImage: {}
}
},
xAxis: {
type: 'value',
boundaryGap: false
},
yAxis: {
type: 'value',
boundaryGap: [0, '100%']
},
dataZoom: [
{
type: 'inside',
start: 0,
end: 20
},
{
start: 0,
end: 20
}
],
series: [
{
name: 'Fake Data',
type: 'line',
smooth: true,
symbol: 'none',
areaStyle: {},
data: data
}
]
};

if (option && typeof option === 'object') {
myChart.setOption(option);
}

window.addEventListener('resize', myChart.resize);
</script>
</body>
</html>
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def attach_probe():

def main():
global config
CONFIGFILE = "../config/config.ini"
CONFIGFILE = "../../config/config.ini"
config = configparser.ConfigParser()
config.read(CONFIGFILE)

Expand Down Expand Up @@ -251,5 +251,6 @@ def exit_app(signum, frame):
# 打印BPF程序中的输出
# bpf.trace_print()


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <uapi/linux/ptrace.h>
#include <linux/sched.h>
#define TARGET_PID 65005
#define TARGET_PID 2069

typedef int pid_t;
BPF_ARRAY(TotalMap, u64, 9);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def exit_app(signum, frame):

signal.signal(signal.SIGINT, exit_app)

CONFIGFILE = "../config/config.ini"
CONFIGFILE = "../../config/config.ini"
config = configparser.ConfigParser()
config.read(CONFIGFILE)

Expand Down
75 changes: 75 additions & 0 deletions eBPF_Supermarket/CPU_Subsystem/BCC_sar/src/wakeup/bpfutil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import re, os

# print a cint_list(list of ctypes variable)
def printList(cint_list):
for i in cint_list:
print(i.value, end=",")
print()

# get the number of the count of cpus
# @return int
def get_num_cpus() -> int:
num_cpus = 1
with open("/proc/cpuinfo", "r") as f:
while True:
s = f.readline()
if not s: break
if re.match("^processor\t: [0-9]+\n$", s):
num_cpus = int(s[:-1].split(" ")[-1]) + 1
return num_cpus

# find ksymbol in /proc/kallsyms
# if find, return a positive number, else negative.
# @return int
def find_ksym(ksym: str) -> int:
addr = -1
with open("/proc/kallsyms", 'r') as f:
line = f.readline()
while line:
if line[:-1].endswith(" " + ksym):
addr = line.split(" ")[0]
break
line = f.readline()
return addr

class SecondRecord:
def __init__(self, initval=0) -> None:
self.val = initval

# update and read delta
def UpRd(self, val):
dta = val - self.val
self.val = val
return dta

def get_pid_by_name(name: str) -> int:
f = os.popen("ps -A | grep ' " + name + "$" + "'")
lines = f.readlines()
if len(lines) != 1:
return -1
else:
f_str = lines[0]

pid = re.match(" *([0-9]+) ", f_str).group(0)
pid = int(pid)
return pid

# GRAY=30
# RED=31
# GREEN=32
# YELLOW=33
# BLUE=34
# MAGENTA=35
# CYAN=36
# WHITE=37
# CRIMSON=38
def colorize(num, string, bold=False, highlight = False):
assert isinstance(num, int)
attr = []
if highlight:
num += 10
attr.append(str(num))
if bold: attr.append('1')
return '\x1b[%sm%s\x1b[0m' % (';'.join(attr), string)

# 原文链接:https://blog.csdn.net/hxxjxw/article/details/122432886
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
# 按照时间从大到小排序打印进程pid和comm,只打印前10条
ps -eo pid,comm,time --sort=-time | head -n 10
9 changes: 9 additions & 0 deletions eBPF_Supermarket/CPU_Subsystem/BCC_sar/src/wakeup/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import time
import os

if __name__ == "__main__":
print(os.getpid())
while True:
time.sleep(0.3)
for i in range(1000000):
pass
Loading

0 comments on commit c10e2d5

Please sign in to comment.