]> git.lizzy.rs Git - micro.git/blob - internal/util/profile.go
d15655dd1da78ccdb82c2352e185d352ee812b84
[micro.git] / internal / util / profile.go
1 package util
2
3 import (
4         "fmt"
5         "log"
6         "runtime"
7         "time"
8
9         humanize "github.com/dustin/go-humanize"
10 )
11
12 // GetMemStats returns a string describing the memory usage and gc time used so far
13 func GetMemStats() string {
14         var memstats runtime.MemStats
15         runtime.ReadMemStats(&memstats)
16         return fmt.Sprintf("Alloc: %s, Sys: %s, GC: %d, PauseTotalNs: %dns", humanize.Bytes(memstats.Alloc), humanize.Bytes(memstats.Sys), memstats.NumGC, memstats.PauseTotalNs)
17 }
18
19 var start time.Time
20
21 func Tic(s string) {
22         log.Println("START:", s)
23         start = time.Now()
24 }
25
26 func Toc() {
27         end := time.Now()
28         log.Println("END: ElapsedTime in seconds:", end.Sub(start))
29 }