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