/collect

collect all pprof profiles with one command

Primary LanguageGoMIT LicenseMIT

Collect

Go Report Card codecov

Allows you to collect all pprof profiles with one command.

Installation

Just go-get it:

$ 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:

$ 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:

$ 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:

$ collect -u=http://localhost:8080 -u=http://localhost:7070

You can choose which profiles will be scraped:

$ collect -p=allocs -p=heap -u=http://localhost:8080

Query parameters for profiles are also supported:

$ 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).

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