micro/internal/util/profile.go

28 lines
641 B
Go
Raw Normal View History

2018-08-27 19:53:10 +00:00
package util
2018-08-26 03:06:44 +00:00
import (
"fmt"
2018-08-27 19:53:10 +00:00
"log"
2018-08-26 03:06:44 +00:00
"runtime"
2018-08-27 19:53:10 +00:00
"time"
2018-08-26 03:06:44 +00:00
humanize "github.com/dustin/go-humanize"
)
2018-12-31 19:46:04 +00:00
// GetMemStats returns a string describing the memory usage and gc time used so far
2018-08-26 03:06:44 +00: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 19:53:10 +00:00
2019-12-28 17:04:43 +00:00
func Tic(s string) time.Time {
2018-08-27 19:53:10 +00:00
log.Println("START:", s)
2019-12-28 17:04:43 +00:00
return time.Now()
2018-08-27 19:53:10 +00:00
}
2019-12-28 17:04:43 +00:00
func Toc(start time.Time) {
2018-08-27 19:53:10 +00:00
end := time.Now()
log.Println("END: ElapsedTime in seconds:", end.Sub(start))
}