vdbench测试过程可视化

背景

之前做过一个版本的vdbench的可视化,当时也是用python写的,但是需要引用bootstrap,整个页面也要做一些控制,配置起来就比较麻烦了
现在采用新的方法,安装一些软件之后,一个脚本就可以把测试数据进行可视化,并且测试过程都可以看到数据的波动情况

软件

采用了dash和plotly

1
2
3
pip3 install dash  -i https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install pandas -i https://pypi.tuna.tsinghua.edu.cn/simple

脚本如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
[root@lab102 plotly]# cat vdisplay.py
#! /usr/bin/python3
# -*- coding: UTF-8 -*-
import dash
from dash import dcc, html
from dash.dependencies import Input, Output
import pandas as pd
import plotly.express as px
import subprocess
import threading
import time
## 配置区域
vdbench_output_dir = "/root/vdbench/output"
vdbench_bin = "/root/vdbench/vdbench"
plotdir = "/root/plotly/output/"
##

plotdata = "%s/data.csv" %(plotdir)
# Vdbench 解析命令
parse_command = "%s parse -i %s/flatfile.html -c Interval rate resp read_rate read_resp write_rate write_resp mb_read mb_write mb/sec xfersize mkdir_rate mkdir_resp -o %s 2>/dev/null" % (vdbench_bin, vdbench_output_dir, plotdata)
copy_config = "cat %s/parmfile.html > %s/config.txt 2>/dev/null " %(vdbench_output_dir,plotdir)
copy_summary = "cat %s/summary.html > %s/summary.txt 2>/dev/null" %(vdbench_output_dir,plotdir)


try:
print("执行拷贝配置文件命令...")
subprocess.run(copy_config, shell=True, check=True)
except subprocess.CalledProcessError as e:
print(f"执行拷贝配置文件失败: {e}")


# 配置文件路径
config_file_path = "%s/config.txt" %(plotdir)
# 读取配置文件内容
try:
with open(config_file_path, "r") as file:
lines = file.readlines() # 读取所有行
config_content = ''.join(lines[4:]) # 跳过前四行,将剩余内容保存到变量中
print("配置文件内容已成功读取并保存到变量 config_content 中。")
except FileNotFoundError:
print(f"错误:文件 {config_file_path} 未找到。")
except Exception as e:
print(f"读取文件时发生错误:{e}")


# **后台线程:周期性执行 `vdbench parse` 命令**
def run_vdbench_periodically(interval=10):
while True:
try:
#print("执行 Vdbench 解析命令...")
subprocess.run(parse_command, shell=True, check=True)
except subprocess.CalledProcessError as e:
print(f"Vdbench 解析失败: {e}")
time.sleep(interval)

# 启动后台线程
threading.Thread(target=run_vdbench_periodically, daemon=True).start()

# 配置文件路径
summary_file_path = "%s/summary.txt" %(plotdir)
#summary_content=""
def run_summary_periodically(interval=10):
while True:
try:
#print("执行 summary 拷贝命令...")
subprocess.run(copy_summary, shell=True, check=True)
except subprocess.CalledProcessError as e:
print(f"summary 拷贝失败: {e}")
time.sleep(interval)

# 启动后台线程
threading.Thread(target=run_summary_periodically, daemon=True).start()


# Dash应用
app = dash.Dash(__name__)

app.layout = html.Div([
html.H3("vdbench测试性能监控看板", style={'textAlign': 'center'}),
# 控制刷新按钮
html.Button("暂停刷新", id='pause-button', n_clicks=0, style={'marginTop': 20}),

# 图表显示
dcc.Graph(id='graph-rate'),
dcc.Graph(id='graph-resp'),
dcc.Graph(id='graph-read-rate'),
dcc.Graph(id='graph-read-resp'),
dcc.Graph(id='graph-write-rate'),
dcc.Graph(id='graph-write-resp'),
dcc.Graph(id='graph-mb-read'),
dcc.Graph(id='graph-mb-write'),
dcc.Graph(id='graph-mb'),

# 自动刷新(每10秒刷新一次)
dcc.Interval(
id='interval-update',
interval=10000, # 默认每10秒刷新一次
n_intervals=0,
disabled=False # 默认刷新启用
),

# 显示配置文件内容
html.H4("vdbench测试配置文件内容:", style={'marginTop': 20}),
html.Pre(config_content, style={
'backgroundColor': '#f5f5f5',
'padding': '10px',
'border': '1px solid #ddd',
'whiteSpace': 'pre-wrap', # 保留换行和空格
'overflowX': 'auto' # 如果内容过长,添加水平滚动条
}),
html.H4("vdbench测试结果:", style={'marginTop': 20}),
html.Pre(id='summary_content', style={
'backgroundColor': '#f5f5f5',
'padding': '10px',
'border': '1px solid #ddd',
'whiteSpace': 'pre-wrap', # 保留换行和空格
'overflowX': 'auto' # 如果内容过长,添加水平滚动条
}),
# 数据来源说明
#html.Div("数据来源:lab101", style={'marginTop': 20})
])


# 定义回调函数,定期更新 summary_content
@app.callback(
Output('summary_content', 'children'),
Input('interval-update', 'n_intervals')
)
def update_summary(n_intervals):
"""
每次 interval 触发时,更新 summary_content 的内容
"""
try:
with open(summary_file_path, "r") as file:
lines = file.readlines() # 读取所有行
# 检查最后一行是否包含 "Vdbench execution completed successfully"
if lines and "Vdbench execution completed successfully" in lines[-1]:
# 读取最后四行并保存到变量中
summary_content = ''.join(lines[-4:])
summary_data=summary_content
else:
summary_data = "summary未生成"

except FileNotFoundError:
summary_data = "summary未生成"

return summary_data

# 自动刷新和手动刷新控制的回调函数
@app.callback(
[
Output('graph-rate', 'figure'),
Output('graph-resp', 'figure'),
Output('graph-read-rate', 'figure'),
Output('graph-read-resp', 'figure'),
Output('graph-write-rate', 'figure'),
Output('graph-write-resp', 'figure'),
Output('graph-mb-read', 'figure'),
Output('graph-mb-write', 'figure'),
Output('graph-mb', 'figure'),
Output('interval-update', 'disabled'), # 控制 Interval 组件的 disabled 属性
],
[Input('interval-update', 'n_intervals'),
Input('pause-button', 'n_clicks')] # 点击暂停按钮时触发
)
def update_graphs(n_intervals, n_clicks):
# 判断按钮点击次数,偶数表示继续刷新,奇数表示暂停刷新
is_paused = n_clicks % 2 == 1

try:
# 读取最新的 CSV 数据
df = pd.read_csv(plotdata, header=0, skiprows=[1])

# 创建图表时不裁剪数据,直接使用整个数据集
fig_rate = px.line(df, x='Interval', y='rate', title='I/O Rate随时间变化趋势',
labels={'rate': '请求速率(ops/s)', 'Interval': '时间间隔'}, markers=True)
fig_resp = px.line(df, x='Interval', y='resp', title='I/O response随时间变化趋势',
labels={'resp': '响应时间(ms)', 'Interval': '时间间隔'}, markers=True)
fig_read_rate = px.line(df, x='Interval', y='read_rate', title='I/O 读取请求速率随时间变化趋势',
labels={'read_rate': '读取请求速率(ops/s)', 'Interval': '时间间隔'}, markers=True)
fig_read_resp = px.line(df, x='Interval', y='read_resp', title='I/O 读取response随时间变化趋势',
labels={'read_resp': '响应时间(ms)', 'Interval': '时间间隔'}, markers=True)
fig_write_rate = px.line(df, x='Interval', y='write_rate', title='I/O 写入请求速率随时间变化趋势',
labels={'write_rate': '请求速率(ops/s)', 'Interval': '时间间隔'}, markers=True)
fig_write_resp = px.line(df, x='Interval', y='write_resp', title='I/O 写入response随时间变化趋势',
labels={'write_resp': '响应时间(ms)', 'Interval': '时间间隔'}, markers=True)
fig_mb_read = px.line(df, x='Interval', y='mb_read', title='I/O 读取带宽随时间变化趋势',
labels={'mb_read': '带宽(MB/s)', 'Interval': '时间间隔'}, markers=True)
fig_mb_write = px.line(df, x='Interval', y='mb_write', title='I/O 写入带宽随时间变化趋势',
labels={'mb_write': '带宽(MB/s)', 'Interval': '时间间隔'}, markers=True)
fig_mb = px.line(df, x='Interval', y='mb/sec', title='I/O 总带宽随时间变化趋势',
labels={'mb/sec': '带宽(MB/s)', 'Interval': '时间间隔'}, markers=True)

# 获取最后 60 个数据的 x 范围
x_range = df['Interval'].iloc[-60:].values

# 统一调整图表样式
for fig in [fig_rate, fig_resp, fig_read_rate, fig_read_resp, fig_write_rate, fig_write_resp, fig_mb_read, fig_mb_write, fig_mb]:
fig.update_yaxes(range=[0, None])
fig.update_layout(
plot_bgcolor='#f5f5f5',
hovermode='x unified',
xaxis=dict(
tickmode='linear',
dtick=1,
type='category', # 离散类别类型
rangeslider=dict(visible=True), # 启用滑动条
range=[x_range[0], x_range[-1]] # 默认显示最近 60 个数据点
)
)
return [fig_rate, fig_resp, fig_read_rate, fig_read_resp, fig_write_rate, fig_write_resp, fig_mb_read, fig_mb_write, fig_mb, is_paused]

except Exception as e:
print(f"读取 CSV 失败: {e}")
return dash.no_update

if __name__ == '__main__':
app.run_server(debug=False, host='0.0.0.0', port=8050)

配置

1
2
3
4
5
## 配置区域
vdbench_output_dir = "/root/vdbench/output"
vdbench_bin = "/root/vdbench/vdbench"
plotdir = "/root/plotly/output/"
##

就三个配置:

  • vdbench测试输出的文件夹名称
  • vdbench的二进制的路径
  • 准备存储本次测试处理数据的地方

运行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@lab102 plotly]# python3 vdisplay.py
执行拷贝配置文件命令...
配置文件内容已成功读取并保存到变量 config_content 中。
Dash is running on http://0.0.0.0:8050/

* Serving Flask app 'vdisplay' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on all addresses.
WARNING: This is a development server. Do not use it in a production deployment.
* Running on http://192.168.19.102:8050/ (Press CTRL+C to quit)
17:31:18.680 ParseFlat completed successfully.
192.168.19.101 - - [12/Feb/2025 17:31:20] "POST /_dash-update-component HTTP/1.1" 200 -

运行效果


后续如果有优化会记录

总结

这个方便进行一些测试过程的查看,特别是需要进行存储的调试的时候,能够在大量的数据里面找到一些过高或者过低的点


vdbench测试过程可视化
https://zphj1987.com/2025/02/12/vdbench测试过程可视化/
作者
zphj1987
发布于
2025年2月12日
许可协议