github.com/TeaOSLab/EdgeNode@v1.3.8/internal/utils/dbs/query_stat.go (about)

     1  // Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
     2  
     3  package dbs
     4  
     5  type QueryStat struct {
     6  	Query   string
     7  	CostMin float64
     8  	CostMax float64
     9  
    10  	CostTotal float64
    11  	Calls     int64
    12  }
    13  
    14  func NewQueryStat(query string) *QueryStat {
    15  	return &QueryStat{
    16  		Query: query,
    17  	}
    18  }
    19  
    20  func (this *QueryStat) AddCost(cost float64) {
    21  	if this.CostMin == 0 || this.CostMin > cost {
    22  		this.CostMin = cost
    23  	}
    24  	if this.CostMax == 0 || this.CostMax < cost {
    25  		this.CostMax = cost
    26  	}
    27  
    28  	this.CostTotal += cost
    29  	this.Calls++
    30  }