Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
spiritLHLS committed May 12, 2024
1 parent 9eb4f55 commit 3cb0d1b
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func main() {
// res := disktest.WinsatTest("zh", false)
// res := disktest.DDTest("en", true)
res := disktest.FioTest("zh", true)
res := disktest.FioTest("zh", false)
fmt.Println(res)
// fio test
// https://github.com/devlights/diskio
Expand Down
71 changes: 65 additions & 6 deletions disktest/disktest.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func FioTest(language string, enableMultiCheck bool) string {
// 生成对应文件
// https://github.com/masonr/yet-another-bench-script/blob/0ad4c4e85694dbcf0958d8045c2399dbd0f9298c/yabs.sh#L435
// fio --name=setup --ioengine=libaio --rw=read --bs=64k --iodepth=64 --numjobs=2 --size=512MB --runtime=1 --gtod_reduce=1 --filename="/tmp/test.fio" --direct=1 --minimal
cmd1 := exec.Command("fio", "--name=setup", "--ioengine=libaio", "--rw=read", "--bs=64k", "--iodepth=64", "--numjobs=2", "--size="+fioSize, "--runtime=1", "--gtod_reduce=1",
cmd1 := exec.Command("sudo", "fio", "--name=setup", "--ioengine=libaio", "--rw=read", "--bs=64k", "--iodepth=64", "--numjobs=2", "--size="+fioSize, "--runtime=1", "--gtod_reduce=1",
"--filename=\""+path+"/test.fio\"", "--direct=1", "--minimal")
defer os.Remove(path + "/test.fio")
stderr1, err := cmd1.StderrPipe()
Expand Down Expand Up @@ -258,14 +258,73 @@ func FioTest(language string, enableMultiCheck bool) string {
}
}
}
}
}
}
}
} else {
var buildPath string
// 生成对应文件
cmd1 := exec.Command("sudo", "fio", "--name=setup", "--ioengine=libaio", "--rw=read", "--bs=64k", "--iodepth=64", "--numjobs=2", "--size="+fioSize, "--runtime=1", "--gtod_reduce=1",
"--filename=\"/root/test.fio\"", "--direct=1", "--minimal")
defer os.Remove("/root/test.fio")
stderr, err := cmd1.StderrPipe()
if err == nil {
if err := cmd1.Start(); err == nil {
outputBytes, err := io.ReadAll(stderr)
if err == nil {
tempText := string(outputBytes)
if strings.Contains(tempText, "failed") || strings.Contains(tempText, "Permission denied") {
cmd1 := exec.Command("sudo", "fio", "--name=setup", "--ioengine=libaio", "--rw=read", "--bs=64k", "--iodepth=64", "--numjobs=2", "--size="+fioSize, "--runtime=1", "--gtod_reduce=1",
"--filename=\"/tmp/test.fio\"", "--direct=1", "--minimal")
defer os.Remove("/tmp/test.fio")
_, err = cmd1.StderrPipe()
if err == nil {
if err := cmd1.Start(); err == nil {
buildPath = "/tmp"
}
}
} else {
return ""
buildPath = "/root"
}
}
}
}
if buildPath != "" {
// 测试
blockSizes := []string{"4k", "64k", "512k", "1m"}
for _, BS := range blockSizes {
// timeout 35 fio --name=rand_rw_4k --ioengine=libaio --rw=randrw --rwmixread=50 --bs=4k --iodepth=64 --numjobs=2 --size=512MB --runtime=30 --gtod_reduce=1 --direct=1 --filename="/tmp/test.fio" --group_reporting --minimal
cmd2 := exec.Command("timeout", "35", "sudo", "fio", "--name=rand_rw_"+BS, "--ioengine=libaio", "--rw=randrw", "--rwmixread=50", "--bs="+BS, "--iodepth=64", "--numjobs=2", "--size="+fioSize, "--runtime=30", "--gtod_reduce=1", "--direct=1", "--filename=\""+buildPath+"/test.fio\"", "--group_reporting", "--minimal")
output, err := cmd2.Output()
if err == nil {
tempText := string(output)
tempList := strings.Split(tempText, "\n")
for _, l := range tempList {
if strings.Contains(l, "rand_rw_"+BS) {
tpList := strings.Split(l, ";")
// IOPS
DISK_IOPS_R := tpList[8]
DISK_IOPS_W := tpList[49]
DISK_IOPS_R_INT, _ := strconv.Atoi(DISK_IOPS_R)
DISK_IOPS_W_INT, _ := strconv.Atoi(DISK_IOPS_W)
DISK_IOPS := DISK_IOPS_R_INT + DISK_IOPS_W_INT
// Speed
DISK_TEST_R := tpList[7]
DISK_TEST_W := tpList[48]
DISK_TEST_R_INT, _ := strconv.ParseFloat(DISK_TEST_R, 64)
DISK_TEST_W_INT, _ := strconv.ParseFloat(DISK_TEST_W, 64)
DISK_TEST := DISK_TEST_R_INT + DISK_TEST_W_INT
// 拼接输出文本
result += fmt.Sprintf("%-10s", buildPath) + " "
result += fmt.Sprintf("%-5s", BS) + " "
result += fmt.Sprintf("%-20s", formatSpeed(DISK_TEST_R, "string")+"("+formatIOPS(DISK_IOPS_R, "string")+")") + " "
result += fmt.Sprintf("%-20s", formatSpeed(DISK_TEST_W, "string")+"("+formatIOPS(DISK_IOPS_W, "string")+")") + " "
result += fmt.Sprintf("%-20s", formatSpeed(DISK_TEST, "float64")+"("+formatIOPS(DISK_IOPS, "int")+")") + " "
result += "\n"
}
}
} else {
return ""
}
} else {
return ""
}
}
}
Expand Down

0 comments on commit 3cb0d1b

Please sign in to comment.