vm

package
v0.0.0-...-5655933 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package vm provides a virtual machine environment for executing mtail bytecode.

Index

Constants

This section is empty.

Variables

View Source
var (
	ProgRuntimeErrors = expvar.NewMap("prog_runtime_errors_total")

	LineProcessingDurations = prometheus.NewHistogramVec(prometheus.HistogramOpts{
		Namespace: "mtail",
		Subsystem: "vm",
		Name:      "line_processing_duration_seconds",
		Help:      "VM line processing time distribution in seconds.",
		Buckets:   prometheus.ExponentialBuckets(0.00002, 2.0, 10),
	}, []string{"prog"})
)

Functions

This section is empty.

Types

type VM

type VM struct {
	Metrics []*metrics.Metric // Metrics accessible to this program.

	HardCrash bool // User settable flag to make the VM crash instead of recover on panic.
	// 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 New

func New(name string, obj *code.Object, syslogUseCurrentYear bool, loc *time.Location, log bool, trace bool) *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() 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) ProcessLogLine

func (v *VM) ProcessLogLine(ctx context.Context, line *logline.LogLine)

ProcessLogLine handles the incoming lines by running a fetch-execute cycle on the VM bytecode with the line as input to the program, until termination.

func (*VM) Run

func (v *VM) Run(lines <-chan *logline.LogLine, wg *sync.WaitGroup)

Run starts the VM and processes lines coming in on the input channel. When the channel is closed, and the VM has finished processing the VM is shut down and the loader signalled via the given waitgroup.

func (*VM) RuntimeErrorString

func (v *VM) RuntimeErrorString() string

RuntimeErrorString returns the last runtime erro rthat the program enountered.

Jump to

Keyboard shortcuts

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