micro/internal/util/profile.go

30 lines
638 B
Go
Raw Normal View History

2018-08-27 22:53:10 +03:00
package util
2018-08-26 06:06:44 +03:00
import (
"fmt"
2018-08-27 22:53:10 +03:00
"log"
2018-08-26 06:06:44 +03:00
"runtime"
2018-08-27 22:53:10 +03:00
"time"
2018-08-26 06:06:44 +03:00
humanize "github.com/dustin/go-humanize"
)
2018-12-31 22:46:04 +03:00
// GetMemStats returns a string describing the memory usage and gc time used so far
2018-08-26 06:06:44 +03:00
func GetMemStats() string {
var memstats runtime.MemStats
runtime.ReadMemStats(&memstats)
return fmt.Sprintf("Alloc: %s, Sys: %s, GC: %d, PauseTotalNs: %dns", humanize.Bytes(memstats.Alloc), humanize.Bytes(memstats.Sys), memstats.NumGC, memstats.PauseTotalNs)
}
2018-08-27 22:53:10 +03:00
var start time.Time
2019-01-01 06:07:01 +03:00
func Tic(s string) {
2018-08-27 22:53:10 +03:00
log.Println("START:", s)
start = time.Now()
}
2019-01-01 06:07:01 +03:00
func Toc() {
2018-08-27 22:53:10 +03:00
end := time.Now()
log.Println("END: ElapsedTime in seconds:", end.Sub(start))
}