Skip to content

cmd/pprof: heap command top and traces show different data #34236

Closed
@q2683252

Description

@q2683252

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

$ go version
go version go1.11.5 linux/amd64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

$ go env GOARCH="amd64" GOBIN="" GOCACHE="/data/tbase/.cache/go-build" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/data/tbase/oss_compile/golang_pkg/packages:" GOPROXY="" GORACE="" GOROOT="/usr/lib/golang" GOTMPDIR="" GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64" GCCGO="gccgo" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build502356231=/tmp/go-build -gno-record-gcc-switches" Output

What did you do?

I write a program to test pprof heap but I found someting inconsisitent.

go  tool pprof  http://127.0.0.1:8200/debug/pprof/heap?debug=1
Fetching profile over HTTP from http://127.0.0.1:8200/debug/pprof/heap?debug=1
Saved profile in /data/tbase/pprof/pprof.alloc_objects.alloc_space.inuse_objects.inuse_space.005.pb.gz
Type: inuse_space
No samples were found with the default sample value type.
Try "sample_index" command to analyze different sample values.
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) top
Showing nodes accounting for 0, 0% of 0 total
      flat  flat%   sum%        cum   cum%
(pprof) traces
Type: inuse_space
-----------+-------------------------------------------------------
     bytes:  2kB
         0   runtime/pprof.writeHeapInternal
             runtime/pprof.writeHeap
             runtime/pprof.(*Profile).WriteTo
             net/http/pprof.handler.ServeHTTP
             net/http/pprof.Index
             net/http.HandlerFunc.ServeHTTP
             net/http.(*ServeMux).ServeHTTP
             net/http.serverHandler.ServeHTTP
             net/http.(*conn).serve
             runtime.goexit
-----------+-------------------------------------------------------
     bytes:  136kB
         0   compress/flate.(*compressor).init
             compress/flate.NewWriter
             compress/gzip.(*Writer).Write
             runtime/pprof.(*profileBuilder).build
             runtime/pprof.writeHeapProto
             runtime/pprof.writeHeapInternal
             runtime/pprof.writeHeap
             runtime/pprof.(*Profile).WriteTo
             net/http/pprof.handler.ServeHTTP
             net/http/pprof.Index
             net/http.HandlerFunc.ServeHTTP
             net/http.(*ServeMux).ServeHTTP
             net/http.serverHandler.ServeHTTP
             net/http.(*conn).serve
             runtime.goexit
-----------+-------------------------------------------------------
     bytes:  8kB
         0   bytes.makeSlice
             bytes.(*Buffer).grow
             bytes.(*Buffer).ReadFrom
             io/ioutil.readAll
             io/ioutil.ReadFile
             runtime/pprof.(*profileBuilder).readMapping
             runtime/pprof.newProfileBuilder
             runtime/pprof.writeHeapProto
             runtime/pprof.writeHeapInternal
             runtime/pprof.writeHeap
             runtime/pprof.(*Profile).WriteTo
             net/http/pprof.handler.ServeHTTP
             net/http/pprof.Index
             net/http.HandlerFunc.ServeHTTP
             net/http.(*ServeMux).ServeHTTP
             net/http.serverHandler.ServeHTTP
             net/http.(*conn).serve
             runtime.goexit
-----------+-------------------------------------------------------
     bytes:  1kB
         0   sync.(*Pool).pinSlow
             sync.(*Pool).pin
             sync.(*Pool).Get
             net/http.newBufioWriterSize
             net/http.(*conn).readRequest
             net/http.(*conn).serve
             runtime.goexit
-----------+-------------------------------------------------------
     bytes:  2.25kB
         0   compress/flate.(*huffmanEncoder).generate
             compress/flate.(*huffmanBitWriter).writeBlockDynamic
             compress/flate.(*compressor).encSpeed
             compress/flate.(*compressor).close
             compress/flate.(*Writer).Close
             compress/gzip.(*Writer).Close
             runtime/pprof.(*profileBuilder).build
             runtime/pprof.writeHeapProto
             runtime/pprof.writeHeapInternal
             runtime/pprof.writeHeap
             runtime/pprof.(*Profile).WriteTo
             net/http/pprof.handler.ServeHTTP
             net/http/pprof.Index
             net/http.HandlerFunc.ServeHTTP
             net/http.(*ServeMux).ServeHTTP
             net/http.serverHandler.ServeHTTP
             net/http.(*conn).serve
             runtime.goexit
-----------+-------------------------------------------------------
     bytes:  648kB
         0   compress/flate.NewWriter
             compress/gzip.(*Writer).Write
             runtime/pprof.(*profileBuilder).build
             runtime/pprof.writeHeapProto
             runtime/pprof.writeHeapInternal
             runtime/pprof.writeHeap
             runtime/pprof.(*Profile).WriteTo
             net/http/pprof.handler.ServeHTTP
             net/http/pprof.Index
             net/http.HandlerFunc.ServeHTTP
             net/http.(*ServeMux).ServeHTTP
             net/http.serverHandler.ServeHTTP
             net/http.(*conn).serve
             runtime.goexit
-----------+-------------------------------------------------------
     bytes:  1GB
         0   main.Test1
             main.Test
             runtime.goexit
-----------+-------------------------------------------------------
(pprof) 

What did you expect to see?

Top command shows nothing but traces command shows there are many memory usage.
And when I used top only to found out it did not cause that much memory.

25586_ tbase 20 0 1670.0m 36.7m 3.0m S 16.3 0.2 30:13.38 test

Here is my program.

package main

import (
                _ "net/http/pprof"
                "time"
                "net/http"
                "strconv"
                "log"
)

func Test1() {
        a := make([]byte,1024 *1024 * 1024)
        for i := 1 ; i < 1024 * 1024 * 1024 ; i++ {
                a[i] = 'c'
        }
        for true {
                time.Sleep(10000);
        }
}

func Test() {

        Test1();

}

func main() {

        go func() {
                server_addr := ":" + strconv.Itoa(8200)
                log.Println(http.ListenAndServe(server_addr, nil))
        }()

        go Test()

        for true {
                time.Sleep(10000);
        }
}

How can I explain their difference?

What did you see instead?

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions