profiler

package
v0.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

README

Profiler Utilities

Important Notes

  • This package is designed for troubleshooting performance related issues such as
    • Memory Leak
    • High CPU Usage
  • This package MUST NOT be used in production.

How To Use

This package leverage GO runtime/pprof and net/http/pprof packages.

For more efficient troubleshooting, this package should be used together with GO benchmarking techniques and suitable pprof visualization tools.

Serve pprof Data via HTTP

To enable pprof over HTTP, add following code before application start, usually in init() of application's main package:

package main
import "github.com/cisco-open/go-lanai/pkg/profiler"
func init() {
	profiler.Use()
}

The profiler package will enable runtime/pprof and install following endpoints under application's server.context-path:

  • GET /${server.contex-path}/debug/pprof/[pprof_profile]: Dump compressed raw data as gz.

    Common [pprof_profile] values are

    • heap
    • block
    • goroutine
    • threadcreate
    • mutex
  • GET /${server.contex-path}/debug/pprof/cmdline: Returns running program's command line, with arguments separated by NUL bytes.

  • GET /${server.contex-path}/debug/pprof/profile: Returns the pprof-formatted cpu profile.

  • GET /${server.contex-path}/debug/pprof/symbol: Looks up the program counters listed in the request, responding with a table mapping program counters to function names

  • GET /${server.contex-path}/debug/pprof/trace: Returns the execution trace in binary form

More details about GO pprof can be found at:

Visualize pprof Data

There are many tools available to visualize data produced by pprof. Here is an exmaple:

Tool: Google pprof GO implementation

Prerequisites:

  1. Go development kit (recommended 1.16+)

  2. Graphviz. To install on MacOS:

    brew install graphviz
    

Install google/pprof CLI:

go install github.com/google/pprof@latest

Example Usage (Investigating AuthService's memory allocation):

pprof -http=localhost:6061 http://localhost:8900/auth/debug/pprof/heap

Command above would start a web service at localhost:6061 and render various views of current heap snapshot.

Use pprof --help for detailed usage.

Real-Time Performance Monitoring

This folder also includes a performance monitoring utility that serve an HTML page of real-time metrics charts. To enable it:

package main
import "github.com/cisco-open/go-lanai/pkg/profiler/monitor"
func init() {
	monitor.Use()
}

The charts can be accessed via HTTP http://server:port/<context-path>/debug/charts/

Note: This is an experimental feature and may consume fare amount of resources.

Documentation

Index

Constants

View Source
const (
	RouteGroup      = "debug"
	PathPrefixPProf = "pprof"
)

Variables

View Source
var Module = &bootstrap.Module{
	Precedence: bootstrap.DebugPrecedence,
	Options: []fx.Option{
		fx.Invoke(initialize),
	},
}

Functions

func Use

func Use()

Use Allow service to include this module in main()

Types

type PProfController

type PProfController struct{}

func (*PProfController) Mappings

func (c *PProfController) Mappings() []web.Mapping

func (*PProfController) Profile

func (c *PProfController) Profile(gc *gin.Context)

type PProfRequest

type PProfRequest struct {
	Profile string `uri:"profile"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL