代码拉取完成,页面将自动刷新
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()))
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。