Documentation ¶
Overview ¶
Package vm provides a compiler and virtual machine environment for executing mtail programs.
Index ¶
- Variables
- func CompileOnly(l *Loader) error
- func DumpAst(l *Loader) error
- func DumpAstTypes(l *Loader) error
- func DumpBytecode(l *Loader) error
- func ErrorsAbort(l *Loader) error
- func OmitMetricSource(l *Loader) error
- func OverrideLocation(loc *time.Location) func(*Loader) error
- func SyslogUseCurrentYear(l *Loader) error
- type Loader
- func (l *Loader) CompileAndRun(name string, input io.Reader) error
- func (l *Loader) LoadAllPrograms() error
- func (l *Loader) LoadProgram(programPath string) error
- func (l *Loader) SetOption(options ...func(*Loader) error) error
- func (l *Loader) UnloadProgram(pathname string)
- func (l *Loader) WriteStatusHTML(w io.Writer) error
- type VM
Constants ¶
This section is empty.
Variables ¶
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 ¶
CompileOnly sets the Loader to compile programs only, without executing them.
func DumpAstTypes ¶
DumpAstTypes instructs the Loader to print the AST after type checking.
func DumpBytecode ¶
DumpBytecode instructs the loader to print the compiled bytecode after code generation.
func ErrorsAbort ¶
ErrorsAbort sets the Loader to abort the Loader on compile errors.
func OmitMetricSource ¶
OmitMetricSource instructs the Loader to not annotate metrics with their program source when added to the metric store.
func OverrideLocation ¶
OverrideLocation sets the timezone location for the VM.
func SyslogUseCurrentYear ¶
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 ¶
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 ¶
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 ¶
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 ¶
SetOption takes one or more option functions and applies them in order to Loader.
func (*Loader) UnloadProgram ¶
UnloadProgram removes the named program from the watcher to prevent future updates, and terminates any currently running VM goroutine.
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 ¶
New creates a new virtual machine with the given name, and compiler artifacts for executable and data segments.
func (*VM) DumpByteCode ¶
DumpByteCode emits the program disassembly and program objects to a string.
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. |