github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/internal/trace/traceviewer/pprof.go (about)

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Serving of pprof-like profiles.
     6  
     7  package traceviewer
     8  
     9  import (
    10  	"github.com/shogo82148/std/internal/profile"
    11  	"github.com/shogo82148/std/internal/trace"
    12  	"github.com/shogo82148/std/net/http"
    13  	"github.com/shogo82148/std/time"
    14  )
    15  
    16  type ProfileFunc func(r *http.Request) ([]ProfileRecord, error)
    17  
    18  // SVGProfileHandlerFunc serves pprof-like profile generated by prof as svg.
    19  func SVGProfileHandlerFunc(f ProfileFunc) http.HandlerFunc
    20  
    21  type ProfileRecord struct {
    22  	Stack []*trace.Frame
    23  	Count uint64
    24  	Time  time.Duration
    25  }
    26  
    27  func BuildProfile(prof []ProfileRecord) *profile.Profile