2021-11-01 19:58:55 +01:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------- *
|
|
|
|
* IMPORTS
|
|
|
|
* ---------------------------------------------------------------- */
|
|
|
|
|
|
|
|
import (
|
2021-11-02 13:05:34 +01:00
|
|
|
"fmt"
|
2021-11-01 19:58:55 +01:00
|
|
|
"time"
|
|
|
|
|
2021-11-02 13:05:34 +01:00
|
|
|
"ads/internal/core/utils"
|
2021-11-01 19:58:55 +01:00
|
|
|
"ads/internal/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------- *
|
|
|
|
* GLOBAL VARIABLES/CONSTANTS
|
|
|
|
* ---------------------------------------------------------------- */
|
|
|
|
|
|
|
|
var _ctr_time = types.NewCounter()
|
|
|
|
var _ctr_space = types.NewCounter()
|
|
|
|
var _tmr = types.NewTimer()
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------- *
|
|
|
|
* METHODS
|
|
|
|
* ---------------------------------------------------------------- */
|
|
|
|
|
2021-11-02 13:05:34 +01:00
|
|
|
func ResetMetrics() {
|
2021-11-01 19:58:55 +01:00
|
|
|
_ctr_time.Reset()
|
|
|
|
_ctr_space.Reset()
|
2021-11-02 13:05:34 +01:00
|
|
|
_tmr.Reset()
|
|
|
|
}
|
|
|
|
|
|
|
|
func StartMetrics() {
|
|
|
|
_tmr.Start()
|
|
|
|
}
|
|
|
|
|
|
|
|
func StopMetrics() {
|
|
|
|
_tmr.Stop()
|
2021-11-01 19:58:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return _tmr.ElapsedTime()
|
|
|
|
}
|
2021-11-02 13:05:34 +01:00
|
|
|
|
|
|
|
func GetTimeElapsedLongFormat() string {
|
|
|
|
t := _tmr.ElapsedTime()
|
|
|
|
h := utils.Floor(t.Hours())
|
|
|
|
m := utils.Floor(t.Minutes()) - h*60
|
|
|
|
s := t.Seconds() - float64(m*60)
|
|
|
|
h_string := fmt.Sprintf("%v", h)
|
|
|
|
for len(h_string) < 2 {
|
|
|
|
h_string = "0" + h_string
|
|
|
|
}
|
|
|
|
m_string := fmt.Sprintf("%v", m)
|
|
|
|
for len(m_string) < 2 {
|
|
|
|
m_string = "0" + m_string
|
|
|
|
}
|
|
|
|
s_string := fmt.Sprintf("%f", s)
|
|
|
|
return fmt.Sprintf("%[1]s:%[2]s:%[3]s", h_string, m_string, s_string)
|
|
|
|
}
|