pprof source and disasm views overcount recursive functions
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 45/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- go
- Área
- performance, tooling
Línea de trabajo
Comienza inspeccionando internal/report/source.go en la línea referenciada y reproduce el perfil recursivo de fac con go tool pprof, comparando la página Sources con list fac. Rastrea cómo se agregan las muestras acumuladas para las llamadas recursivas en las vistas de código fuente y desensamblado. Se considera terminado cuando las funciones recursivas ya no informen de porcentajes ni tiempos acumulados superiores al total del perfil.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
What version of pprof are you using?
go tool pprof with go1.18.3.
Full go env output
GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/keyhan/.cache/go-build" GOENV="/home/keyhan/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/keyhan/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/keyhan/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/snap/go/9848" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/snap/go/9848/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.18.3" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/dev/null" GOWORK="" 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-build2938140119=/tmp/go-build -gno-record-gcc-switches"
What operating system and processor architecture are you using?
Linux, x86-64 Intel.
What did you do?
I opened the attached profile with go tool pprof -http=: fac.pb.gz,
and navigated to the "Sources" page. Here is the output:

As you can see, it is claimed that fac took 6193% of the total time.
It is also said that it took 150 seconds, which is wrong since the
program took only a couple of seconds.
The issue also occurs with the command line version, although strangely
the output is better.
(pprof) list fac
Total: 2.43s
ROUTINE ======================== main.fac in /home/keyhan/exgo/e.go
2.43s 3.34s (flat, cum) 137.45% of Total
. . 2:
. . 3:import "os"
. . 4:import "log"
. . 5:import "runtime/pprof"
. . 6:
850ms 850ms 7:func fac(n uint64) uint64 {
60ms 60ms 8: if n == 0 {
. . 9: return 1
. . 10: } else {
1.52s 2.43s 11: return n * fac(n - 1)
. . 12: }
. . 13:}
. . 14:
. . 15:func main() {
. . 16: f, err := os.Create("example.pb.gz")
What did you expect to see?
cum% should not be more than 100%.
What did you see instead?
cum% is claimed to be 6193%.
Root cause(?)
I believe the root cause is this line of code:
This is wrong, since the cumulative time spent in the current function
is not fns.Sum() if the function calls itself recursively. In those
cases some nodes will be counted multiple times.
Source Code
package main
import "os"
import "log"
import "runtime/pprof"
func fac(n uint64) uint64 {
if n == 0 {
return 1
} else {
return n * fac(n - 1)
}
}
func main() {
f, err := os.Create("example.pb.gz")
if err != nil {
log.Fatal("could not create CPU profile: ", err)
}
defer f.Close() // error handling omitted for example
if err := pprof.StartCPUProfile(f); err != nil {
log.Fatal("could not start CPU profile: ", err)
}
defer pprof.StopCPUProfile()
for i := 1; i <= 1e6; i++ {
fac(1000)
}
}
- Lenguaje dominante
- Go
- Estrellas
- 9.3k
- Forks
- 683
- Merge medio
- 1 d 21 h
- PR fusionados (30 d)
- 10
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de google/pprof
-
Make comments more discoverable in the web UIPosiblemente ocupada @jabrailkhalil la tomó hace 25 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
google/pprof#1029 · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 74/100
google/pprof#1020 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
pprof cannot locate source code for the list command in common Go setupsPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
google/pprof#1009 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Label with zero int64 value and no unit get dropped during decodingPosiblemente ocupada @ms-hujia la tomó hace 130 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 55/100
google/pprof#1002 · 6 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 42/100
google/pprof#992 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de google/pprof
Issues similares
-
stage-fail
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
siyuan-note/bazaar#2405 ·
Los mantenedores suelen responder en 1 día
-
bug priority: high workstream:cache
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
rossoctl/context-guru#707 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
prime-radiant-inc/evener#5028 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100