1 Star 0 Fork 0

CaptialSTeam/ubdframe

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
costprint.go 1.05 KB
一键复制 编辑 原始数据 按行查看 历史
Souki 提交于 2024-12-17 08:59 +08:00 . !1初始化
package performance
import (
"fmt"
v1log "gitee.com/captials-team/ubdframe/src/pkg/logs"
"time"
)
// CostPoint 耗时点位信息
type CostPoint struct {
name string
t time.Time
}
func NewCostPoint(name string, ts ...time.Time) *CostPoint {
t := time.Now()
if len(ts) > 0 {
t = ts[0]
}
return &CostPoint{
name, t,
}
}
// BatchPointCostPrinter 批量点位耗时打印
type BatchPointCostPrinter struct {
v1log.InvokeLog
arr []*CostPoint
}
func NewBatchPointCostPrinter() *BatchPointCostPrinter {
return &BatchPointCostPrinter{
arr: []*CostPoint{NewCostPoint("start")},
}
}
func (printer *BatchPointCostPrinter) Print(id string, ts ...*CostPoint) {
if id == "" {
id = fmt.Sprint(time.Now().UnixNano())
}
if len(ts) == 0 {
ts = printer.arr
}
for i, p := range ts {
cost := time.Duration(0)
if i > 0 {
cost = ts[i].t.Sub(ts[i-1].t)
}
printer.Info("%s point-%s cost %s, %s", id, p.name, cost, p.t)
}
}
func (printer *BatchPointCostPrinter) AddPoint(name string) {
printer.arr = append(printer.arr, NewCostPoint(name, time.Now()))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/captials-team/ubdframe.git
git@gitee.com:captials-team/ubdframe.git
captials-team
ubdframe
ubdframe
v1.0.4

搜索帮助