Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/daangn/autopprof
Automatically profile the Go applications when CPU or memory utilization crosses threshold
https://github.com/daangn/autopprof
Last synced: about 3 hours ago
JSON representation
Automatically profile the Go applications when CPU or memory utilization crosses threshold
- Host: GitHub
- URL: https://github.com/daangn/autopprof
- Owner: daangn
- License: apache-2.0
- Created: 2022-10-19T03:37:16.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-29T05:22:23.000Z (3 months ago)
- Last Synced: 2024-08-04T04:01:32.378Z (3 months ago)
- Language: Go
- Homepage:
- Size: 204 KB
- Stars: 184
- Watchers: 29
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# autopprof
![Run tests](https://github.com/daangn/autopprof/workflows/Run%20tests/badge.svg) [![Release](https://img.shields.io/github/v/tag/daangn/autopprof?label=Release)](https://github.com/daangn/autopprof/releases)
Automatically profile the Go applications when CPU or memory utilization crosses specific
threshold levels against the Linux container CPU quota and memory limit.Once you start the autopprof, the autopprof process will periodically check the CPU and
memory utilization of the Go applications. If the resource utilization crosses the
specified threshold for each type of resource, the autopprof will automatically profile
the application (heap or cpu) and report the profiling report to the specific reporter (
e.g. Slack).| CPU Profile Report Example | Memory Profile Report Example |
|------------------------------------------------------------|------------------------------------------------------------|
| ![profiling example cpu](images/profiling_example_cpu.png) | ![profiling example mem](images/profiling_example_mem.png) |## Installation
```bash
go get -u github.com/daangn/autopprof
```## Usage
> If your application is running on non-linux systems, you should check the
> ErrUnsupportedPlatform error returned from `autopprof.Start()` and handle it properly.```go
package mainimport (
"errors"
"log""github.com/daangn/autopprof"
"github.com/daangn/autopprof/report"
)func main() {
err := autopprof.Start(autopprof.Option{
CPUThreshold: 0.8, // Default: 0.75.
MemThreshold: 0.8, // Default: 0.75.
Reporter: report.NewSlackReporter(
&report.SlackReporterOption{
App: "YOUR_APP_NAME",
Token: "YOUR_TOKEN_HERE",
Channel: "#REPORT_CHANNEL",
},
),
})
if errors.Is(err, autopprof.ErrUnsupportedPlatform) {
// You can just skip the autopprof.
log.Println(err)
} else if err != nil {
log.Fatalln(err)
}
defer autopprof.Stop()// Your code here.
}
```> You can create a custom reporter by implementing the `report.Reporter` interface.
## Benchmark
Benchmark the overhead of watching the CPU and memory utilization. The overhead is very
small, so we don't have to worry about the performance degradation.> You can run the benchmark test with this command.
>
> ```bash
> ./benchmark.sh
> ```
>```
BenchmarkLightJob-5 49444164 245.6 ns/op 0 B/op 0 allocs/op
BenchmarkLightJobWithWatchCPUUsage-5 48884026 250.1 ns/op 0 B/op 0 allocs/op
BenchmarkLightJobWithWatchMemUsage-5 49036617 246.3 ns/op 0 B/op 0 allocs/op
BenchmarkHeavyJob-5 59010 203759 ns/op 0 B/op 0 allocs/op
BenchmarkHeavyJobWithWatchCPUUsage-5 58915 204054 ns/op 2 B/op 0 allocs/op
BenchmarkHeavyJobWithWatchMemUsage-5 58850 204764 ns/op 2 B/op 0 allocs/op
```## License
[Apache 2.0](LICENSE)