51 lines
1.0 KiB
Go
51 lines
1.0 KiB
Go
|
package metrics
|
||
|
|
||
|
/* ---------------------------------------------------------------- *
|
||
|
* IMPORTS
|
||
|
* ---------------------------------------------------------------- */
|
||
|
|
||
|
import (
|
||
|
"time"
|
||
|
|
||
|
"ads/internal/types"
|
||
|
)
|
||
|
|
||
|
/* ---------------------------------------------------------------- *
|
||
|
* GLOBAL VARIABLES/CONSTANTS
|
||
|
* ---------------------------------------------------------------- */
|
||
|
|
||
|
var _ctr_time = types.NewCounter()
|
||
|
var _ctr_space = types.NewCounter()
|
||
|
var _tmr = types.NewTimer()
|
||
|
|
||
|
/* ---------------------------------------------------------------- *
|
||
|
* METHODS
|
||
|
* ---------------------------------------------------------------- */
|
||
|
|
||
|
func RestartMetrics() {
|
||
|
_tmr.Reset()
|
||
|
_ctr_time.Reset()
|
||
|
_ctr_space.Reset()
|
||
|
}
|
||
|
|
||
|
func AddTimeCost(options ...int) {
|
||
|
_ctr_time.Add(options...)
|
||
|
}
|
||
|
|
||
|
func AddSpaceCost(options ...int) {
|
||
|
_ctr_space.Add(options...)
|
||
|
}
|
||
|
|
||
|
func GetTimeCost() int {
|
||
|
return _ctr_time.Size()
|
||
|
}
|
||
|
|
||
|
func GetSpaceCost() int {
|
||
|
return _ctr_space.Size()
|
||
|
}
|
||
|
|
||
|
func GetTimeElapsed() time.Duration {
|
||
|
_tmr.Stop()
|
||
|
return _tmr.ElapsedTime()
|
||
|
}
|