]> git.lizzy.rs Git - micro.git/blob - internal/util/profile.go
Merge pull request #1423 from caligari87/patch-1
[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 func Tic(s string) time.Time {
20         log.Println("START:", s)
21         return time.Now()
22 }
23
24 func Toc(start time.Time) {
25         end := time.Now()
26         log.Println("END: ElapsedTime in seconds:", end.Sub(start))
27 }