Skip to content

cmd/pprof: forces choice between "inuse" and "alloc" heap profiles #16892

@rhysh

Description

@rhysh

Hello! I've got a bug with go tool pprof's proto format that forces a choice between "inuse" and "alloc" modes (assuming "inuse" by default), which means I've got to capture two separate profiles or use the standalone google/pprof tool.

  1. What version of Go are you using (go version)?

    $ go version
    go version devel +8f3c8a3 Fri Aug 26 20:06:58 2016 +0000 darwin/amd64
    $ go1.7 version
    go version go1.7 darwin/amd64
    
  2. What operating system and processor architecture are you using (go env)?

    darwin/amd64, though I've also observed this on linux/amd64.

  3. What did you do?

    First, I run a trivial http server with pprof enabled. Then I point go tool pprof at it, asking the command to save a gzipped-protobuf-formatted heap profile. I then try to read that profile in various modes: inuse_space and alloc_space

  4. What did you expect to see?

    I expected a single saved heap profile to be readable in all four modes (inuse_space, inuse_objects, alloc_space, alloc_objects). I expected this because the other pprof tool can do this, and because the text file served from /debug/pprof/heap can be interpreted in all four modes.

  5. What did you see instead?

    A heap profile saved with go tool pprof -proto -inuse_space -output ./file http://... cannot be read with go tool pprof -alloc_space ./file, and vice versa.

main.go:

package main

import (
    "net/http"
    _ "net/http/pprof"
)

var sink []byte

func main() {
    for i := 0; i < 10; i++ {
        sink = make([]byte, 1<<20)
    }
    panic(http.ListenAndServe("127.0.0.1:8080", nil))
}

test.sh:

#!/usr/bin/env bash

go version

go build -o ./server ./main.go
./server &
server="$!"
sleep 1

for tool in "go tool pprof" "pprof"; do
    for record_style in "" "-inuse_space" "-alloc_space"; do
        $tool $record_style -proto -symbolize=remote -output ./heap.pb.gz http://127.0.0.1:8080/debug/pprof/heap &>/dev/null
        for view_style in "-inuse_space" "-alloc_space"; do
            $tool $view_style -top ./heap.pb.gz &>/dev/null || printf "failed tool=%q record=%q view=%q\n" "$tool" "$record_style" "$view_style"
        done
        rm ./heap.pb.gz
    done
done

kill -KILL -- "$server"
rm ./server
$ ./test.sh 
go version devel +8f3c8a3 Fri Aug 26 20:06:58 2016 +0000 darwin/amd64
failed tool=go\ tool\ pprof record='' view=-alloc_space
failed tool=go\ tool\ pprof record=-inuse_space view=-alloc_space
failed tool=go\ tool\ pprof record=-alloc_space view=-inuse_space
$ PATH="$HOME/go1.7/bin:$PATH" ./test.sh 
go version go1.7 darwin/amd64
failed tool=go\ tool\ pprof record='' view=-alloc_space
failed tool=go\ tool\ pprof record=-inuse_space view=-alloc_space
failed tool=go\ tool\ pprof record=-alloc_space view=-inuse_space

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions