Categorygithub.com/jbleduigou/aws-lambda-profile
modulepackage
0.0.0-20240704142145-047370dacb76
Repository: https://github.com/jbleduigou/aws-lambda-profile.git
Documentation: pkg.go.dev

# 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.

# Functions

AWSRegion sets the AWS region of the S3 bucket.
CPUProfile enables CPU profiling.
MemProfile enables memory profiling.
Quiet suppresses informational messages during profiling.
S3Bucket sets the name of the S3 bucket to upload the profile to.
Start starts a new profiling session.

# Structs

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