From 2b491f919762f01bee4ac6f24a56b95d12abf427 Mon Sep 17 00:00:00 2001 From: zhanghan2021 Date: Tue, 30 Jan 2024 11:35:53 +0800 Subject: [PATCH] fix result analysis --- server/controller/tune.go | 2 +- server/dao/resultanalysis.go | 15 +++++++++++++++ server/model/common.go | 2 +- server/service/resultanalysis.go | 19 +++++++++++++++---- server/service/resultservice.go | 6 +++--- server/template/enter_tune.go | 2 +- server/template/tune/compress_Except.go | 10 ++++++---- 7 files changed, 42 insertions(+), 14 deletions(-) diff --git a/server/controller/tune.go b/server/controller/tune.go index aa31a40..e690077 100644 --- a/server/controller/tune.go +++ b/server/controller/tune.go @@ -11,7 +11,7 @@ import ( func GetAtuneAll(c *gin.Context) { allData := []string{ "compress", - "compress_Except", + "compress_Except_example", "ffmpeg", "fio", "gcc_compile", diff --git a/server/dao/resultanalysis.go b/server/dao/resultanalysis.go index 7c8ceb4..c8e883a 100644 --- a/server/dao/resultanalysis.go +++ b/server/dao/resultanalysis.go @@ -11,6 +11,21 @@ func SaveResultAnalysis(ra *model.TuningResults) error { } return nil } + +func UpdateResultAnalysis(taskId int, machine_uuid string, ra *model.TuningResults) error { + var r model.TuningResults + if err := db.MySQL().Model(&r).Where("task_id = ? AND machine_uuid = ?", taskId, machine_uuid).Updates(&ra).Error; err != nil { + return err + } + return nil +} + +func IsExistResultAnalisis(taskId int, machine_uuid string) (bool, error) { + var result model.TuningResults + err := db.MySQL().Where("task_id = ? AND machine_uuid = ?", taskId, machine_uuid).Find(&result).Error + return result.ID != 0, err +} + func GetResultAnalisis(taskId, machine_uuid string) (model.TuningResults, error) { var result model.TuningResults if err := db.MySQL().Where("task_id = ? AND machine_uuid = ?", taskId, machine_uuid).Find(&result).Error; err != nil { diff --git a/server/model/common.go b/server/model/common.go index 396e985..b8897fe 100644 --- a/server/model/common.go +++ b/server/model/common.go @@ -65,7 +65,7 @@ type TuningIterResult struct { TuningStep string `json:"step"` RecommandParameters interface{} `json:"recommand_parameters"` EvaluationValue interface{} `json:"evaluation_value"` - PerformanceImprovement string `json:"performance_improvement"` + PerformanceImprovement interface{} `json:"performance_improvement"` } // TuningResult 是用于存储调优结果的结构体 diff --git a/server/service/resultanalysis.go b/server/service/resultanalysis.go index 9802bad..d6f982d 100644 --- a/server/service/resultanalysis.go +++ b/server/service/resultanalysis.go @@ -3,6 +3,7 @@ package service import ( "encoding/json" "regexp" + "strconv" "strings" "gitee.com/openeuler/PilotGo/sdk/logger" @@ -48,7 +49,11 @@ func ResultAnalysis(taskId int, machine_uuid string) error { // 本轮评估值 iterResult.EvaluationValue = extractKeyValue(m[1]) // 性能提升 - iterResult.PerformanceImprovement = m[2] + percentage, err := strconv.ParseFloat(strings.TrimRight(m[2], "%"), 64) + if err != nil { + logger.Error("无法将字符串转换为浮点数:%v", err) + } + iterResult.PerformanceImprovement = percentage iterResults = append(iterResults, iterResult) } } else if strings.Contains(line, "The final optimization result") { @@ -83,8 +88,14 @@ func ResultAnalysis(taskId int, machine_uuid string) error { FinalEvaluationValue: jsonToString(finalEvaluationValue), BaselinePerformance: jsonToString(baselinePerformance), } - if err = dao.SaveResultAnalysis(tuningResult); err != nil { - return err + if ok, err := dao.IsExistResultAnalisis(taskId, machine_uuid); ok && err == nil { + if err := dao.UpdateResultAnalysis(taskId, machine_uuid, tuningResult); err != nil { + return err + } + } else if !ok && err == nil { + if err = dao.SaveResultAnalysis(tuningResult); err != nil { + return err + } } return nil } @@ -107,7 +118,7 @@ func GetResultAnalisis(taskId, machine_uuid string) (interface{}, error) { func extractKeyValue(input string) map[string]string { result := make(map[string]string) - re := regexp.MustCompile(`(\w+)=(\w+)`) + re := regexp.MustCompile(`(\w+)=([\w.]+)`) matches := re.FindAllStringSubmatch(input, -1) for _, match := range matches { result[match[1]] = match[2] diff --git a/server/service/resultservice.go b/server/service/resultservice.go index aa2b57c..a6b5c05 100644 --- a/server/service/resultservice.go +++ b/server/service/resultservice.go @@ -22,9 +22,9 @@ const ( const ( // 命令类型 - CommandTypePrepare = "prepare" - CommandTypeTune = "tune" - CommandTypeRestore = "restore" + CommandTypePrepare = "环境准备" + CommandTypeTune = "调优" + CommandTypeRestore = "环境恢复" ) func processResult(dbtaskid int, res *common.CmdResult, commandType string) (string, error) { diff --git a/server/template/enter_tune.go b/server/template/enter_tune.go index a134dd9..cc87beb 100644 --- a/server/template/enter_tune.go +++ b/server/template/enter_tune.go @@ -4,7 +4,7 @@ import "openeuler.org/PilotGo/atune-plugin/template/tune" const ( Compress = "compress" - CompressExcept = "compress_Except" + CompressExcept = "compress_Except_example" Ffmpeg = "ffmpeg" Fio = "fio" GccCompile = "gcc_compile" diff --git a/server/template/tune/compress_Except.go b/server/template/tune/compress_Except.go index fa43f62..18ab1f5 100644 --- a/server/template/tune/compress_Except.go +++ b/server/template/tune/compress_Except.go @@ -1,14 +1,16 @@ package tune +import "openeuler.org/PilotGo/atune-plugin/plugin" + type CompressExceptApp struct{} func (ce *CompressExceptApp) Info() *TuneInfo { info := &TuneInfo{ - TuneName: "compress_Except", - WorkDirectory: "mkdir -p /tmp/tune/ && cp -r ../../templete/compress_Except_example.tar.gz /tmp/tune/ && cd /tmp/tune && tar -xzvf compress_Except_example.tar.gz", + TuneName: "compress_Except_example", + WorkDirectory: "mkdir -p /tmp/tune/ && cd /tmp/tune/ && [ -e compress_Except_example.tar.gz ] && tar -xzvf compress_Except_example.tar.gz || ( curl -OJ http://" + plugin.GlobalClient.Server() + "/api/v1/download/compress_Except_example.tar.gz && tar -xzvf compress_Except_example.tar.gz)", Prepare: "cd /tmp/tune/compress_Except_example && sh prepare.sh enwik8.zip", - Tune: "atune-adm tuning --project compress_Except_example --detail compress_Except_example_client.yaml", - Restore: "atune-adm tuning --restore --project compress_Except_example", + Tune: "cd /tmp/tune/compress_Except_example && atune-adm tuning --project compress_Except_example --detail compress_Except_example_client.yaml", + Restore: "cd /tmp/tune/compress_Except_example && atune-adm tuning --restore --project compress_Except_example", } return info -- Gitee