Skip to content

Commit

Permalink
add:trace 收集展示
Browse files Browse the repository at this point in the history
  • Loading branch information
xyctruth committed Dec 24, 2021
1 parent f93a707 commit a5f0a99
Show file tree
Hide file tree
Showing 41 changed files with 39 additions and 42 deletions.
9 changes: 4 additions & 5 deletions pkg/apiserver/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import (
"net/http"
"time"

"github.com/xyctruth/profiler/pkg/apiserver/trace"

"github.com/gin-gonic/gin"
"github.com/google/pprof/profile"
log "github.com/sirupsen/logrus"
"github.com/xyctruth/profiler/pkg/apiserver/pprof"
"github.com/xyctruth/profiler/pkg/apiserver/trace"
"github.com/xyctruth/profiler/pkg/storage"
"github.com/xyctruth/profiler/pkg/utils"
)
Expand All @@ -20,8 +19,8 @@ type APIServer struct {
store storage.Store
router *gin.Engine
srv *http.Server
pprof *pprof.PProfServer
trace *trace.TraceServer
pprof *pprof.Server
trace *trace.Server
}

func NewAPIServer(addr string, store storage.Store) *APIServer {
Expand All @@ -31,7 +30,7 @@ func NewAPIServer(addr string, store storage.Store) *APIServer {
apiServer := &APIServer{
store: store,
pprof: pprof.NewPProfServer(pprofPath, store),
trace: trace.NewTraceServer(tracePath, store),
trace: trace.NewServer(tracePath, store),
}

router := gin.Default()
Expand Down
26 changes: 13 additions & 13 deletions pkg/apiserver/pprof/pprofflags.go → pkg/apiserver/pprof/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,70 +5,70 @@ import (
"strings"
)

type pprofFlags struct {
type flags struct {
args []string
s flag.FlagSet
usage []string
}

// Bool implements the plugin.FlagSet interface.
func (p *pprofFlags) Bool(o string, d bool, c string) *bool {
func (p *flags) Bool(o string, d bool, c string) *bool {
return p.s.Bool(o, d, c)
}

// Int implements the plugin.FlagSet interface.
func (p *pprofFlags) Int(o string, d int, c string) *int {
func (p *flags) Int(o string, d int, c string) *int {
return p.s.Int(o, d, c)
}

// Float64 implements the plugin.FlagSet interface.
func (p *pprofFlags) Float64(o string, d float64, c string) *float64 {
func (p *flags) Float64(o string, d float64, c string) *float64 {
return p.s.Float64(o, d, c)
}

// String implements the plugin.FlagSet interface.
func (p *pprofFlags) String(o, d, c string) *string {
func (p *flags) String(o, d, c string) *string {
return p.s.String(o, d, c)
}

// BoolVar implements the plugin.FlagSet interface.
func (p *pprofFlags) BoolVar(b *bool, o string, d bool, c string) {
func (p *flags) BoolVar(b *bool, o string, d bool, c string) {
p.s.BoolVar(b, o, d, c)
}

// IntVar implements the plugin.FlagSet interface.
func (p *pprofFlags) IntVar(i *int, o string, d int, c string) {
func (p *flags) IntVar(i *int, o string, d int, c string) {
p.s.IntVar(i, o, d, c)
}

// Float64Var implements the plugin.FlagSet interface.
// the value of the flag.
func (p *pprofFlags) Float64Var(f *float64, o string, d float64, c string) {
func (p *flags) Float64Var(f *float64, o string, d float64, c string) {
p.s.Float64Var(f, o, d, c)
}

// StringVar implements the plugin.FlagSet interface.
func (p *pprofFlags) StringVar(s *string, o, d, c string) {
func (p *flags) StringVar(s *string, o, d, c string) {
p.s.StringVar(s, o, d, c)
}

// StringList implements the plugin.FlagSet interface.
func (p *pprofFlags) StringList(o, d, c string) *[]*string {
func (p *flags) StringList(o, d, c string) *[]*string {
return &[]*string{p.s.String(o, d, c)}
}

// AddExtraUsage implements the plugin.FlagSet interface.
func (p *pprofFlags) AddExtraUsage(eu string) {
func (p *flags) AddExtraUsage(eu string) {
p.usage = append(p.usage, eu)
}

// ExtraUsage implements the plugin.FlagSet interface.
func (p *pprofFlags) ExtraUsage() string {
func (p *flags) ExtraUsage() string {
return strings.Join(p.usage, "\n")
}

// Parse implements the plugin.FlagSet interface.
func (p *pprofFlags) Parse(usage func()) []string {
func (p *flags) Parse(usage func()) []string {
p.s.Usage = usage
_ = p.s.Parse(p.args)
args := p.s.Args()
Expand Down
15 changes: 7 additions & 8 deletions pkg/apiserver/pprof/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@ import (
"path"
"sync"

"github.com/xyctruth/profiler/pkg/utils"

"github.com/google/pprof/driver"
"github.com/xyctruth/profiler/pkg/storage"
"github.com/xyctruth/profiler/pkg/utils"
)

type PProfServer struct {
type Server struct {
mux *http.ServeMux
mu sync.Mutex
basePath string
store storage.Store
}

func NewPProfServer(basePath string, store storage.Store) *PProfServer {
s := &PProfServer{
func NewPProfServer(basePath string, store storage.Store) *Server {
s := &Server{
mux: http.NewServeMux(),
basePath: basePath,
store: store,
Expand All @@ -31,11 +30,11 @@ func NewPProfServer(basePath string, store storage.Store) *PProfServer {
return s
}

func (s *PProfServer) Web(w http.ResponseWriter, r *http.Request) {
func (s *Server) Web(w http.ResponseWriter, r *http.Request) {
s.mux.ServeHTTP(w, r)
}

func (s *PProfServer) register(w http.ResponseWriter, r *http.Request) {
func (s *Server) register(w http.ResponseWriter, r *http.Request) {
id := utils.ExtractProfileID(r.URL.Path)
if id == "" {
http.Error(w, "Invalid parameter", http.StatusBadRequest)
Expand All @@ -60,7 +59,7 @@ func (s *PProfServer) register(w http.ResponseWriter, r *http.Request) {
return
}

flags := &pprofFlags{
flags := &flags{
args: []string{"-http=localhost:0", "-no_browser", filepath},
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/apiserver/trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import (
"path"
"sync"

"github.com/xyctruth/profiler/pkg/go/v1175/traceui"
"github.com/xyctruth/profiler/pkg/internal/v1175/traceui"
"github.com/xyctruth/profiler/pkg/storage"
"github.com/xyctruth/profiler/pkg/utils"
)

type TraceServer struct {
type Server struct {
mux *http.ServeMux
mu sync.Mutex
basePath string
store storage.Store
}

func NewTraceServer(basePath string, store storage.Store) *TraceServer {
s := &TraceServer{
func NewServer(basePath string, store storage.Store) *Server {
s := &Server{
mux: http.NewServeMux(),
basePath: basePath,
store: store,
Expand All @@ -30,11 +30,11 @@ func NewTraceServer(basePath string, store storage.Store) *TraceServer {
return s
}

func (s *TraceServer) Web(w http.ResponseWriter, r *http.Request) {
func (s *Server) Web(w http.ResponseWriter, r *http.Request) {
s.mux.ServeHTTP(w, r)
}

func (s *TraceServer) register(w http.ResponseWriter, r *http.Request) {
func (s *Server) register(w http.ResponseWriter, r *http.Request) {
id := utils.ExtractProfileID(r.URL.Path)
if id == "" {
http.Error(w, "Invalid parameter", http.StatusBadRequest)
Expand Down
3 changes: 1 addition & 2 deletions pkg/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import (
"sync"
"time"

"github.com/xyctruth/profiler/pkg/go/v1175/trace"

"github.com/google/pprof/profile"
"github.com/sirupsen/logrus"
"github.com/xyctruth/profiler/pkg/internal/v1175/trace"
"github.com/xyctruth/profiler/pkg/storage"
)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"strings"
"time"

"github.com/xyctruth/profiler/pkg/go/v1175/trace"
"github.com/xyctruth/profiler/pkg/internal/v1175/trace"
)

// httpUserTasks reports all tasks found in the trace.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"sync"
"time"

"github.com/xyctruth/profiler/pkg/go/v1175/trace"
"github.com/xyctruth/profiler/pkg/internal/v1175/trace"
)

// gtype describes a group of goroutines grouped by start PC.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"sync"
"time"

"github.com/xyctruth/profiler/pkg/go/v1175/trace"
"github.com/xyctruth/profiler/pkg/internal/v1175/trace"
)

var utilFlagNames = map[string]trace.UtilFlags{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
"strconv"
"time"

exec "github.com/xyctruth/profiler/pkg/go/v1175/execabs"
exec "github.com/xyctruth/profiler/pkg/internal/v1175/execabs"

"github.com/xyctruth/profiler/pkg/go/v1175/trace"
"github.com/xyctruth/profiler/pkg/internal/v1175/trace"

"github.com/google/pprof/profile"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"strings"
"time"

"github.com/xyctruth/profiler/pkg/go/v1175/trace"
"github.com/xyctruth/profiler/pkg/go/v1175/traceviewer"
"github.com/xyctruth/profiler/pkg/internal/v1175/trace"
"github.com/xyctruth/profiler/pkg/internal/v1175/traceviewer"
)

// httpTrace serves either whole trace (goid==0) or trace for goid goroutine.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

_ "net/http/pprof" // Required to use pprof

"github.com/xyctruth/profiler/pkg/go/v1175/trace"
"github.com/xyctruth/profiler/pkg/internal/v1175/trace"
)

type TraceUI struct {
Expand Down
File renamed without changes.

0 comments on commit a5f0a99

Please sign in to comment.