Skip to content

cmd/pprof: rejects inuse_space flag with debug=0 profiles #18230

@rhysh

Description

@rhysh
go version devel +be8a6fd2e3 Wed Dec 7 17:09:37 2016 +0000 darwin/amd64

The go tool pprof command cannot interpret gzipped-protobuf-formatted heap profiles in -inuse_space or -inuse_objects modes.

What did you do?

Test cases are adapted from #16892.

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

go tool pprof -raw -output=/dev/null -inuse_space 'http://127.0.0.1:8080/debug/pprof/heap'

echo '--- loops now ---'
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 &>/dev/null
    done
done

kill -KILL -- "$server"
rm ./server

What did you expect to see?

I expected cmd/pprof to be able to show "inuse" space and allocation count profiles from the new gzipped-protobuf-formatted profiles generated by runtime/pprof and net/http/pprof.

What did you see instead?

The go tool pprof command prints help text followed by the message "option -inuse_space not valid for this profile" when asked to show the in-use space from a debug=0 profile at tip.

The pprof command from github.com/google/pprof correctly interprets the profiles.

$ ./test.sh 
go version devel +be8a6fd2e3 Wed Dec 7 17:09:37 2016 +0000 darwin/amd64
Fetching profile from http://127.0.0.1:8080/debug/pprof/heap
Saved profile in /Users/rhys/pprof/pprof.127.0.0.1:8080.alloc_objects.alloc_space.inuse_objects.inuse_space.008.pb.gz
usage: pprof [options] [binary] <profile source> ...
Output format (only set one):
  -callgrind        Outputs a graph in callgrind format
  -disasm=p         Output annotated assembly for functions matching regexp or address
  -dot              Outputs a graph in DOT format
  -eog              Visualize graph through eog
  -evince           Visualize graph through evince
  -gif              Outputs a graph image in GIF format
  -gv               Visualize graph through gv
  -list=p           Output annotated source for functions matching regexp
  -pdf              Outputs a graph in PDF format
  -peek=p           Output callers/callees of functions matching regexp
  -png              Outputs a graph image in PNG format
  -proto            Outputs the profile in compressed protobuf format
  -ps               Outputs a graph in PS format
  -raw              Outputs a text representation of the raw profile
  -svg              Outputs a graph in SVG format
  -tags             Outputs all tags in the profile
  -text             Outputs top entries in text form
  -top              Outputs top entries in text form
  -tree             Outputs a text rendering of call graph
  -web              Visualize graph through web browser
  -weblist=p        Output annotated source in HTML for functions matching regexp or address
Output file parameters (for file-based output formats):
  -output=f         Generate output on file f (stdout by default)
Output granularity (only set one):
  -functions        Report at function level [default]
  -files            Report at source file level
  -lines            Report at source line level
  -addresses        Report at address level
Comparison options:
  -base <profile>   Show delta from this profile
  -drop_negative    Ignore negative differences
Sorting options:
  -cum              Sort by cumulative data

Dynamic profile options:
  -seconds=N        Length of time for dynamic profiles
Profile trimming options:
  -nodecount=N      Max number of nodes to show
  -nodefraction=f   Hide nodes below <f>*total
  -edgefraction=f   Hide edges below <f>*total
Sample value selection option (by index):
  -sample_index      Index of sample value to display
  -mean              Average sample value over first value
Sample value selection option (for heap profiles):
  -inuse_space      Display in-use memory size
  -inuse_objects    Display in-use object counts
  -alloc_space      Display allocated memory size
  -alloc_objects    Display allocated object counts
Sample value selection option (for contention profiles):
  -total_delay      Display total delay at each region
  -contentions      Display number of delays at each region
  -mean_delay       Display mean delay at each region
Filtering options:
  -runtime          Show runtime call frames in memory profiles
  -focus=r          Restricts to paths going through a node matching regexp
  -ignore=r         Skips paths going through any nodes matching regexp
  -tagfocus=r       Restrict to samples tagged with key:value matching regexp
                    Restrict to samples with numeric tags in range (eg "32kb:1mb")
  -tagignore=r      Discard samples tagged with key:value matching regexp
                    Avoid samples with numeric tags in range (eg "1mb:")
Miscellaneous:
  -call_tree        Generate a context-sensitive call tree
  -unit=u           Convert all samples to unit u for display
  -divide_by=f      Scale all samples by dividing them by f
  -buildid=id       Override build id for main binary in profile
  -tools=path       Search path for object-level tools
  -help             This message
Environment Variables:
   PPROF_TMPDIR       Location for saved profiles (default $HOME/pprof)
   PPROF_TOOLS        Search path for object-level tools
   PPROF_BINARY_PATH  Search path for local binary files
                      default: $HOME/pprof/binaries
                      finds binaries by $name and $buildid/$name
option -inuse_space not valid for this profile
--- loops now ---
failed tool=go\ tool\ pprof record='' view=-inuse_space
failed tool=go\ tool\ pprof record=-inuse_space view=-inuse_space
failed tool=go\ tool\ pprof record=-inuse_space view=-alloc_space
failed tool=go\ tool\ pprof record=-alloc_space view=-inuse_space

/cc @matloob @rauls5382

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions