Permalink
Please sign in to comment.
Browse files
Merge pull request #12 from performancecopilot/string-type-support
add string type support for metrics, closes #4
- Loading branch information...
Showing
with
87 additions
and 17 deletions.
- +42 −0 examples/simple_string_metric/main.go
- +14 −0 metrics.go
- +7 −3 registry.go
- +24 −14 writer.go
| @@ -0,0 +1,42 @@ | ||
| +package main | ||
| + | ||
| +import ( | ||
| + "flag" | ||
| + "time" | ||
| + | ||
| + "github.com/performancecopilot/speed" | ||
| +) | ||
| + | ||
| +var timelimit = flag.Int("time", 60, "number of seconds to run for") | ||
| + | ||
| +func main() { | ||
| + flag.Parse() | ||
| + | ||
| + w, err := speed.NewPCPWriter("stringtest", speed.ProcessFlag) | ||
| + if err != nil { | ||
| + panic(err) | ||
| + } | ||
| + | ||
| + names := []string{ | ||
| + "Batman", | ||
| + "Robin", | ||
| + "Nightwing", | ||
| + "Batgirl", | ||
| + "Red Robin", | ||
| + "Red Hood", | ||
| + } | ||
| + | ||
| + m, err := w.RegisterString("bat.names", names[0], speed.InstantSemantics, speed.StringType, speed.OneUnit) | ||
| + if err != nil { | ||
| + panic(err) | ||
| + } | ||
| + | ||
| + w.Start() | ||
| + defer w.Stop() | ||
| + | ||
| + metric := m.(speed.SingletonMetric) | ||
| + for i := 0; i < *timelimit; i++ { | ||
| + metric.Set(names[i%len(names)]) | ||
| + time.Sleep(time.Second) | ||
| + } | ||
| +} |
14
metrics.go
10
registry.go
0 comments on commit
ed0d7f8