github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/examples/metrics-export/app/main.go (about)

     1  package main
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/pyroscope-io/client/pyroscope"
     7  )
     8  
     9  //go:noinline
    10  func work(n int) {
    11  	// revive:disable:empty-block this is fine because this is a example app, not real production code
    12  	for i := 0; i < n; i++ {
    13  	}
    14  	// revive:enable:empty-block
    15  }
    16  
    17  func fastFunction() {
    18  	work(2000)
    19  }
    20  
    21  func slowFunction() {
    22  	work(8000)
    23  }
    24  
    25  func main() {
    26  	pyroscope.Start(pyroscope.Config{
    27  		ApplicationName: "simple.golang.app",
    28  		ServerAddress:   "http://pyroscope:4040", // this will run inside docker-compose, hence `pyroscope` for hostname
    29  		Tags: map[string]string{
    30  			"env": os.Getenv("APP_ENV"),
    31  		},
    32  	})
    33  
    34  	for {
    35  		fastFunction()
    36  		slowFunction()
    37  	}
    38  }