修改统计计算
This commit is contained in:
parent
09f8cd1926
commit
bace8219ae
28
lib/ai.go
28
lib/ai.go
@ -94,12 +94,14 @@ func (m *myAI) Start() bool {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
start := time.Now()
|
||||||
for {
|
for {
|
||||||
total := atomic.LoadUint32(&m.useCountTotal)
|
total := atomic.LoadUint32(&m.useCountTotal)
|
||||||
if total == m.config.Global.UserCountTotal {
|
if total == m.config.Global.UserCountTotal {
|
||||||
|
elipse := time.Since(start)
|
||||||
logrus.Info("开始生成测试报告")
|
logrus.Info("开始生成测试报告")
|
||||||
m.MergeResult()
|
m.MergeResult()
|
||||||
m.genReport()
|
m.genReport(elipse)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -132,11 +134,19 @@ func (m *myAI) MergeResult() {
|
|||||||
//判断协议是否相同
|
//判断协议是否相同
|
||||||
if k == l {
|
if k == l {
|
||||||
statis := &Statistics{}
|
statis := &Statistics{}
|
||||||
statis.ElapseTotal = time.Duration(int64(a.ElapseTotal+b.ElapseTotal) / int64(2))
|
statis.ElapseTotal = time.Duration(int64(a.ElapseTotal + b.ElapseTotal))
|
||||||
statis.AvgElapse = time.Duration(int64(a.AvgElapse+b.AvgElapse) / int64(2))
|
statis.AvgElapse = time.Duration(int64(a.AvgElapse+b.AvgElapse) / int64(2))
|
||||||
statis.CallCount = (a.CallCount + b.CallCount)
|
statis.CallCount = (a.CallCount + b.CallCount)
|
||||||
statis.MaxElapse = time.Duration(int64(a.MaxElapse+b.MaxElapse) / int64(2))
|
max := a.MaxElapse
|
||||||
statis.MinElapse = time.Duration(int64(a.MinElapse+b.MinElapse) / int64(2))
|
if max < b.MaxElapse {
|
||||||
|
max = b.MaxElapse
|
||||||
|
}
|
||||||
|
statis.MaxElapse = max
|
||||||
|
min := a.MinElapse
|
||||||
|
if min > b.MinElapse {
|
||||||
|
min = b.MinElapse
|
||||||
|
}
|
||||||
|
statis.MinElapse = min
|
||||||
statis.Route = a.Route
|
statis.Route = a.Route
|
||||||
statis.SceneName = a.SceneName
|
statis.SceneName = a.SceneName
|
||||||
if n[i][k] == nil {
|
if n[i][k] == nil {
|
||||||
@ -170,11 +180,7 @@ func (m *myAI) MergeResult() {
|
|||||||
m.ReportMap = n
|
m.ReportMap = n
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *myAI) genReport() {
|
func (m *myAI) genReport(elipse time.Duration) {
|
||||||
var buf bytes.Buffer
|
|
||||||
buf.WriteString("测试报告\n")
|
|
||||||
buf.WriteString(fmt.Sprintf("用户总数:%d 单次投放人数:%d 投放间隔时间:%ds\n",
|
|
||||||
m.config.Global.UserCountTotal, m.config.Global.UserCount, m.config.Global.IntervalS))
|
|
||||||
var msgs []string
|
var msgs []string
|
||||||
var i []int
|
var i []int
|
||||||
for key, _ := range m.ReportMap {
|
for key, _ := range m.ReportMap {
|
||||||
@ -188,6 +194,10 @@ func (m *myAI) genReport() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
record := strings.Join(msgs, "\n")
|
record := strings.Join(msgs, "\n")
|
||||||
|
var buf bytes.Buffer
|
||||||
|
buf.WriteString("测试报告\n")
|
||||||
|
buf.WriteString(fmt.Sprintf("用户总数:%d 单次投放人数:%d 投放间隔时间:%ds 共计时间:%s\n",
|
||||||
|
m.config.Global.UserCountTotal, m.config.Global.UserCount, m.config.Global.IntervalS, elipse.String()))
|
||||||
buf.WriteString(record)
|
buf.WriteString(record)
|
||||||
buf.WriteString("\n------------------------------------------------------------------------------------------------------\n")
|
buf.WriteString("\n------------------------------------------------------------------------------------------------------\n")
|
||||||
// logrus.WithField("res", buf.String()).Debug("报告内容")
|
// logrus.WithField("res", buf.String()).Debug("报告内容")
|
||||||
|
@ -208,7 +208,6 @@ func (m *Robot) syncCall() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithField("err", err).Debug("所有场景执行结束")
|
logrus.WithField("err", err).Debug("所有场景执行结束")
|
||||||
m.prepareToStop()
|
m.prepareToStop()
|
||||||
// m.genReport(sceneElipseTotal)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
m.scene = scene
|
m.scene = scene
|
||||||
|
@ -61,9 +61,9 @@ func TestMerge(t *testing.T) {
|
|||||||
robot1.ReportMap[1]["user.login"] = &lib.Statistics{
|
robot1.ReportMap[1]["user.login"] = &lib.Statistics{
|
||||||
ElapseTotal: 5,
|
ElapseTotal: 5,
|
||||||
CallCount: 2,
|
CallCount: 2,
|
||||||
AvgElapse: 1,
|
AvgElapse: 2,
|
||||||
MaxElapse: 4,
|
MaxElapse: 4,
|
||||||
MinElapse: 1,
|
MinElapse: 2,
|
||||||
Route: "user.login",
|
Route: "user.login",
|
||||||
SceneName: "登录",
|
SceneName: "登录",
|
||||||
}
|
}
|
||||||
@ -75,9 +75,9 @@ func TestMerge(t *testing.T) {
|
|||||||
robot2.ReportMap[1]["user.login"] = &lib.Statistics{
|
robot2.ReportMap[1]["user.login"] = &lib.Statistics{
|
||||||
ElapseTotal: 7,
|
ElapseTotal: 7,
|
||||||
CallCount: 1,
|
CallCount: 1,
|
||||||
AvgElapse: 1,
|
AvgElapse: 3,
|
||||||
MaxElapse: 5,
|
MaxElapse: 5,
|
||||||
MinElapse: 2,
|
MinElapse: 4,
|
||||||
Route: "user.login",
|
Route: "user.login",
|
||||||
SceneName: "登录",
|
SceneName: "登录",
|
||||||
}
|
}
|
||||||
@ -89,15 +89,30 @@ func TestMerge(t *testing.T) {
|
|||||||
robot3.ReportMap[1]["user.login"] = &lib.Statistics{
|
robot3.ReportMap[1]["user.login"] = &lib.Statistics{
|
||||||
ElapseTotal: 8,
|
ElapseTotal: 8,
|
||||||
CallCount: 1,
|
CallCount: 1,
|
||||||
AvgElapse: 3,
|
AvgElapse: 2,
|
||||||
MaxElapse: 2,
|
MaxElapse: 6,
|
||||||
MinElapse: 2,
|
MinElapse: 3,
|
||||||
Route: "user.login",
|
Route: "user.login",
|
||||||
SceneName: "登录",
|
SceneName: "登录",
|
||||||
}
|
}
|
||||||
ma.AppendRobot(robot3)
|
ma.AppendRobot(robot3)
|
||||||
ma.MergeResult()
|
ma.MergeResult()
|
||||||
|
|
||||||
|
robot4 := lib.NewRobot(config)
|
||||||
|
robot4.ReportMap = make(map[int]map[string]*lib.Statistics)
|
||||||
|
robot4.ReportMap[1] = make(map[string]*lib.Statistics)
|
||||||
|
robot4.ReportMap[1]["user.login"] = &lib.Statistics{
|
||||||
|
ElapseTotal: 8,
|
||||||
|
CallCount: 1,
|
||||||
|
AvgElapse: 2,
|
||||||
|
MaxElapse: 8,
|
||||||
|
MinElapse: 2,
|
||||||
|
Route: "user.login",
|
||||||
|
SceneName: "登录",
|
||||||
|
}
|
||||||
|
ma.AppendRobot(robot4)
|
||||||
|
ma.MergeResult()
|
||||||
|
|
||||||
fmt.Println(ma.ReportMap)
|
fmt.Println(ma.ReportMap)
|
||||||
for i, v := range ma.ReportMap {
|
for i, v := range ma.ReportMap {
|
||||||
fmt.Println(i)
|
fmt.Println(i)
|
||||||
|
Loading…
Reference in New Issue
Block a user