pgo

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2023 License: Apache-2.0 Imports: 9 Imported by: 1

README

Embedded pgo-fleet profiler

import "github.com/t2bot/pgo-fleet/embedded"

Usage

See godoc for detailed docs.

Quickstart:

endpoint, err := pgo.NewCollectorEndpoint("https://collector.example.org/v1/submit", "YourSecretKeyGoesHere")
if err != nil {
	panic(err)
}

// Run a profile about once an hour for 5 minutes, submitting to the given endpoint
pgo.Enable(1 * time.Hour, 5 * time.Minute, endpoint)

// Stop collecting profiles
pgo.Disable()

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorFunc func(err error)

ErrorFunc is an optional error handler for any errors raised while collecting profiles. If not set, errors will be silently ignored (the default).

Functions

func Disable

func Disable()

Disable prevents the next CPU profile from being run, but if a profile is already in progress then that profile will be submitted. That profile runner will not be rescheduled, however.

func Enable

func Enable(interval time.Duration, sampleSize time.Duration, endpoint Endpoint)

Enable begins CPU profiling with the given interval and sampleSize. The first profile will begin after 1 interval. After the interval, the CPU profile will begin buffering for sampleSize amount of time. Once sampleSize is elapsed, the CPU profile is stopped and submitted to the given endpoint.

Only after the profile is fully submitted to the endpoint will another wait for interval begins. That is, the time between profiles is `interval + sampleSize + submission time`.

Any encountered errors during the profile and submission will be sent to ErrorFunc.

Enable implies a call to Disable first.

Types

type CollectorEndpoint

type CollectorEndpoint struct {
	Endpoint
	// contains filtered or unexported fields
}

CollectorEndpoint is an Endpoint compatible with pgo-fleet's `collector` process.

func NewCollectorEndpoint

func NewCollectorEndpoint(apiUrl string, authKey string) (*CollectorEndpoint, error)

NewCollectorEndpoint creates a new Endpoint compatible with pgo-fleet's `collector` process. The API URL is the URL to HTTP POST the profile to upon submission, and the authKey will be provided in the Authentication header.

An error is only returned if the given URL is invalid in some way.

func (*CollectorEndpoint) Submit

func (e *CollectorEndpoint) Submit(profile io.Reader) error

type Endpoint

type Endpoint interface {
	Submit(profile io.Reader) error
}

Endpoint is an interface to describe where to submit profiles to when they're collected.

Jump to

Keyboard shortcuts

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