reading net/http/pprof file format (heap/cpu profile)

400 views
Skip to first unread message

fem...@googlemail.com

unread,
Jul 11, 2018, 8:42:37 AM7/11/18
to golang-nuts
Hello,


I'm trying to read the raw data net/http/pprof supplies. I've tried using protoc with the proto file that comes in github.com/google/pprof/proto/profile.proto. I'm grabbing the heap profile via  http.Get on the default endpoint. After trying to Unmarshal, the error is: 

  bad wiretype for field profiling.Profile.Mapping: got wiretype 7, want 2

I can't seem to find proper documentation on the process of reading the files, could you point me in the right direction?

greetings

lafolle

unread,
Jul 25, 2018, 2:15:12 PM7/25/18
to golang-nuts
This is what i did:

1. Enabled net/http/pprof on server.
2. Collected cpu profile for 5s: curl http://localhost:6060/debug/pprof/profile?seconds=5 -o cpu-profile-over-http.gz
3. Copied profile.proto file from github/pprof/proto into current directory.
4. Generated profile.pb.go by: protoc profile.proto --go_out .
5. Read "cpu-profile-over-http.gz" by: go run profile.pb.go main.go,  where main.go is

package main

import (
        "compress/gzip"
        "fmt"
        "io/ioutil"
        "os"

)

func main() {

        f, err := os.Open("cpu-profile-over-http.gz")
        if err != nil {
                panic(err)
        }

        r, err := gzip.NewReader(f)
        if err != nil {
                panic(err)
        }

        data, err := ioutil.ReadAll(r)
        if err != nil {
                panic(err)
        }

        p := Profile{}

        err = proto.Unmarshal(data, &p)
        if err != nil {
                panic(err)
        }

        fmt.Println(p)

}



The output of which seems correct.

Did you take similar steps?  If no,  then try this.  Otherwise we would need to look at some other angle.

-----

On the other hand it seems the error you mentioned "bad wiretype for field ..." is present in v1.0.0 and not in v1.1.0 (latest) of protobuf.

If you're using old version,  consider upgrading protobuf to v1.1.0 (check releases in github)

fem...@googlemail.com

unread,
Jul 31, 2018, 7:44:05 AM7/31/18
to golang-nuts
I didn't use gzip after fetching via `net/http`. D'oh!

thanks for the help.
Reply all
Reply to author
Forward
0 new messages