An open API service indexing awesome lists of open source software.

https://github.com/tommsawyer/collect

collect all pprof profiles with one command
https://github.com/tommsawyer/collect

golang pprof

Last synced: 6 months ago
JSON representation

collect all pprof profiles with one command

Awesome Lists containing this project

README

          

# Collect
[![Go Report Card](https://goreportcard.com/badge/github.com/tommsawyer/collect)](https://goreportcard.com/report/github.com/tommsawyer/collect)
[![codecov](https://codecov.io/gh/tommsawyer/collect/branch/main/graph/badge.svg?token=63GFZ0O3OR)](https://codecov.io/gh/tommsawyer/collect)

Allows you to collect all pprof profiles with one command.

## Installation
Just go-get it:
```bash
$ go get github.com/tommsawyer/collect/cmd/collect
```

## Motivation

Sometimes I need to quickly collect all pprof profiles for future optimization. It's very frustrating to do it with long curl commands like:
```bash
$ curl -sK -v http://localhost:8080/debug/pprof/heap > heap.out && curl -sK -v http://localhost:8080/debug/pprof/allocs > allocs.out && curl -sK -v http://localhost:8080/debug/pprof/goroutine > goroutine.out && curl -sK -v http://localhost:8080/debug/pprof/profile > profile.out && curl -o ./trace "http://localhost:8080/debug/pprof/trace?debug=1&seconds=20"

```

Also:
- it doesn't run concurrently, resulting in slow execution
- you have to manually move profiles to some directories if you want to store them for future comparison
- you need to wait for the command to complete and run it again if you want to collect profiles several times

## Usage
Provide url from which profiles will be scraped:
```bash
$ collect -u=http://localhost:8080
```
This will download allocs, heap, goroutine and cpu profiles and save them into a directory structure like this:

```
- localhost 8080
- YYYY MM DD
- HH MM SS
- allocs
- heap
- profile
- goroutine
```

You can provide as many urls as you want:
```bash
$ collect -u=http://localhost:8080 -u=http://localhost:7070
```

You can choose which profiles will be scraped:
```bash
$ collect -p=allocs -p=heap -u=http://localhost:8080
```

Query parameters for profiles are also supported:
```bash
$ collect -p=trace\?seconds\=20 -u=http://localhost:8080
```

Use `-l` flag to collect profiles in an endless loop(until Ctrl-C). This will collect profiles every 60 seconds (you can redefine interval with `-i`).
```bash
$ collect -l -u=http://localhost:8080
```

## Command-Line flags
| Flag | Default | Usage |
| ----------- | -------------------------------| -------------------------------------------|
| -u | | url from which profiles will be collected. |
| -p | allocs,heap,goroutine,profile | profiles to collect. |
| -l | false | collect profiles in endless loop |
| -i | 60s | interval between collecting. use with -l |
| -d | ./ | directory to put the pprof files in. |
| -k | false | keep going collect if some requests failed.|