| 1 | // Copyright 2017 Google Inc. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package driverscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/ |
| 16 | |
| 17 | import ( |
| 18 | "bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/" |
| 19 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 20 | "html/templatescip-go gomod github.com/golang/go/src go1.24.0 `html/template`/" |
| 21 | "ioscip-go gomod github.com/golang/go/src go1.24.0 io/" |
| 22 | "mapsscip-go gomod github.com/golang/go/src go1.24.0 maps/" |
| 23 | "netscip-go gomod github.com/golang/go/src go1.24.0 net/" |
| 24 | "net/httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/" |
| 25 | gourlscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/ "net/urlscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/" |
| 26 | "osscip-go gomod github.com/golang/go/src go1.24.0 os/" |
| 27 | "os/execscip-go gomod github.com/golang/go/src go1.24.0 `os/exec`/" |
| 28 | "slicesscip-go gomod github.com/golang/go/src go1.24.0 slices/" |
| 29 | "strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/" |
| 30 | "stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/" |
| 31 | "timescip-go gomod github.com/golang/go/src go1.24.0 time/" |
| 32 | |
| 33 | "github.com/google/pprof/internal/graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/" |
| 34 | "github.com/google/pprof/internal/measurementscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/" |
| 35 | "github.com/google/pprof/internal/pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/" |
| 36 | "github.com/google/pprof/internal/reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/" |
| 37 | "github.com/google/pprof/profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/" |
| 38 | ) |
| 39 | |
| 40 | // webInterface holds the state needed for serving a browser based interface. |
| 41 | type webInterfacescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface# struct { |
| 42 | profscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#prof. *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile# |
| 43 | copierscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#copier. profileCopierscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/profileCopier# |
| 44 | optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#options. *pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.Optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options# |
| 45 | helpscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#help. map[string]string |
| 46 | settingsFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#settingsFile. string |
| 47 | } |
| 48 | |
| 49 | func makeWebInterfacescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/makeWebInterface().(p *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#, copier profileCopierscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/profileCopier#, opt *pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.Optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#) (*webInterfacescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#, error) { |
| 50 | settingsFile, err := settingsFileNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/settingsFileName().() |
| 51 | if err != nil { |
| 52 | return nil, err |
| 53 | } |
| 54 | return &webInterfacescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#{ |
| 55 | profscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#prof.: p, |
| 56 | copierscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#copier.: copier, |
| 57 | optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#options.: opt, |
| 58 | helpscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#help.: make(map[string]string), |
| 59 | settingsFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#settingsFile.: settingsFile, |
| 60 | }, nil |
| 61 | } |
| 62 | |
| 63 | // maxEntries is the maximum number of entries to print for text interfaces. |
| 64 | const maxEntriesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/maxEntries. = 50 |
| 65 | |
| 66 | // errorCatcher is a UI that captures errors for reporting to the browser. |
| 67 | type errorCatcherscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/errorCatcher# struct { |
| 68 | pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/errorCatcher#UI. |
| 69 | errorsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/errorCatcher#errors. []string |
| 70 | } |
| 71 | |
| 72 | func (ec *errorCatcherscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/errorCatcher#) PrintErrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/errorCatcher#PrintErr().(args ...interface{}) { |
| 73 | ec.errorsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/errorCatcher#errors. = append(ec.errorsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/errorCatcher#errors., stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.TrimSuffixscip-go gomod github.com/golang/go/src go1.24.0 strings/TrimSuffix().(fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintlnscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprintln().(args...), "\n")) |
| 74 | ec.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/errorCatcher#UI..PrintErrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#PrintErr.(args...) |
| 75 | } |
| 76 | |
| 77 | // webArgs contains arguments passed to templates in webhtml.go. |
| 78 | type webArgsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs# struct { |
| 79 | Titlescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#Title. string |
| 80 | Errorsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#Errors. []string |
| 81 | Totalscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#Total. int64 |
| 82 | SampleTypesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#SampleTypes. []string |
| 83 | Legendscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#Legend. []string |
| 84 | DocURLscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#DocURL. string |
| 85 | Standalonescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#Standalone. bool // True for command-line generation of HTML |
| 86 | Helpscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#Help. map[string]string |
| 87 | Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#Nodes. []string |
| 88 | HTMLBodyscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#HTMLBody. templatescip-go gomod github.com/golang/go/src go1.24.0 `html/template`/.HTMLscip-go gomod github.com/golang/go/src go1.24.0 `html/template`/HTML# |
| 89 | TextBodyscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#TextBody. string |
| 90 | Topscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#Top. []reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/.TextItemscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/TextItem# |
| 91 | Listingscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#Listing. reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/.WebListDatascip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/WebListData# |
| 92 | FlameGraphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#FlameGraph. templatescip-go gomod github.com/golang/go/src go1.24.0 `html/template`/.JSscip-go gomod github.com/golang/go/src go1.24.0 `html/template`/JS# |
| 93 | Stacksscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#Stacks. templatescip-go gomod github.com/golang/go/src go1.24.0 `html/template`/.JSscip-go gomod github.com/golang/go/src go1.24.0 `html/template`/JS# |
| 94 | Configsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#Configs. []configMenuEntryscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configMenuEntry# |
| 95 | UnitDefsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#UnitDefs. []measurementscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/.UnitTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/UnitType# |
| 96 | } |
| 97 | |
| 98 | func serveWebInterfacescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/serveWebInterface().(hostport string, p *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#, o *pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.Optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#, disableBrowser bool) error { |
| 99 | host, port, err := getHostAndPortscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/getHostAndPort().(hostport) |
| 100 | if err != nil { |
| 101 | return err |
| 102 | } |
| 103 | interactiveModescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/interactiveMode. = true |
| 104 | copier := makeProfileCopierscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/makeProfileCopier().(p) |
| 105 | ui, err := makeWebInterfacescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/makeWebInterface().(p, copier, o) |
| 106 | if err != nil { |
| 107 | return err |
| 108 | } |
| 109 | for n, c := range pprofCommandsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/pprofCommands. { |
| 110 | ui.helpscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#help.[n] = c.descriptionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/command#description. |
| 111 | } |
| 112 | mapsscip-go gomod github.com/golang/go/src go1.24.0 maps/.Copyscip-go gomod github.com/golang/go/src go1.24.0 maps/Copy().(ui.helpscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#help., configHelpscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configHelp.) |
| 113 | ui.helpscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#help.["details"] = "Show information about the profile and this view" |
| 114 | ui.helpscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#help.["graph"] = "Display profile as a directed graph" |
| 115 | ui.helpscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#help.["flamegraph"] = "Display profile as a flame graph" |
| 116 | ui.helpscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#help.["reset"] = "Show the entire profile" |
| 117 | ui.helpscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#help.["save_config"] = "Save current settings" |
| 118 | |
| 119 | server := o.HTTPServerscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#HTTPServer. |
| 120 | if server == nil { |
| 121 | server = defaultWebServerscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/defaultWebServer(). |
| 122 | } |
| 123 | args := &pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.HTTPServerArgsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/HTTPServerArgs#{ |
| 124 | Hostportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/HTTPServerArgs#Hostport.: netscip-go gomod github.com/golang/go/src go1.24.0 net/.JoinHostPortscip-go gomod github.com/golang/go/src go1.24.0 net/JoinHostPort().(host, strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/.Itoascip-go gomod github.com/golang/go/src go1.24.0 strconv/Itoa().(port)), |
| 125 | Hostscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/HTTPServerArgs#Host.: host, |
| 126 | Portscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/HTTPServerArgs#Port.: port, |
| 127 | Handlersscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/HTTPServerArgs#Handlers.: map[string]httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Handlerscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Handler#{ |
| 128 | "/": redirectWithQueryscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/redirectWithQuery().("flamegraph", httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.StatusMovedPermanentlyscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/StatusMovedPermanently.), |
| 129 | "/graph": httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/HandlerFunc#(ui.dotscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#dot().), |
| 130 | "/top": httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/HandlerFunc#(ui.topscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#top().), |
| 131 | "/disasm": httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/HandlerFunc#(ui.disasmscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#disasm().), |
| 132 | "/source": httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/HandlerFunc#(ui.sourcescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#source().), |
| 133 | "/peek": httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/HandlerFunc#(ui.peekscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#peek().), |
| 134 | "/flamegraph": httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/HandlerFunc#(ui.stackViewscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#stackView().), |
| 135 | "/saveconfig": httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/HandlerFunc#(ui.saveConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#saveConfig().), |
| 136 | "/deleteconfig": httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/HandlerFunc#(ui.deleteConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#deleteConfig().), |
| 137 | "/download": httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/ResponseWriter#, req *httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Request#) { |
| 138 | w.Headerscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Header#Set().("Content-Type", "application/vnd.google.protobuf+gzip") |
| 139 | w.Headerscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Header#Set().("Content-Disposition", "attachment;filename=profile.pb.gz") |
| 140 | p.Writescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Write().(w) |
| 141 | }), |
| 142 | // Keep legacy URLs working. |
| 143 | "/flamegraph2": redirectWithQueryscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/redirectWithQuery().("flamegraph", httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.StatusMovedPermanentlyscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/StatusMovedPermanently.), |
| 144 | "/flamegraphold": redirectWithQueryscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/redirectWithQuery().("flamegraph", httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.StatusMovedPermanentlyscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/StatusMovedPermanently.), |
| 145 | }, |
| 146 | } |
| 147 | |
| 148 | url := "http://" + args.Hostportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/HTTPServerArgs#Hostport. |
| 149 | |
| 150 | o.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI..Printscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#Print.("Serving web UI on ", url) |
| 151 | |
| 152 | if o.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI..WantBrowserscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#WantBrowser.() && !disableBrowser { |
| 153 | go openBrowserscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/openBrowser().(url, o) |
| 154 | } |
| 155 | return server(args) |
| 156 | } |
| 157 | |
| 158 | func getHostAndPortscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/getHostAndPort().(hostport string) (string, int, error) { |
| 159 | host, portStr, err := netscip-go gomod github.com/golang/go/src go1.24.0 net/.SplitHostPortscip-go gomod github.com/golang/go/src go1.24.0 net/SplitHostPort().(hostport) |
| 160 | if err != nil { |
| 161 | return "", 0, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("could not split http address: %v", err) |
| 162 | } |
| 163 | if host == "" { |
| 164 | host = "localhost" |
| 165 | } |
| 166 | var port int |
| 167 | if portStr == "" { |
| 168 | ln, err := netscip-go gomod github.com/golang/go/src go1.24.0 net/.Listenscip-go gomod github.com/golang/go/src go1.24.0 net/Listen().("tcp", netscip-go gomod github.com/golang/go/src go1.24.0 net/.JoinHostPortscip-go gomod github.com/golang/go/src go1.24.0 net/JoinHostPort().(host, "0")) |
| 169 | if err != nil { |
| 170 | return "", 0, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("could not generate random port: %v", err) |
| 171 | } |
| 172 | port = ln.Addrscip-go gomod github.com/golang/go/src go1.24.0 net/Listener#Addr().().(*netscip-go gomod github.com/golang/go/src go1.24.0 net/.TCPAddrscip-go gomod github.com/golang/go/src go1.24.0 net/TCPAddr#).Portscip-go gomod github.com/golang/go/src go1.24.0 net/TCPAddr#Port. |
| 173 | err = ln.Closescip-go gomod github.com/golang/go/src go1.24.0 net/Listener#Close().() |
| 174 | if err != nil { |
| 175 | return "", 0, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("could not generate random port: %v", err) |
| 176 | } |
| 177 | } else { |
| 178 | port, err = strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/.Atoiscip-go gomod github.com/golang/go/src go1.24.0 strconv/Atoi().(portStr) |
| 179 | if err != nil { |
| 180 | return "", 0, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("invalid port number: %v", err) |
| 181 | } |
| 182 | } |
| 183 | return host, port, nil |
| 184 | } |
| 185 | func defaultWebServerscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/defaultWebServer().(args *pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.HTTPServerArgsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/HTTPServerArgs#) error { |
| 186 | ln, err := netscip-go gomod github.com/golang/go/src go1.24.0 net/.Listenscip-go gomod github.com/golang/go/src go1.24.0 net/Listen().("tcp", args.Hostportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/HTTPServerArgs#Hostport.) |
| 187 | if err != nil { |
| 188 | return err |
| 189 | } |
| 190 | isLocal := isLocalhostscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/isLocalhost().(args.Hostscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/HTTPServerArgs#Host.) |
| 191 | handler := httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/ResponseWriter#, req *httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Request#) { |
| 192 | if isLocal { |
| 193 | // Only allow local clients |
| 194 | host, _, err := netscip-go gomod github.com/golang/go/src go1.24.0 net/.SplitHostPortscip-go gomod github.com/golang/go/src go1.24.0 net/SplitHostPort().(req.RemoteAddrscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Request#RemoteAddr.) |
| 195 | if err != nil || !isLocalhostscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/isLocalhost().(host) { |
| 196 | httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Errorscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Error().(w, "permission denied", httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.StatusForbiddenscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/StatusForbidden.) |
| 197 | return |
| 198 | } |
| 199 | } |
| 200 | h := args.Handlersscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/HTTPServerArgs#Handlers.[req.URLscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Request#URL..Pathscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/URL#Path.] |
| 201 | if h == nil { |
| 202 | // Fall back to default behavior |
| 203 | h = httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.DefaultServeMuxscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/DefaultServeMux. |
| 204 | } |
| 205 | h.ServeHTTPscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Handler#ServeHTTP().(w, req) |
| 206 | }) |
| 207 | |
| 208 | // We serve the ui at /ui/ and redirect there from the root. This is done |
| 209 | // to surface any problems with serving the ui at a non-root early. See: |
| 210 | // |
| 211 | // https://github.com/google/pprof/pull/348 |
| 212 | mux := httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.NewServeMuxscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/NewServeMux().() |
| 213 | mux.Handlescip-go gomod github.com/golang/go/src go1.24.0 `net/http`/ServeMux#Handle().("/ui/", httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.StripPrefixscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/StripPrefix().("/ui", handler)) |
| 214 | mux.Handlescip-go gomod github.com/golang/go/src go1.24.0 `net/http`/ServeMux#Handle().("/", redirectWithQueryscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/redirectWithQuery().("/ui", httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.StatusTemporaryRedirectscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/StatusTemporaryRedirect.)) |
| 215 | s := &httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Serverscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Server#{Handlerscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Server#Handler.: mux} |
| 216 | return s.Servescip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Server#Serve().(ln) |
| 217 | } |
| 218 | |
| 219 | // redirectWithQuery responds with a given redirect code, preserving query |
| 220 | // parameters in the redirect URL. It does not convert relative paths to |
| 221 | // absolute paths like http.Redirect does, so that HTTPServerArgs.Handlers can |
| 222 | // generate relative redirects that work with the external prefixing. |
| 223 | func redirectWithQueryscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/redirectWithQuery().(path string, code int) httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/HandlerFunc# { |
| 224 | return func(w httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Request#) { |
| 225 | pathWithQuery := &gourlscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/.URLscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/URL#{Pathscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/URL#Path.: path, RawQueryscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/URL#RawQuery.: r.URLscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Request#URL..RawQueryscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/URL#RawQuery.} |
| 226 | w.Headerscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Header#Set().("Location", pathWithQuery.Stringscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/URL#String().()) |
| 227 | w.WriteHeaderscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/ResponseWriter#WriteHeader().(code) |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | func isLocalhostscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/isLocalhost().(host string) bool { |
| 232 | return slicesscip-go gomod github.com/golang/go/src go1.24.0 slices/.Containsscip-go gomod github.com/golang/go/src go1.24.0 slices/Contains().([]string{"localhost", "127.0.0.1", "[::1]", "::1"}, host) |
| 233 | } |
| 234 | |
| 235 | func openBrowserscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/openBrowser().(url string, o *pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.Optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#) { |
| 236 | // Construct URL. |
| 237 | baseURL, _ := gourlscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/.Parsescip-go gomod github.com/golang/go/src go1.24.0 `net/url`/Parse().(url) |
| 238 | current := currentConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/currentConfig().() |
| 239 | u, _ := current.makeURLscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#makeURL().(*baseURL) |
| 240 | |
| 241 | // Give server a little time to get ready. |
| 242 | timescip-go gomod github.com/golang/go/src go1.24.0 time/.Sleepscip-go gomod github.com/golang/go/src go1.24.0 time/Sleep().(timescip-go gomod github.com/golang/go/src go1.24.0 time/.Millisecondscip-go gomod github.com/golang/go/src go1.24.0 time/Millisecond. * 500) |
| 243 | |
| 244 | for _, b := range browsersscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/browsers().() { |
| 245 | args := stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Splitscip-go gomod github.com/golang/go/src go1.24.0 strings/Split().(b, " ") |
| 246 | if len(args) == 0 { |
| 247 | continue |
| 248 | } |
| 249 | viewer := execscip-go gomod github.com/golang/go/src go1.24.0 `os/exec`/.Commandscip-go gomod github.com/golang/go/src go1.24.0 `os/exec`/Command().(args[0], append(args[1:], u.Stringscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/URL#String().())...) |
| 250 | viewer.Stderrscip-go gomod github.com/golang/go/src go1.24.0 `os/exec`/Cmd#Stderr. = osscip-go gomod github.com/golang/go/src go1.24.0 os/.Stderrscip-go gomod github.com/golang/go/src go1.24.0 os/Stderr. |
| 251 | if err := viewer.Startscip-go gomod github.com/golang/go/src go1.24.0 `os/exec`/Cmd#Start().(); err == nil { |
| 252 | return |
| 253 | } |
| 254 | } |
| 255 | // No visualizer succeeded, so just print URL. |
| 256 | o.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI..PrintErrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#PrintErr.(u.Stringscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/URL#String().()) |
| 257 | } |
| 258 | |
| 259 | // makeReport generates a report for the specified command. |
| 260 | // If configEditor is not null, it is used to edit the config used for the report. |
| 261 | func (ui *webInterfacescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#) makeReportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#makeReport().(w httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/ResponseWriter#, req *httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Request#, |
| 262 | cmd []string, configEditor func(*configscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#)) (*reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/.Reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#, []string) { |
| 263 | cfg := currentConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/currentConfig().() |
| 264 | if err := cfg.applyURLscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#applyURL().(req.URLscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Request#URL..Queryscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/URL#Query().()); err != nil { |
| 265 | httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Errorscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Error().(w, err.Error(), httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.StatusBadRequestscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/StatusBadRequest.) |
| 266 | ui.optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#options..UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI..PrintErrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#PrintErr.(err) |
| 267 | return nil, nil |
| 268 | } |
| 269 | if configEditor != nil { |
| 270 | configEditor(&cfg) |
| 271 | } |
| 272 | catcher := &errorCatcherscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/errorCatcher#{UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/errorCatcher#UI.: ui.optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#options..UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI.} |
| 273 | options := *ui.optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#options. |
| 274 | options.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI. = catcher |
| 275 | _, rpt, err := generateRawReportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/generateRawReport().(ui.copierscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#copier..newCopyscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/profileCopier#newCopy().(), cmd, cfg, &options) |
| 276 | if err != nil { |
| 277 | httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Errorscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Error().(w, err.Error(), httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.StatusBadRequestscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/StatusBadRequest.) |
| 278 | ui.optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#options..UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI..PrintErrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#PrintErr.(err) |
| 279 | return nil, nil |
| 280 | } |
| 281 | return rpt, catcher.errorsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/errorCatcher#errors. |
| 282 | } |
| 283 | |
| 284 | // renderHTML generates html using the named template based on the contents of data. |
| 285 | func renderHTMLscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/renderHTML().(dst ioscip-go gomod github.com/golang/go/src go1.24.0 io/.Writerscip-go gomod github.com/golang/go/src go1.24.0 io/Writer#, tmpl string, rpt *reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/.Reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#, errList, legend []string, data webArgsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#) error { |
| 286 | file := getFromLegendscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/getFromLegend().(legend, "File: ", "unknown") |
| 287 | profile := getFromLegendscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/getFromLegend().(legend, "Type: ", "unknown") |
| 288 | data.Titlescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#Title. = file + " " + profile |
| 289 | data.Errorsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#Errors. = errList |
| 290 | data.Totalscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#Total. = rpt.Totalscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#Total().() |
| 291 | data.DocURLscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#DocURL. = rpt.DocURLscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#DocURL().() |
| 292 | data.Legendscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#Legend. = legend |
| 293 | return getHTMLTemplatesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/getHTMLTemplates().().ExecuteTemplatescip-go gomod github.com/golang/go/src go1.24.0 `html/template`/Template#ExecuteTemplate().(dst, tmpl, data) |
| 294 | } |
| 295 | |
| 296 | // render responds with html generated by passing data to the named template. |
| 297 | func (ui *webInterfacescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#) renderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#render().(w httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/ResponseWriter#, req *httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Request#, tmpl string, |
| 298 | rpt *reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/.Reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#, errList, legend []string, data webArgsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#) { |
| 299 | data.SampleTypesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#SampleTypes. = sampleTypesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/sampleTypes().(ui.profscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#prof.) |
| 300 | data.Helpscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#Help. = ui.helpscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#help. |
| 301 | data.Configsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#Configs. = configMenuscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/configMenu().(ui.settingsFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#settingsFile., *req.URLscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Request#URL.) |
| 302 | html := &bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#{} |
| 303 | if err := renderHTMLscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/renderHTML().(html, tmpl, rpt, errList, legend, data); err != nil { |
| 304 | httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Errorscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Error().(w, "internal template error", httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.StatusInternalServerErrorscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/StatusInternalServerError.) |
| 305 | ui.optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#options..UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI..PrintErrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#PrintErr.(err) |
| 306 | return |
| 307 | } |
| 308 | w.Headerscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/ResponseWriter#Header().().Setscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Header#Set().("Content-Type", "text/html") |
| 309 | w.Writescip-go gomod github.com/golang/go/src go1.24.0 `net/http`/ResponseWriter#Write().(html.Bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#Bytes().()) |
| 310 | } |
| 311 | |
| 312 | // dot generates a web page containing an svg diagram. |
| 313 | func (ui *webInterfacescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#) dotscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#dot().(w httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/ResponseWriter#, req *httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Request#) { |
| 314 | rpt, errList := ui.makeReportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#makeReport().(w, req, []string{"svg"}, nil) |
| 315 | if rpt == nil { |
| 316 | return // error already reported |
| 317 | } |
| 318 | |
| 319 | // Generate dot graph. |
| 320 | g, config := reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/.GetDOTscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/GetDOT().(rpt) |
| 321 | legend := config.Labelsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/DotConfig#Labels. |
| 322 | config.Labelsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/DotConfig#Labels. = nil |
| 323 | dot := &bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#{} |
| 324 | graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/.ComposeDotscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/ComposeDot().(dot, g, &graphscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/.DotAttributesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/DotAttributes#{}, config) |
| 325 | |
| 326 | // Convert to svg. |
| 327 | svg, err := dotToSvgscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/dotToSvg().(dot.Bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#Bytes().()) |
| 328 | if err != nil { |
| 329 | httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Errorscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Error().(w, "Could not execute dot; may need to install graphviz.", |
| 330 | httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.StatusNotImplementedscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/StatusNotImplemented.) |
| 331 | ui.optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#options..UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI..PrintErrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#PrintErr.("Failed to execute dot. Is Graphviz installed?\n", err) |
| 332 | return |
| 333 | } |
| 334 | |
| 335 | // Get all node names into an array. |
| 336 | nodes := []string{""} // dot starts with node numbered 1 |
| 337 | for _, n := range g.Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Graph#Nodes. { |
| 338 | nodes = append(nodes, n.Infoscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/Node#Info..Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/graph`/NodeInfo#Name.) |
| 339 | } |
| 340 | |
| 341 | ui.renderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#render().(w, req, "graph", rpt, errList, legend, webArgsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#{ |
| 342 | HTMLBodyscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#HTMLBody.: templatescip-go gomod github.com/golang/go/src go1.24.0 `html/template`/.HTMLscip-go gomod github.com/golang/go/src go1.24.0 `html/template`/HTML#(string(svg)), |
| 343 | Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#Nodes.: nodes, |
| 344 | }) |
| 345 | } |
| 346 | |
| 347 | func dotToSvgscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/dotToSvg().(dot []byte) ([]byte, error) { |
| 348 | cmd := execscip-go gomod github.com/golang/go/src go1.24.0 `os/exec`/.Commandscip-go gomod github.com/golang/go/src go1.24.0 `os/exec`/Command().("dot", "-Tsvg") |
| 349 | out := &bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#{} |
| 350 | cmd.Stdinscip-go gomod github.com/golang/go/src go1.24.0 `os/exec`/Cmd#Stdin., cmd.Stdoutscip-go gomod github.com/golang/go/src go1.24.0 `os/exec`/Cmd#Stdout., cmd.Stderrscip-go gomod github.com/golang/go/src go1.24.0 `os/exec`/Cmd#Stderr. = bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.NewBufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/NewBuffer().(dot), out, osscip-go gomod github.com/golang/go/src go1.24.0 os/.Stderrscip-go gomod github.com/golang/go/src go1.24.0 os/Stderr. |
| 351 | if err := cmd.Runscip-go gomod github.com/golang/go/src go1.24.0 `os/exec`/Cmd#Run().(); err != nil { |
| 352 | return nil, err |
| 353 | } |
| 354 | |
| 355 | // Fix dot bug related to unquoted ampersands. |
| 356 | svg := bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.ReplaceAllscip-go gomod github.com/golang/go/src go1.24.0 bytes/ReplaceAll().(out.Bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#Bytes().(), []byte("&;"), []byte("&;")) |
| 357 | |
| 358 | // Cleanup for embedding by dropping stuff before the <svg> start. |
| 359 | if pos := bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Indexscip-go gomod github.com/golang/go/src go1.24.0 bytes/Index().(svg, []byte("<svg")); pos >= 0 { |
| 360 | svg = svg[pos:] |
| 361 | } |
| 362 | return svg, nil |
| 363 | } |
| 364 | |
| 365 | func (ui *webInterfacescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#) topscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#top().(w httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/ResponseWriter#, req *httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Request#) { |
| 366 | rpt, errList := ui.makeReportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#makeReport().(w, req, []string{"top"}, func(cfg *configscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#) { |
| 367 | cfg.NodeCountscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#NodeCount. = 500 |
| 368 | }) |
| 369 | if rpt == nil { |
| 370 | return // error already reported |
| 371 | } |
| 372 | top, legend := reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/.TextItemsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/TextItems().(rpt) |
| 373 | var nodes []string |
| 374 | for _, item := range top { |
| 375 | nodes = append(nodes, item.Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/TextItem#Name.) |
| 376 | } |
| 377 | |
| 378 | ui.renderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#render().(w, req, "top", rpt, errList, legend, webArgsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#{ |
| 379 | Topscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#Top.: top, |
| 380 | Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#Nodes.: nodes, |
| 381 | }) |
| 382 | } |
| 383 | |
| 384 | // disasm generates a web page containing disassembly. |
| 385 | func (ui *webInterfacescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#) disasmscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#disasm().(w httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/ResponseWriter#, req *httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Request#) { |
| 386 | args := []string{"disasm", req.URLscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Request#URL..Queryscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/URL#Query().().Getscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/Values#Get().("f")} |
| 387 | rpt, errList := ui.makeReportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#makeReport().(w, req, args, nil) |
| 388 | if rpt == nil { |
| 389 | return // error already reported |
| 390 | } |
| 391 | |
| 392 | out := &bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#{} |
| 393 | if err := reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/.PrintAssemblyscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/PrintAssembly().(out, rpt, ui.optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#options..Objscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#Obj., maxEntriesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/maxEntries.); err != nil { |
| 394 | httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Errorscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Error().(w, err.Error(), httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.StatusBadRequestscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/StatusBadRequest.) |
| 395 | ui.optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#options..UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI..PrintErrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#PrintErr.(err) |
| 396 | return |
| 397 | } |
| 398 | |
| 399 | legend := reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/.ProfileLabelsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/ProfileLabels().(rpt) |
| 400 | ui.renderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#render().(w, req, "plaintext", rpt, errList, legend, webArgsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#{ |
| 401 | TextBodyscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#TextBody.: out.Stringscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#String().(), |
| 402 | }) |
| 403 | |
| 404 | } |
| 405 | |
| 406 | // source generates a web page containing source code annotated with profile |
| 407 | // data. |
| 408 | func (ui *webInterfacescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#) sourcescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#source().(w httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/ResponseWriter#, req *httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Request#) { |
| 409 | args := []string{"weblist", req.URLscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Request#URL..Queryscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/URL#Query().().Getscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/Values#Get().("f")} |
| 410 | rpt, errList := ui.makeReportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#makeReport().(w, req, args, nil) |
| 411 | if rpt == nil { |
| 412 | return // error already reported |
| 413 | } |
| 414 | |
| 415 | // Generate source listing. |
| 416 | listing, err := reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/.MakeWebListscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/MakeWebList().(rpt, ui.optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#options..Objscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#Obj., maxEntriesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/maxEntries.) |
| 417 | if err != nil { |
| 418 | httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Errorscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Error().(w, err.Error(), httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.StatusBadRequestscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/StatusBadRequest.) |
| 419 | ui.optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#options..UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI..PrintErrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#PrintErr.(err) |
| 420 | return |
| 421 | } |
| 422 | |
| 423 | legend := reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/.ProfileLabelsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/ProfileLabels().(rpt) |
| 424 | ui.renderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#render().(w, req, "sourcelisting", rpt, errList, legend, webArgsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#{ |
| 425 | Listingscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#Listing.: listing, |
| 426 | }) |
| 427 | } |
| 428 | |
| 429 | // peek generates a web page listing callers/callers. |
| 430 | func (ui *webInterfacescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#) peekscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#peek().(w httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/ResponseWriter#, req *httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Request#) { |
| 431 | args := []string{"peek", req.URLscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Request#URL..Queryscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/URL#Query().().Getscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/Values#Get().("f")} |
| 432 | rpt, errList := ui.makeReportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#makeReport().(w, req, args, func(cfg *configscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#) { |
| 433 | cfg.Granularityscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Granularity. = "lines" |
| 434 | }) |
| 435 | if rpt == nil { |
| 436 | return // error already reported |
| 437 | } |
| 438 | |
| 439 | out := &bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#{} |
| 440 | if err := reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/.Generatescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Generate().(out, rpt, ui.optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#options..Objscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#Obj.); err != nil { |
| 441 | httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Errorscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Error().(w, err.Error(), httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.StatusBadRequestscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/StatusBadRequest.) |
| 442 | ui.optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#options..UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI..PrintErrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#PrintErr.(err) |
| 443 | return |
| 444 | } |
| 445 | |
| 446 | legend := reportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/.ProfileLabelsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/ProfileLabels().(rpt) |
| 447 | ui.renderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#render().(w, req, "plaintext", rpt, errList, legend, webArgsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#{ |
| 448 | TextBodyscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#TextBody.: out.Stringscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#String().(), |
| 449 | }) |
| 450 | } |
| 451 | |
| 452 | // saveConfig saves URL configuration. |
| 453 | func (ui *webInterfacescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#) saveConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#saveConfig().(w httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/ResponseWriter#, req *httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Request#) { |
| 454 | if err := setConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/setConfig().(ui.settingsFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#settingsFile., *req.URLscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Request#URL.); err != nil { |
| 455 | httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Errorscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Error().(w, err.Error(), httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.StatusBadRequestscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/StatusBadRequest.) |
| 456 | ui.optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#options..UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI..PrintErrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#PrintErr.(err) |
| 457 | return |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | // deleteConfig deletes a configuration. |
| 462 | func (ui *webInterfacescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#) deleteConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#deleteConfig().(w httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/ResponseWriter#, req *httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Request#) { |
| 463 | name := req.URLscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Request#URL..Queryscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/URL#Query().().Getscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/Values#Get().("config") |
| 464 | if err := removeConfigscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/removeConfig().(ui.settingsFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#settingsFile., name); err != nil { |
| 465 | httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Errorscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Error().(w, err.Error(), httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.StatusBadRequestscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/StatusBadRequest.) |
| 466 | ui.optionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#options..UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Options#UI..PrintErrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#PrintErr.(err) |
| 467 | return |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | // getFromLegend returns the suffix of an entry in legend that starts |
| 472 | // with param. It returns def if no such entry is found. |
| 473 | func getFromLegendscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/getFromLegend().(legend []string, param, def string) string { |
| 474 | for _, s := range legend { |
| 475 | if stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.24.0 strings/HasPrefix().(s, param) { |
| 476 | return s[len(param):] |
| 477 | } |
| 478 | } |
| 479 | return def |
| 480 | } |