goprof

package module
v0.0.0-...-71c946b Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2017 License: MIT Imports: 18 Imported by: 0

README

goprof

This library provides single entry point to all profiling functionality available in golang 1.5. StartProfiling starts writing trace and cpu profile to some random directory it creates before running. When you call StopProfiling it writes heap profile to the same directory as well as stopping current profiling. By default, StartProfiling writes profiles up to 5 minutes in order to avoid forgotten profiling.

Code example

http.HandleFunc("/", index)
	// we start profiling tools at a separate address in background
	go func() {
		profilingAddress := ":8033"
		fmt.Printf("Running profiling tools on %v\n", profilingAddress)
		if err := goprof.ListenAndServe(profilingAddress); err != nil {
			panic(err)
		}
	}()

Logging

By default, the library writes logs about start/stop profiling and errors using standard go logger. You can provide your own log function in order to make it fit your logging or shut up the logging at all.

We don't use much log levels since all the messages have quite the same level.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenAndServe

func ListenAndServe(address string) error

ListenAndServe starts server on provided address for toggling profiling and downloading results

func NewHandler

func NewHandler() http.Handler

NewHandler creates http handler for the whole profiling tools application If you want to use it aside of other handlers, don't miss http.StripPrefix wrapping like

mux.Handle("/pprof/", http.StripPrefix("/pprof", goprof.NewHandler()))

func SetLogFunction

func SetLogFunction(fxn LogFxn)

SetLogFunction changes function used for logging. Logging is very basic and doesn't have many levels, since all the messages has quite the same level

Types

type LogFxn

type LogFxn func(format string, args ...interface{})

LogFxn is function which is used for writing log messages It doesn't have many levels, since all the messages has quite the same level

type ProfileListResponse

type ProfileListResponse struct {
	OK    bool   `json:"ok"`
	Items []prof `json:"items"`
}

type SimpleResponse

type SimpleResponse struct {
	OK           bool   `json:"ok"`
	ErrorMessage string `json:"error_message,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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