status

package
v1.7.0-dev-20190926 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2019 License: Apache-2.0 Imports: 13 Imported by: 121

Documentation

Overview

Package status provides methods for reporting application status.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Block added in v1.3.1

func Block(ctx context.Context)

Block marks the current task as blocked

func Do

func Do(ctx context.Context, name string, block func(context.Context))

Do is a convenience function for calling block between Start() and Finish().

func Event

func Event(ctx context.Context, scope EventScope, name string, args ...interface{})

Event causes an event to be recorded. If EventScope == Task then the the currently executing task will get the scope

func Finish

func Finish(ctx context.Context)

Finish marks the task started with Start() as finished.

func MemorySnapshot

func MemorySnapshot() runtime.MemStats

MemorySnapshot returns the memory statistics sampled from the last call to SnapshotMemory().

func PutTask

func PutTask(ctx context.Context, t *Task) context.Context

PutTask attaches a task to a Context.

func SnapshotMemory

func SnapshotMemory(ctx context.Context)

SnapshotMemory takes a snapshot of the current process's memory.

func Start

func Start(ctx context.Context, name string, args ...interface{}) context.Context

Start returns a new context for a long running task. End() must be called with the returned context once the task has been finished.

func StartBackground added in v1.3.1

func StartBackground(ctx context.Context, name string, args ...interface{}) context.Context

StartBackground returns a new context for a long running background task. End() must be called with the returned context once the task has been finished.

func Unblock added in v1.3.1

func Unblock(ctx context.Context)

Block marks the current task as blocked

func UpdateProgress

func UpdateProgress(ctx context.Context, n, outof uint64)

UpdateProgress updates the progress of the task started with Start(). n is the number of units of completion, which ranges from [0, outof).

Types

type EventScope

type EventScope int

EventScope defines the scope for a particular event

const (
	// TaskScope is an event that applies to the current task
	TaskScope EventScope = iota
	// ProcessScope is an event that only applies to this process
	ProcessScope
	// GlobalScope is an event that applies globally
	GlobalScope
)

func (EventScope) String

func (s EventScope) String() string

type Listener

type Listener interface {
	OnTaskStart(context.Context, *Task)
	OnTaskProgress(context.Context, *Task)
	OnTaskFinish(context.Context, *Task)
	OnEvent(context.Context, *Task, string, EventScope)
	OnMemorySnapshot(context.Context, runtime.MemStats)
	OnTaskBlock(context.Context, *Task)
	OnTaskUnblock(context.Context, *Task)
	OnReplayStatusUpdate(context.Context, *Replay, uint64, uint32, uint32)
}

Listener is the interface implemented by types that want to listen to application status messages.

type Replay

type Replay struct {
	ID     uint32
	Device id.ID
	// contains filtered or unexported fields
}

Replay contains status information about a replay.

func ReplayQueued

func ReplayQueued(ctx context.Context, id uint32, device id.ID) *Replay

ReplayQueued notifies listeners that a new replay has been queued.

func (*Replay) Finish

func (r *Replay) Finish(ctx context.Context)

Finish notifies listeners that a replay has finished.

func (*Replay) Finished

func (r *Replay) Finished() bool

Finished returns wether a replay has finished.

func (*Replay) Progress

func (r *Replay) Progress(ctx context.Context, label uint64, totalInstrs, finishedInstrs uint32)

Progress notifies listeners of progress on a currently running replay.

func (*Replay) Start

func (r *Replay) Start(ctx context.Context)

Start notifies listeners that a replay has started.

func (*Replay) Started

func (r *Replay) Started() bool

Started returns wether a replay has started.

type Task

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

Task represents a long running job which should be reported as part of the application's status.

func GetTask

func GetTask(ctx context.Context) *Task

GetTask retrieves the task from a context previously annotated by PutTask.

func Tasks

func Tasks() []*Task

Tasks returns the currently running tasks.

func (*Task) Background added in v1.3.1

func (t *Task) Background() bool

func (*Task) Completion

func (t *Task) Completion() int

Completion returns the task's completion as a percentage.

func (*Task) ID

func (t *Task) ID() uint64

ID returns the task's unique identifier.

func (*Task) Name

func (t *Task) Name() string

Name returns the task's name.

func (*Task) ParentID added in v1.3.1

func (t *Task) ParentID() uint64

ParentID returns the ID of the parent task, or 0 if there is no parent

func (*Task) String

func (t *Task) String() string

func (*Task) SubTasks

func (t *Task) SubTasks() []*Task

SubTasks returns all the sub-tasks of this task.

func (*Task) TimeSinceStart

func (t *Task) TimeSinceStart() time.Duration

TimeSinceStart returns the time the task was started.

func (*Task) Traverse

func (t *Task) Traverse(cb func(*Task))

Traverse calls cb for all descendant tasks.

type Unregister

type Unregister func()

Unregister is the function returned by RegisterListener and is used to unregister the listenenr.

func RegisterListener

func RegisterListener(l Listener) Unregister

RegisterListener registers l for status updates

func RegisterLogger

func RegisterLogger(progressUpdateFreq time.Duration) Unregister

RegisterLogger registers a status listener that logs the updates to the logger bound to the context. Task completion updates will only be logged at the given frequency.

func RegisterTracer

func RegisterTracer(w io.Writer) Unregister

RegisterTracer registers a status listener that writes all status updates in the Chrome Trace Event Format to the writer w. See https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU for documentation on the trace event format.

Jump to

Keyboard shortcuts

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