distribution/Godeps/_workspace/src/github.com/yvasiyarov/gorelic/examples/example1.go
Stephen J Day fc2a840e8f Use Godep to vendor distribution dependencies
As we get closer to release, we need to ensure that builds are repeatable.
Godep provides a workable solution to managing dependencies in Go to support
this requirement. This commit should be bolstered by updates to documentation
and build configuration.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2015-01-12 14:01:04 -08:00

52 lines
1 KiB
Go

package main
import (
"flag"
"github.com/yvasiyarov/gorelic"
"log"
"math/rand"
"runtime"
"time"
)
var newrelicLicense = flag.String("newrelic-license", "", "Newrelic license")
func allocateAndSum(arraySize int) int {
arr := make([]int, arraySize, arraySize)
for i := range arr {
arr[i] = rand.Int()
}
time.Sleep(time.Duration(rand.Intn(3000)) * time.Millisecond)
result := 0
for _, v := range arr {
result += v
}
//log.Printf("Array size is: %d, sum is: %d\n", arraySize, result)
return result
}
func doSomeJob(numRoutines int) {
for {
for i := 0; i < numRoutines; i++ {
go allocateAndSum(rand.Intn(1024) * 1024)
}
log.Printf("All %d routines started\n", numRoutines)
time.Sleep(1000 * time.Millisecond)
runtime.GC()
}
}
func main() {
flag.Parse()
if *newrelicLicense == "" {
log.Fatalf("Please, pass a valid newrelic license key.\n Use --help to get more information about available options\n")
}
agent := gorelic.NewAgent()
agent.Verbose = true
agent.NewrelicLicense = *newrelicLicense
agent.Run()
doSomeJob(100)
}