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

     1  // Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
     2  
     3  package dbs
     4  
     5  import "time"
     6  
     7  type QueryLabel struct {
     8  	manager *QueryStatManager
     9  	query   string
    10  	before  time.Time
    11  }
    12  
    13  func NewQueryLabel(manager *QueryStatManager, query string) *QueryLabel {
    14  	return &QueryLabel{
    15  		manager: manager,
    16  		query:   query,
    17  		before:  time.Now(),
    18  	}
    19  }
    20  
    21  func (this *QueryLabel) End() {
    22  	var cost = time.Since(this.before).Seconds()
    23  	this.manager.AddCost(this.query, cost)
    24  }