vm

package
v0.0.0-...-93548a8 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2020 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Overview

Package vm provides a compiler and virtual machine environment for executing mtail programs.

Index

Constants

This section is empty.

Variables

View Source
var (
	// LineCount counts the number of lines read by the program loader from the input channel.
	LineCount = expvar.NewInt("line_count")
	// ProgLoads counts the number of program load events.
	ProgLoads = expvar.NewMap("prog_loads_total")
	// ProgLoadErrors counts the number of program load errors.
	ProgLoadErrors = expvar.NewMap("prog_load_errors")
)

Functions

func CompileOnly

func CompileOnly(l *Loader) error

CompileOnly sets the Loader to compile programs only, without executing them.

func DumpAst

func DumpAst(l *Loader) error

DumpAst instructs the Loader to print the AST after program compilation.

func DumpAstTypes

func DumpAstTypes(l *Loader) error

DumpAstTypes instructs the Loader to print the AST after type checking.

func DumpBytecode

func DumpBytecode(l *Loader) error

DumpBytecode instructs the loader to print the compiled bytecode after code generation.

func ErrorsAbort

func ErrorsAbort(l *Loader) error

ErrorsAbort sets the Loader to abort the Loader on compile errors.

func OmitMetricSource

func OmitMetricSource(l *Loader) error

OmitMetricSource instructs the Loader to not annotate metrics with their program source when added to the metric store.

func OverrideLocation

func OverrideLocation(loc *time.Location) func(*Loader) error

OverrideLocation sets the timezone location for the VM.

func PrometheusRegisterer

func PrometheusRegisterer(reg prometheus.Registerer) func(l *Loader) error

PrometheusRegisterer passes in a registry for setting up exported metrics.

func SyslogUseCurrentYear

func SyslogUseCurrentYear(l *Loader) error

SyslogUseCurrentYear instructs the VM to annotate yearless timestamps with the current year.

Types

type Loader

type Loader struct {
	VMsDone chan struct{} // Notify mtail when all running VMs are shutdown.
	// contains filtered or unexported fields
}

Loader handles the lifecycle of programs and virtual machines, by watching the configured program source directory, compiling changes to programs, and managing the running virtual machines that receive input from the lines channel.

func NewLoader

func NewLoader(programPath string, store *metrics.Store, lines <-chan *logline.LogLine, w watcher.Watcher, options ...func(*Loader) error) (*Loader, error)

NewLoader creates a new program loader that reads programs from programPath.

func (*Loader) CompileAndRun

func (l *Loader) CompileAndRun(name string, input io.Reader) error

CompileAndRun compiles a program read from the input, starting execution if it succeeds. If an existing virtual machine of the same name already exists, the previous virtual machine is terminated and the new loaded over it. If the new program fails to compile, any existing virtual machine with the same name remains running.

func (*Loader) LoadAllPrograms

func (l *Loader) LoadAllPrograms() error

LoadAllPrograms loads all programs in a directory and starts watching the directory for filesystem changes. Any compile errors are stored for later retrieival. This function returns an error if an internal error occurs.

func (*Loader) LoadProgram

func (l *Loader) LoadProgram(programPath string) error

LoadProgram loads or reloads a program from the full pathname programPath. The name of the program is the basename of the file.

func (*Loader) SetOption

func (l *Loader) SetOption(options ...func(*Loader) error) error

SetOption takes one or more option functions and applies them in order to Loader.

func (*Loader) UnloadProgram

func (l *Loader) UnloadProgram(pathname string)

UnloadProgram removes the named program from the watcher to prevent future updates, and terminates any currently running VM goroutine.

func (*Loader) WriteStatusHTML

func (l *Loader) WriteStatusHTML(w io.Writer) error

WriteStatusHTML writes the current state of the loader as HTML to the given writer w.

type VM

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

VM describes the virtual machine for each program. It contains virtual segments of the executable bytecode, constant data (string and regular expressions), mutable state (metrics), and a stack for the current thread of execution.

func Compile

func Compile(name string, input io.Reader, emitAst bool, emitAstTypes bool, syslogUseCurrentYear bool, loc *time.Location) (*VM, error)

Compile compiles a program from the input into a virtual machine or a list of compile errors. It takes the program's name and the metric store as additional arguments to build the virtual machine.

func New

func New(name string, obj *object.Object, syslogUseCurrentYear bool, loc *time.Location) *VM

New creates a new virtual machine with the given name, and compiler artifacts for executable and data segments.

func (*VM) DumpByteCode

func (v *VM) DumpByteCode(name string) string

DumpByteCode emits the program disassembly and program objects to a string.

func (*VM) ParseTime

func (v *VM) ParseTime(layout, value string) (tm time.Time)

ParseTime performs location and syslog-year aware timestamp parsing.

func (*VM) Run

func (v *VM) Run(_ uint32, lines <-chan *logline.LogLine, shutdown chan<- struct{}, started chan<- struct{})

Run executes the virtual machine on each line of input received. When the input closes, it signals to the loader that it has terminated by closing the shutdown channel.

Directories

Path Synopsis
Package code contains the bytecode instructions for the mtail virtual machine.
Package code contains the bytecode instructions for the mtail virtual machine.
Package parser implements the parse phase of the mtail program compilation.
Package parser implements the parse phase of the mtail program compilation.
Package position implements a data structure for storing source code positions.
Package position implements a data structure for storing source code positions.

Jump to

Keyboard shortcuts

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