scopeagent

package module
v0.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2020 License: Apache-2.0 Imports: 14 Imported by: 1

README

Scope

Scope Go Agent

Scope agent for Go

Installation instructions

Check https://docs.scope.dev/docs/go-installation for detailed installation and usage instructions.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBenchmark

func GetBenchmark(b *testing.B) *scopetesting.Benchmark

Gets the *Benchmark from a *testing.B

func GetContextFromTest

func GetContextFromTest(t *testing.T) context.Context

Gets the context from a test

func GetTest

func GetTest(t *testing.T) *scopetesting.Test

Gets the *Test from a *testing.T

func Run

func Run(m *testing.M, opts ...agent.Option) int

Helper function to run a `testing.M` object and gracefully stopping the agent afterwards

func SetTestCodeFromCaller added in v0.2.0

func SetTestCodeFromCaller(t *testing.T)

Sets the test code from the caller of this func

func SetTestCodeFromCallerSkip added in v0.2.0

func SetTestCodeFromCallerSkip(t *testing.T, skip int)

Sets the test code from the caller of this func

func SetTestCodeFromFunc added in v0.2.0

func SetTestCodeFromFunc(t *testing.T, fn interface{})

Sets the test code from a func

func StartBenchmark

func StartBenchmark(b *testing.B, benchFunc func(b *testing.B))

Instruments the given benchmark func

Example of usage:

func factorial(value int) int {
		if value == 1 {
			return 1
		}
		return value * factorial(value-1)
}
func BenchmarkFactorial(b *testing.B) {
		scopeagent.StartBenchmark(b, func(b *testing.B) {
			for i := 0; i < b.N; i++ {
				_ = factorial(25)
			}
		}
}
func BenchmarkFactorialWithSubBenchmarks(b *testing.B) {
		res := 0

		b.Run("25", func(b *testing.B) {
			scopeagent.StartBenchmark(b, func(b *testing.B) {
				for i := 0; i < b.N; i++ {
					res = factorial(25)
				}
			})
		})

		b.Run("50", func(b *testing.B) {
			scopeagent.StartBenchmark(b, func(b *testing.B) {
				for i := 0; i < b.N; i++ {
					res = factorial(50)
				}
			})
		})

		b.Run("75", func(b *testing.B) {
			scopeagent.StartBenchmark(b, func(b *testing.B) {
				for i := 0; i < b.N; i++ {
					res = factorial(75)
				}
			})
		})

		b.Run("100", func(b *testing.B) {
			scopeagent.StartBenchmark(b, func(b *testing.B) {
				for i := 0; i < b.N; i++ {
					res = factorial(100)
				}
			})
		})

		_ = res
}

func StartTest

func StartTest(t *testing.T, opts ...scopetesting.Option) *scopetesting.Test

Instruments the given test, returning a `Test` object that can be used to extend the test trace

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL