process

package
v1.17.1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2022 License: MIT Imports: 12 Imported by: 157

Documentation

Index

Constants

View Source
const DescriptionPProfLabel = "process-description"

DescriptionPProfLabel is a label set on goroutines that have a process attached

View Source
const PIDPProfLabel = "pid"

PIDPProfLabel is a label set on goroutines that have a process attached

View Source
const PPIDPProfLabel = "ppid"

PPIDPProfLabel is a label set on goroutines that have a process attached

View Source
const ProcessTypePProfLabel = "process-type"

ProcessTypePProfLabel is a label set on goroutines that have a process attached

Variables

View Source
var (
	SystemProcessType  = "system"
	RequestProcessType = "request"
	NormalProcessType  = "normal"
	NoneProcessType    = "none"
)
View Source
var (

	// DefaultContext is the default context to run processing commands in
	DefaultContext = context.Background()
)
View Source
var ProcessContextKey interface{} = "process-context"

ProcessContextKey is the key under which process contexts are stored

Functions

func SetSysProcAttribute added in v1.16.9

func SetSysProcAttribute(cmd *exec.Cmd)

SetSysProcAttribute sets the common SysProcAttrs for commands

Types

type Context added in v1.16.0

type Context struct {
	context.Context
	// contains filtered or unexported fields
}

Context is a wrapper around context.Context and contains the current pid for this context

func GetContext added in v1.16.0

func GetContext(ctx context.Context) *Context

GetContext will return a process context if one exists

func (*Context) GetPID added in v1.16.0

func (c *Context) GetPID() IDType

GetPID returns the PID for this context

func (*Context) GetParent added in v1.16.0

func (c *Context) GetParent() *Context

GetParent returns the parent process context (if any)

func (*Context) Value added in v1.16.0

func (c *Context) Value(key interface{}) interface{}

Value is part of the interface for context.Context. We mostly defer to the internal context - but we return this in response to the ProcessContextKey

type Error added in v1.13.0

type Error struct {
	PID         IDType
	Description string
	Err         error
	CtxErr      error
	Stdout      string
	Stderr      string
}

Error is a wrapped error describing the error results of Process Execution

func (*Error) Error added in v1.13.0

func (err *Error) Error() string

func (*Error) Unwrap added in v1.13.0

func (err *Error) Unwrap() error

Unwrap implements the unwrappable implicit interface for go1.13 Unwrap()

type FinishedFunc added in v1.16.0

type FinishedFunc = context.CancelFunc

FinishedFunc is a function that marks that the process is finished and can be removed from the process table - it is simply an alias for context.CancelFunc and is only for documentary purposes

type IDType added in v1.16.0

type IDType string

IDType is a pid type

func GetPID added in v1.16.0

func GetPID(ctx context.Context) IDType

GetPID returns the PID for this context

func GetParentPID added in v1.16.0

func GetParentPID(ctx context.Context) IDType

GetParentPID returns the ParentPID for this context

type Label added in v1.17.0

type Label struct {
	Name  string
	Value string
}

Label represents a pprof label assigned to goroutine stack

type Manager added in v1.1.0

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

Manager manages all processes and counts PIDs.

func GetManager added in v1.1.0

func GetManager() *Manager

GetManager returns a Manager and initializes one as singleton if there's none yet

func (*Manager) Add added in v1.1.0

func (pm *Manager) Add(ctx context.Context, description string, cancel context.CancelFunc, processType string, currentlyRunning bool) (context.Context, IDType, FinishedFunc)

Add create a new process

func (*Manager) AddContext added in v1.16.0

func (pm *Manager) AddContext(parent context.Context, description string) (ctx context.Context, cancel context.CancelFunc, finished FinishedFunc)

AddContext creates a new context and adds it as a process. Once the process is finished, finished must be called to remove the process from the process table. It should not be called until the process is finished but must always be called.

cancel should be used to cancel the returned context, however it will not remove the process from the process table. finished will cancel the returned context and remove it from the process table.

Most processes will not need to use the cancel function but there will be cases whereby you want to cancel the process but not immediately remove it from the process table.

func (*Manager) AddContextTimeout added in v1.16.0

func (pm *Manager) AddContextTimeout(parent context.Context, timeout time.Duration, description string) (ctx context.Context, cancel context.CancelFunc, finshed FinishedFunc)

AddContextTimeout creates a new context and add it as a process. Once the process is finished, finished must be called to remove the process from the process table. It should not be called until the process is finished but must always be called.

cancel should be used to cancel the returned context, however it will not remove the process from the process table. finished will cancel the returned context and remove it from the process table.

Most processes will not need to use the cancel function but there will be cases whereby you want to cancel the process but not immediately remove it from the process table.

func (*Manager) AddTypedContext added in v1.17.0

func (pm *Manager) AddTypedContext(parent context.Context, description, processType string, currentlyRunning bool) (ctx context.Context, cancel context.CancelFunc, finished FinishedFunc)

AddTypedContext creates a new context and adds it as a process. Once the process is finished, finished must be called to remove the process from the process table. It should not be called until the process is finished but must always be called.

cancel should be used to cancel the returned context, however it will not remove the process from the process table. finished will cancel the returned context and remove it from the process table.

Most processes will not need to use the cancel function but there will be cases whereby you want to cancel the process but not immediately remove it from the process table.

func (*Manager) Cancel added in v1.11.0

func (pm *Manager) Cancel(pid IDType)

Cancel a process in the ProcessManager.

func (*Manager) Exec added in v1.1.0

func (pm *Manager) Exec(desc, cmdName string, args ...string) (string, string, error)

Exec a command and use the default timeout.

func (*Manager) ExecDir added in v1.1.0

func (pm *Manager) ExecDir(ctx context.Context, timeout time.Duration, dir, desc, cmdName string, args ...string) (string, string, error)

ExecDir a command and use the default timeout.

func (*Manager) ExecDirEnv added in v1.1.0

func (pm *Manager) ExecDirEnv(ctx context.Context, timeout time.Duration, dir, desc string, env []string, cmdName string, args ...string) (string, string, error)

ExecDirEnv runs a command in given path and environment variables, and waits for its completion up to the given timeout (or DefaultTimeout if -1 is given). Returns its complete stdout and stderr outputs and an error, if any (including timeout)

func (*Manager) ExecDirEnvStdIn added in v1.9.5

func (pm *Manager) ExecDirEnvStdIn(ctx context.Context, timeout time.Duration, dir, desc string, env []string, stdIn io.Reader, cmdName string, args ...string) (string, string, error)

ExecDirEnvStdIn runs a command in given path and environment variables with provided stdIN, and waits for its completion up to the given timeout (or DefaultTimeout if timeout <= 0 is given). Returns its complete stdout and stderr outputs and an error, if any (including timeout)

func (*Manager) ExecTimeout added in v1.1.0

func (pm *Manager) ExecTimeout(timeout time.Duration, desc, cmdName string, args ...string) (string, string, error)

ExecTimeout a command and use a specific timeout duration.

func (*Manager) ProcessStacktraces added in v1.17.0

func (pm *Manager) ProcessStacktraces(flat, noSystem bool) ([]*Process, int, int64, error)

ProcessStacktraces gets the processes and stacktraces in a thread safe manner

func (*Manager) Processes added in v1.1.0

func (pm *Manager) Processes(flat, noSystem bool) ([]*Process, int)

Processes gets the processes in a thread safe manner

func (*Manager) Remove added in v1.1.0

func (pm *Manager) Remove(pid IDType)

Remove a process from the ProcessManager.

type Process

type Process struct {
	PID         IDType
	ParentPID   IDType
	Description string
	Start       time.Time
	Type        string

	Children []*Process `json:",omitempty"`
	Stacks   []*Stack   `json:",omitempty"`
}

A Process is a combined representation of a Process and a Stacktrace for the goroutines associated with it

type Stack added in v1.17.0

type Stack struct {
	Count       int64 // Number of goroutines with this stack trace
	Description string
	Labels      []*Label      `json:",omitempty"`
	Entry       []*StackEntry `json:",omitempty"`
}

Stack is a stacktrace relating to a goroutine. (Multiple goroutines may have the same stacktrace)

type StackEntry added in v1.17.0

type StackEntry struct {
	Function string
	File     string
	Line     int
}

StackEntry is an entry on a stacktrace

Jump to

Keyboard shortcuts

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