prism: Index | Files

package tools

import ""


Package Files

ast.go callgraph.go injector.go package.go ssa.go

type CallGraph Uses

type CallGraph []*CallGraphNode

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

type CallGraphNode Uses

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 Uses

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 Uses

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 Uses

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: ""

package foo

func MoreStuff(){}

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

The injector targets for the two functions are defined as:

func (*GoPackage) Patch Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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.

Package tools imports 18 packages (graph) and is imported by 1 packages. Updated 2016-11-21. Refresh now. Tools for package owners.