tools

package
Version: v0.0.0-...-11988c7 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallGraph

type CallGraph []*CallGraphNode

CallGraph is a slice of callgraph nodes obtained by performing Rapid Type Analysis (RTA) on a ProfileTarget.

type CallGraphNode

type CallGraphNode struct {
	// A fully qualified function name reachable through a ProfileTarget.
	Name string

	// Number of hops from the callgraph entrypoint (root).
	Depth int
}

CallGraphNode models a section of the callgraph that is reachable through a Target root node via one or more hops.

type GoPackage

type GoPackage struct {

	// The fully qualified package name for the base package.
	PkgPrefix string

	// The GOPATH for loading package dependencies. We intentionally override it
	// so that the workspace path where this package's sources exist is included first.
	GOPATH string
	// contains filtered or unexported fields
}

GoPackage contains the SSA analysis output performed on a package and all packages it imports.

func NewGoPackage

func NewGoPackage(pathToPackage string) (*GoPackage, error)

NewGoPackage analyzes all go files in pathToPackage as well as any other packages that are referenced by them and constructs a static single-assignment representation of the underlying code.

func (*GoPackage) Find

func (pkg *GoPackage) Find(targetList ...string) ([]ProfileTarget, error)

Find will lookup a list of fully qualified profile targets inside the parsed package sources. These targets serve as the entrypoint for injecting profiler hooks to any function reachable by that entrypoint.

Injector targets for functions without receivers are constructed by concatenating the fully qualified package name where the function is defined, a '/' character and the function name.

If the function uses a receiver, the target name is constructed by concatenating the fully qualified package name, a '/' character, the function receiver's name, a '.' character and finally the function name.

Here is an example of constructing injector targets for a set of functions defined in package: "github.com/geckoboard/foo"

package foo

func MoreStuff(){}

type Foo struct{}
func (f *Foo) DoStuff(){}

The injector targets for the two functions are defined as:

github.com/geckoboard/foo/MoreStuff
github.com/geckoboard/foo/Foo.DoStuff

func (*GoPackage) Patch

func (pkg *GoPackage) Patch(vendorPkgRegex []string, patchCmds ...PatchCmd) (updatedFiles int, patchCount int, err error)

Patch iterates the list of go source files that comprise this package and any folder defined inside it and applies the patch function to AST entries matching the given list of targets.

This function will automatically overwrite any files that are modified by the given patch function.

type PatchCmd

type PatchCmd struct {
	// The slice of targets to hook.
	Targets []ProfileTarget

	// The patch function to apply to functions matching the target.
	PatchFn PatchFunc
}

PatchCmd groups together a list of targets and a patch function to apply to them.

type PatchFunc

type PatchFunc func(cgNode *CallGraphNode, fnDeclNode *ast.BlockStmt) (modifiedAST bool, extraImports []string)

PatchFunc is a function used to modify the AST for a go function matching a profile target. The function should return a flag to indicate whether the AST of the function was modified and a list of additional package imports to be injected into the file where the target is defined.

The method is passed a callgraph node instance and the AST node that corresponds to its body.

func InjectProfiler

func InjectProfiler() PatchFunc

InjectProfiler returns a PatchFunc that injects our profiler instrumentation code in all functions that are reachable from the profile targets that the user specified.

func InjectProfilerBootstrap

func InjectProfilerBootstrap(profileDir, profileLabel string) PatchFunc

InjectProfilerBootstrap returns a PatchFunc that injects our profiler init code the main function of the target package.

type ProfileTarget

type ProfileTarget struct {
	// The fully qualified function name for the target.
	QualifiedName string

	// The fully qualified package name for the analyzed go package.
	PkgPrefix string
	// contains filtered or unexported fields
}

ProfileTarget encapsulates the SSA representation of a function that serves as an entrypoint for applying profiler instrumentation code to itself and any functions reachable through it.

func (*ProfileTarget) CallGraph

func (pt *ProfileTarget) CallGraph() CallGraph

CallGraph constructs a callgraph containing the list of qualified function names in the project package and its sub-packages that are reachable via a call to the profile target.

The discovery of any functions reachable by the endpoint is facilitated by the use of Rapid Type Analysis (RTA).

The discovery algorithm only considers functions whose FQN begins with the processed root package name. This includes any vendored dependencies.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto