profile

package module
v0.0.0-...-047370d Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2024 License: BSD-2-Clause Imports: 10 Imported by: 1

README

profile: AWS Lambda performance profiling

Go Version GoDoc Build Status Go report Contributors License

An AWS Lambda Function performance profiling tool based on profile package by Dave Cheney.
The idea is to provide an adapter on top of the existing package to make it easier to use in the context of AWS Lambda.
The profiling output file is uploaded to an S3 bucket.

🚀 Install

go get github.com/jbleduigou/aws-lambda-profile

Compatibility: go >= 1.21

💡 Usage

GoDoc: https://pkg.go.dev/github.com/jbleduigou/aws-lambda-profile

Basic example

To enable profiling in your application, you need to add one line in your main function:

import profile "github.com/jbleduigou/aws-lambda-profile"

func main(ctx context.Context) {
    defer profile.Start(profile.S3Bucket("pprof-bucket"), profile.AWSRegion("eu-west-1")).Stop(ctx)
}
CPU profiling

By default, the CPU profiling is enabled.
You can still explicitly enable it by using the CPUProfile option:

import profile "github.com/jbleduigou/aws-lambda-profile"

defer profile.Start(profile.CPUProfile, profile.S3Bucket("pprof-bucket"), profile.AWSRegion("eu-west-1")).Stop(ctx)
Memory profiling

To enable memory profiling, you can use the MemProfile option:

import profile "github.com/jbleduigou/aws-lambda-profile"

defer profile.Start(profile.MemProfile, profile.S3Bucket("pprof-bucket"), profile.AWSRegion("eu-west-1")).Stop(ctx)

🤝 Contributing

Feel free to contribute to this project, either my opening issues or submitting pull requests.
Don't hesitate to contact me, by sending me a PM on LinkedIn.

👤 Contributors

The only contributor so far is me, Jean-Baptiste Le Duigou. Feel free to check my blog to about my other projects: http://www.jbleduigou.com

💫 Show your support

Give a ⭐️ if this project helped you!

GitHub Sponsors

📝 License

This project is BSD licensed.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AWSRegion

func AWSRegion(region string) func(*Profile) func(pkg *pkgprofile.Profile)

AWSRegion sets the AWS region of the S3 bucket.

func CPUProfile

func CPUProfile(p *Profile) func(pkg *pkgprofile.Profile)

CPUProfile enables CPU profiling. It disables any previous profiling settings.

func MemProfile

func MemProfile(p *Profile) func(pkg *pkgprofile.Profile)

MemProfile enables memory profiling. It disables any previous profiling settings.

func Quiet

func Quiet(*Profile) func(pkg *pkgprofile.Profile)

Quiet suppresses informational messages during profiling.

func S3Bucket

func S3Bucket(bucket string) func(*Profile) func(pkg *pkgprofile.Profile)

S3Bucket sets the name of the S3 bucket to upload the profile to.

func Start

func Start(options ...func(*Profile) func(pkg *pkgprofile.Profile)) interface {
	Stop(context.Context)
}

Start starts a new profiling session. The caller should call the Stop method on the value returned to cleanly stop profiling.

Types

type Profile

type Profile struct {
	// contains filtered or unexported fields
}

Profile is an adapter for github.com/pkg/profile

func (*Profile) Stop

func (p *Profile) Stop(ctx context.Context)

Stop stops the profile and flushes any unwritten data.

Jump to

Keyboard shortcuts

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