micro/internal/util/profile.go

28 lines
641 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
2019-12-28 20:04:43 +03:00
func Tic(s string) time.Time {
2018-08-27 22:53:10 +03:00
log.Println("START:", s)
2019-12-28 20:04:43 +03:00
return time.Now()
2018-08-27 22:53:10 +03:00
}
2019-12-28 20:04:43 +03:00
func Toc(start time.Time) {
2018-08-27 22:53:10 +03:00
end := time.Now()
log.Println("END: ElapsedTime in seconds:", end.Sub(start))
}