| 1 | // Copyright 2022 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 | "encoding/jsonscip-go gomod github.com/golang/go/src go1.24.0 `encoding/json`/" |
| 19 | "html/templatescip-go gomod github.com/golang/go/src go1.24.0 `html/template`/" |
| 20 | "net/httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/" |
| 21 | |
| 22 | "github.com/google/pprof/internal/measurementscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/" |
| 23 | ) |
| 24 | |
| 25 | // stackView generates the flamegraph view. |
| 26 | func (ui *webInterfacescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#) stackViewscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#stackView().(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#) { |
| 27 | // Get all data in a report. |
| 28 | rpt, errList := ui.makeReportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#makeReport().(w, req, []string{"svg"}, func(cfg *configscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#) { |
| 29 | cfg.CallTreescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#CallTree. = true |
| 30 | cfg.Trimscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Trim. = false |
| 31 | if cfg.Granularityscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Granularity. == "" { |
| 32 | cfg.Granularityscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Granularity. = "filefunctions" |
| 33 | } |
| 34 | }) |
| 35 | if rpt == nil { |
| 36 | return // error already reported |
| 37 | } |
| 38 | |
| 39 | // Make stack data and generate corresponding JSON. |
| 40 | stacks := rpt.Stacksscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/Report#Stacks().() |
| 41 | b, err := jsonscip-go gomod github.com/golang/go/src go1.24.0 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.24.0 `encoding/json`/Marshal().(stacks) |
| 42 | if err != nil { |
| 43 | 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, "error serializing stacks for flame graph", |
| 44 | 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.) |
| 45 | 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) |
| 46 | return |
| 47 | } |
| 48 | |
| 49 | nodes := make([]string, len(stacks.Sourcesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/StackSet#Sources.)) |
| 50 | for i, src := range stacks.Sourcesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/StackSet#Sources. { |
| 51 | nodes[i] = src.FullNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/StackSource#FullName. |
| 52 | } |
| 53 | nodes[0] = "" // root is not a real node |
| 54 | |
| 55 | ui.renderscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webInterface#render().(w, req, "stacks", rpt, errList, stacks.Legendscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/report`/StackSet#Legend().(), webArgsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#{ |
| 56 | 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#(b), |
| 57 | Nodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/webArgs#Nodes.: nodes, |
| 58 | 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`/.UnitTypesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/UnitTypes., |
| 59 | }) |
| 60 | } |