Skip to content
Measure and aggregate processing time
Go
Branch: master
Clone or download
Latest commit 22a5dc9 Oct 3, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md Update README.md Oct 3, 2018
http.go
metrics.go
metrics_test.go supports multi metrics Sep 23, 2016

README.md

measure

Usage

Measure

Add measure to your code.

import "github.com/najeira/measure"

func foo() {
    defer measure.Start("foo").Stop()

    // your code

}

or

...
m := measure.Start("foo")
// your code
m.Stop()
...

Stats

Get statistics.

stats := measure.GetStats()
stats.SortDesc("sum")

// print stats in CSV format
for _, s := range stats {
	fmt.Fprintf(w, "%s,%d,%f,%f,%f,%f,%f,%f\n",
		s.Key, s.Count, s.Sum, s.Min, s.Max, s.Avg, s.Rate, s.P95)
}

Reset statistics.

measure.Reset()

Metrics

You can handle multiple metrics.

var metricsA = measure.NewMetrics()
var metricsB = measure.NewMetrics()

func foo() {
    defer metricsA.Start("foo").Stop()
}

func bar() {
    defer metricsB.Start("bar").Stop()
}

License

MIT

You can’t perform that action at this time.