Skip to content

Commit

Permalink
v0.0.5 - 修复sysbench测试CPU的信息提取错误
Browse files Browse the repository at this point in the history
  • Loading branch information
spiritLHLS committed Jun 30, 2024
1 parent bf5bc91 commit c2e9d1b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: |
git config --global user.name 'github-actions'
git config --global user.email 'github-actions@github.com'
TAG="v0.0.4-$(date +'%Y%m%d%H%M%S')"
TAG="v0.0.5-$(date +'%Y%m%d%H%M%S')"
git tag $TAG
git push origin $TAG
env:
Expand Down
65 changes: 55 additions & 10 deletions cpu/cputest.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"runtime"
"strconv"
"strings"
"time"

Expand All @@ -31,7 +32,8 @@ func runSysBenchCommand(numThreads, maxTime, version string) (string, error) {
}

func SysBenchTest(language, testThread string) string {
var result, singleScore, multiScore string
var result, singleScore, multiScore, totalTime, totalEvents string
var temp []string
comCheck := exec.Command("sysbench", "--version")
output, err := comCheck.CombinedOutput()
if err == nil {
Expand All @@ -41,10 +43,32 @@ func SysBenchTest(language, testThread string) string {
if err == nil {
tempList := strings.Split(singleResult, "\n")
for _, line := range tempList {
if strings.Contains(line, "events per second:") || strings.Contains(line, "total number of events:") {
temp1 := strings.Split(line, ":")
if len(temp1) == 2 {
singleScore = temp1[1]
if strings.Contains(line, "events per second:") {
temp = strings.Split(line, ":")
if len(temp) == 2 {
singleScore = temp[1]
break
}
} else if singleScore == "" && totalTime == "" && strings.Contains(line, "total time:") {
temp = strings.Split(line, ":")
if len(temp) == 2 {
totalTime = strings.ReplaceAll(temp[1], "s", "")
}
} else if singleScore == "" && totalEvents == "" && strings.Contains(line, "total number of events:") {
temp = strings.Split(line, ":")
if len(temp) == 2 {
totalEvents = temp[1]
}
}
}
if singleScore == "" && totalTime != "" && totalEvents != "" {
totalEventsFloat, err1 := strconv.ParseFloat(totalEvents, 64)
if err1 == nil {
totalTimeFloat, err2 := strconv.ParseFloat(totalTime, 64)
if err2 == nil {
singleScoreFloat := totalEventsFloat / totalTimeFloat
singleScore = strconv.FormatFloat(singleScoreFloat, 'f', 2, 64)
totalTime, totalEvents = "", ""
}
}
}
Expand All @@ -60,10 +84,10 @@ func SysBenchTest(language, testThread string) string {
if err == nil {
tempList := strings.Split(singleResult, "\n")
for _, line := range tempList {
if strings.Contains(line, "events per second:") || strings.Contains(line, "total number of events:") {
temp1 := strings.Split(line, ":")
if len(temp1) == 2 {
singleScore = temp1[1]
if strings.Contains(line, "events per second:") {
temp = strings.Split(line, ":")
if len(temp) == 2 {
singleScore = temp[1]
}
}
}
Expand All @@ -78,11 +102,32 @@ func SysBenchTest(language, testThread string) string {
if err == nil {
tempList := strings.Split(multiResult, "\n")
for _, line := range tempList {
if strings.Contains(line, "events per second:") || strings.Contains(line, "total number of events:") {
if strings.Contains(line, "events per second:") {
temp1 := strings.Split(line, ":")
if len(temp1) == 2 {
multiScore = temp1[1]
}
} else if multiScore == "" && totalTime == "" && strings.Contains(line, "total time:") {
temp = strings.Split(line, ":")
if len(temp) == 2 {
totalTime = strings.ReplaceAll(temp[1], "s", "")
}
} else if multiScore == "" && totalEvents == "" && strings.Contains(line, "total number of events:") {
temp = strings.Split(line, ":")
if len(temp) == 2 {
totalEvents = temp[1]
}
}
}
if multiScore == "" && totalTime != "" && totalEvents != "" {
totalEventsFloat, err1 := strconv.ParseFloat(totalEvents, 64)
if err1 == nil {
totalTimeFloat, err2 := strconv.ParseFloat(totalTime, 64)
if err2 == nil {
multiScoreFloat := totalEventsFloat / totalTimeFloat
multiScore = strconv.FormatFloat(multiScoreFloat, 'f', 2, 64)
totalTime, totalEvents = "", ""
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cpu/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package cpu

const CpuTestVersion = "v0.0.4"
const CpuTestVersion = "v0.0.5"

0 comments on commit c2e9d1b

Please sign in to comment.