File: main.go

package info (click to toggle)
golang-github-performancecopilot-speed 4.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 508 kB
  • sloc: makefile: 38
file content (39 lines) | stat: -rw-r--r-- 824 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// this example showcases speeds metric inference from strings property
package main

import (
	"flag"
	"log"
	"time"

	"github.com/performancecopilot/speed/v4"
)

var timelimit = flag.Int("time", 60, "number of seconds to run for")

func main() {
	flag.Parse()

	c, err := speed.NewPCPClient("strings")
	if err != nil {
		log.Fatal("Could not create client, error: ", err)
	}

	m, err := c.RegisterString(
		"this.is.a.simple.counter.metric.to.demonstrate.the.RegisterString.function",
		10, speed.Int32Type, speed.CounterSemantics, speed.OneUnit)
	if err != nil {
		log.Fatal("Could not register string, error: ", err)
	}

	c.MustStart()
	defer c.MustStop()

	metric := m.(speed.SingletonMetric)
	for i := 0; i < *timelimit; i++ {
		val := metric.Val().(int32)
		val++
		metric.MustSet(val)
		time.Sleep(time.Second)
	}
}