cprofile

package module
v0.0.0-...-88fc160 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2017 License: MIT Imports: 17 Imported by: 0

README

cprofile

Tool to gather useful information about a Go program

Problem

Would like to understand the composition of a partial or complete Go program (library or executable) via AST exporation.

Would like to be able to easily observe performance of Golang programs, sorting and filtering to discover hotspots, with a cross-platform interactive GUI.

Tools

This program exposes several tools

Globals

Using the globals command, one can discover whether there are any instances of global variables in the code.

cprofile globals main
Imports

The imports command will list the imported packages. See the complete documentation.

Building

go build -o bin/cprofile main/main.go

Vendoring

Use the dep tool for vendoring.

dep ensure

Documentation

Index

Constants

View Source
const (
	// DefaultAstDepth specifies that the AST loader will only inspect the specified
	// package
	DefaultAstDepth AstDepth = Shallow

	// DefaultDepth specifies that there is no limit to the number of imports that
	// the AST loader will delve into
	DefaultDepth int = -1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AstDepth

type AstDepth int

AstDepth directs the classifications of packages inspected

const (
	// Shallow addresses the contents of the package
	Shallow AstDepth = iota

	// Deep addresses the contents of the given package and all its referenced children
	Deep

	// Local addresses the contents of all packages in the same organization
	Local

	// Wide addresses the contents of all directly and indirectly imported non-stdlib packages
	Wide

	// Complete addresses the contents of every imported package, including stdlib
	Complete
)

func CheckAstDepth

func CheckAstDepth(v string) (AstDepth, error)

CheckAstDepth validates the AstDepth flag

type ImportError

type ImportError interface {
	error
	AddPackage(*build.Package)
}

ImportError is an error that comes from reading the import chain

func NewImportError

func NewImportError(packageName string, currentPackage *build.Package, base error) ImportError

NewImportError returns a new import error

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader will load code into an AST

func NewLoader

func NewLoader() *Loader

NewLoader constructs a new Loader struct

func (*Loader) Load

func (l *Loader) Load(ctx context.Context, base string, optionFns ...LoaderOptionsFunc) (*Program, error)

Load reads in the AST

type LoaderOptions

type LoaderOptions struct {
	AstDepth AstDepth
	Depth    int
}

LoaderOptions are the options used by the Loader to limit package transversal

func NewLoaderOptions

func NewLoaderOptions(l *Log, funcs ...LoaderOptionsFunc) *LoaderOptions

NewLoaderOptions creates a new LoaderOptions struct and preconfigures it using any provided funcs.

type LoaderOptionsFunc

type LoaderOptionsFunc func(lo *LoaderOptions) (*LoaderOptions, error)

LoaderOptionsFunc allows functions to determine the state of the LoaderOptions

type Log

type Log struct {
	// contains filtered or unexported fields
}

Log is a fairly basic logger

func GetLog

func GetLog(name string, w io.Writer) *Log

GetLog will return a log for the given name, creating one with the provided writer as needed

func Stderr

func Stderr() *Log

Stderr gets the log for os.Stderr

func Stdout

func Stdout() *Log

Stdout gets the log for os.Stdout

func (*Log) Debugf

func (l *Log) Debugf(msg string, v ...interface{})

Debugf will write if the log level is at least Debug. If the pointer receiver is nil, the log for `os.Stdout` will be used.

func (*Log) Errorf

func (l *Log) Errorf(msg string, v ...interface{})

Errorf will write if the log level is at least Error. If the pointer receiver is nil, the log for `os.Stdout` will be used.

func (*Log) Infof

func (l *Log) Infof(msg string, v ...interface{})

Infof will write if the log level is at least Info. If the pointer receiver is nil, the log for `os.Stdout` will be used.

func (*Log) Printf

func (l *Log) Printf(msg string, v ...interface{})

Printf will always log the given message, regardless of log level set. If the pointer receiver is nil, the log for `os.Stdout` will be used.

func (*Log) SetLevel

func (l *Log) SetLevel(lvl LogLevel)

SetLevel will adjust the logger's level. If the pointer receiver is nil, the log for `os.Stdout` will be used.

func (*Log) Verbosef

func (l *Log) Verbosef(msg string, v ...interface{})

Verbosef will write if the log level is at least Verbose. If the pointer receiver is nil, the log for `os.Stdout` will be used.

func (*Log) Warnf

func (l *Log) Warnf(msg string, v ...interface{})

Warnf will write if the log level is at least Warn. If the pointer receiver is nil, the log for `os.Stdout` will be used.

type LogLevel

type LogLevel int

LogLevel is the logging level: None, Error, Warn, Info, Verbose, or Debug

const (
	// None means that the log should never write
	None LogLevel = iota

	// Error means that only errors will be written
	Error

	// Warn means that errors and warnings will be written
	Warn

	// Info logging writes info, warning, and error
	Info

	// Verbose logs everything bug debug-level messages
	Verbose

	// Debug logs every message
	Debug
)

type Package

type Package struct {
	// contains filtered or unexported fields
}

Package represents a Go package

func (*Package) Functions

func (p *Package) Functions(fset *token.FileSet, scope string) []string

func (*Package) Globals

func (p *Package) Globals(fset *token.FileSet) []string

Globals returns a list of global variables in the package

func (*Package) Imports

func (p *Package) Imports() ([]*types.Object, error)

Imports returns the list of packages imported by this package

func (*Package) Name

func (p *Package) Name() string

Name returns the name of this package.

type Program

type Program struct {
	// contains filtered or unexported fields
}

Program is a mass of code

func (*Program) FileSet

func (p *Program) FileSet() *token.FileSet

FileSet returns the set of files involved across all packages loaded for this program

func (*Program) Imports

func (p *Program) Imports() []*Package

Imports returns an array of all packages imported by the program

func (*Program) Package

func (p *Program) Package() (*Package, error)

Package returns the top-level package for this program

Directories

Path Synopsis
test

Jump to

Keyboard shortcuts

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