上传代码
This commit is contained in:
parent
646244d996
commit
4f4acd6304
@ -8,6 +8,7 @@ import (
|
||||
"os"
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
/*
|
||||
@ -18,7 +19,6 @@ type statisticalComp struct {
|
||||
module *RobotModule
|
||||
succclientNum int32 //链接成功客户端数
|
||||
failclientNum int32 //链接失败客户端数
|
||||
endClientnum int32 //结束
|
||||
totalmessage int32 //总消息两
|
||||
robotdata map[string][]*RobotStatistics //机器人统计数据
|
||||
lock sync.RWMutex
|
||||
@ -32,15 +32,20 @@ func (this *statisticalComp) Init(service core.IService, module core.IModule, co
|
||||
return
|
||||
}
|
||||
|
||||
func (this *statisticalComp) Start() (err error) {
|
||||
err = this.ModuleCompBase.Start()
|
||||
go this.run()
|
||||
return
|
||||
}
|
||||
|
||||
//添加成功客户端数
|
||||
func (this *statisticalComp) AddSuccClient(robot *Robot) {
|
||||
this.succclientNum++
|
||||
|
||||
}
|
||||
|
||||
//添加失败客户端数
|
||||
func (this *statisticalComp) AddFailClient(robot *Robot, err error) {
|
||||
this.succclientNum++
|
||||
this.endClientnum++
|
||||
this.failclientNum++
|
||||
}
|
||||
|
||||
//机器人测试结束
|
||||
@ -48,11 +53,7 @@ func (this *statisticalComp) RobotFinishedTest(robot *Robot) {
|
||||
this.lock.Lock()
|
||||
this.robotdata[robot.Account()] = robot.statistics
|
||||
this.lock.Unlock()
|
||||
this.endClientnum++
|
||||
if this.endClientnum >= this.module.options.RobotTotalNum { //压测结束
|
||||
this.OutReport()
|
||||
}
|
||||
log.Debugf("完成测试:%s", robot.account)
|
||||
this.succclientNum++
|
||||
}
|
||||
|
||||
//输出报表
|
||||
@ -61,7 +62,7 @@ func (this *statisticalComp) OutReport() {
|
||||
messages map[string][]int64 = make(map[string][]int64)
|
||||
ok bool
|
||||
)
|
||||
|
||||
this.lock.Lock()
|
||||
for _, datas := range this.robotdata {
|
||||
for _, v := range datas {
|
||||
this.totalmessage++
|
||||
@ -71,8 +72,8 @@ func (this *statisticalComp) OutReport() {
|
||||
messages[v.message] = append(messages[v.message], v.time)
|
||||
}
|
||||
}
|
||||
|
||||
file, err := os.Create(this.module.options.OutFilePath)
|
||||
this.lock.Unlock()
|
||||
file, err := os.OpenFile(this.module.options.OutFilePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
@ -104,3 +105,14 @@ func (this *statisticalComp) OutReport() {
|
||||
}
|
||||
log.Debugf("机器人报表已输出!")
|
||||
}
|
||||
|
||||
func (this *statisticalComp) run() {
|
||||
timer := time.NewTicker(time.Second * 10)
|
||||
for {
|
||||
select {
|
||||
case <-timer.C:
|
||||
this.OutReport()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user