types

package
v0.18.8 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 22 Imported by: 1

Documentation

Index

Constants

View Source
const APrefix = "dbg"

Variables

View Source
var (
	ParamsOutputDiagramsNone  = ParamsOutputDiagrams{0}
	ParamsOutputDiagramsOne   = ParamsOutputDiagrams{1}
	ParamsOutputDiagramsTwo   = ParamsOutputDiagrams{2}
	ParamsOutputDiagramsThree = ParamsOutputDiagrams{3}

	ParamsOutputDiagramsEnum = enum.New(
		ParamsOutputDiagramsNone,
		ParamsOutputDiagramsOne,
		ParamsOutputDiagramsTwo,
		ParamsOutputDiagramsThree,
	)
)

0, 1, 2, 3

View Source
var (
	ParamsOutDiagTxNone      = ParamsOutDiagTx{""}
	ParamsOutDiagTxCalled    = ParamsOutDiagTx{"called"}
	ParamsOutDiagTxMutated   = ParamsOutDiagTx{"mutated"}
	ParamsOutDiagTxTouched   = ParamsOutDiagTx{"touched"}
	ParamsOutDiagTxRelations = ParamsOutDiagTx{"relations"}

	ParamsOutDiagTxEnum = enum.New(ParamsOutDiagTxNone, ParamsOutDiagTxCalled,
		ParamsOutDiagTxMutated, ParamsOutDiagTxTouched, ParamsOutDiagTxRelations)
)

"", "called", "changed", "touched"

View Source
var (
	ParamsOutDiagGroupNone = ParamsOutDiagGroup{""}
	ParamsOutDiagGroupHide = ParamsOutDiagGroup{"hide"}
	ParamsOutDiagGroupSkip = ParamsOutDiagGroup{"skip"}

	ParamsOutDiagGroupEnum = enum.New(ParamsOutDiagGroupNone,
		ParamsOutDiagGroupHide, ParamsOutDiagGroupSkip)
)

"", "hide", "skip"

View Source
var (
	ParamsViewTimelinesNone = ParamsViewTimelines{0}
	ParamsViewTimelinesOne  = ParamsViewTimelines{1}
	ParamsViewTimelinesTwo  = ParamsViewTimelines{2}

	ParamsViewTimelinesEnum = enum.New(
		ParamsViewTimelinesNone,
		ParamsViewTimelinesOne,
		ParamsViewTimelinesTwo,
	)
)

0, 1, 2

View Source
var (
	ToolFilterCanceledTx = ToolName{"skip-canceled"}
	ToolFilterQueuedTx   = ToolName{"skip-queued"}
	ToolFilterAutoTx     = ToolName{"skip-auto"}
	ToolFilterEmptyTx    = ToolName{"skip-empty"}
	ToolFilterHealth     = ToolName{"skip-health"}
	ToolFilterOutGroup   = ToolName{"skip-outgroup"}
	ToolFilterChecks     = ToolName{"skip-checks"}
	ToolFilterDisconn    = ToolName{"skip-disconn"}
	ToolLogTimestamps    = ToolName{"hide-timestamps"}
	ToolFilterTraces     = ToolName{"hide-traces"}
	ToolNarrowLayout     = ToolName{"narrow-layout"}
	ToolLog              = ToolName{"log"}
	ToolDiagrams         = ToolName{"diagrams"}
	ToolDiagramsTx       = ToolName{"diag-tx"}
	ToolDiagramsGroup    = ToolName{"diag-group"}
	ToolTimelines        = ToolName{"timelines"}
	ToolReader           = ToolName{"reader"}
	ToolRain             = ToolName{"rain"}
	ToolLogWrap          = ToolName{"log-wrap"}
	ToolWeb              = ToolName{"web"}
	ToolHelp             = ToolName{"help"}
	ToolPlay             = ToolName{"play"}
	ToolTail             = ToolName{"tail"}
	ToolPrev             = ToolName{"prev"}
	ToolNext             = ToolName{"next"}
	ToolJumpNext         = ToolName{"jump-next"}
	ToolJumpPrev         = ToolName{"jump-prev"}
	ToolFirst            = ToolName{"first"}
	ToolLast             = ToolName{"last"}
	ToolExpand           = ToolName{"expand"}
	ToolMatrix           = ToolName{"matrix"}
	ToolExport           = ToolName{"export"}
	ToolNextStep         = ToolName{"next-step"}
	ToolPrevStep         = ToolName{"prev-step"}

	ToolNames = enum.New(
		ToolFilterCanceledTx,
		ToolFilterQueuedTx,
		ToolFilterAutoTx,
		ToolFilterEmptyTx,
		ToolFilterHealth,
		ToolFilterOutGroup,
		ToolFilterChecks,
		ToolFilterDisconn,
		ToolLogTimestamps,
		ToolFilterTraces,
		ToolNarrowLayout,
		ToolLog,
		ToolDiagrams,
		ToolDiagramsTx,
		ToolDiagramsGroup,
		ToolTimelines,
		ToolReader,
		ToolRain,
		ToolLogWrap,
		ToolWeb,
		ToolHelp,
		ToolPlay,
		ToolTail,
		ToolPrev,
		ToolNext,
		ToolJumpNext,
		ToolJumpPrev,
		ToolFirst,
		ToolLast,
		ToolExpand,
		ToolMatrix,
		ToolExport,
		ToolNextStep,
		ToolPrevStep,
	)
)
View Source
var StateCalls = []am.CallSignature{
	{States: am.S{ss.StateNameSelected}, Needed: []string{"State"}},
	{States: am.S{ss.Redraw}, Args: []string{"Immediate"}},
	{States: am.S{ss.Fwd}, Args: []string{"Amount"}},
	{States: am.S{ss.Back}, Args: []string{"Amount"}},
	{States: am.S{ss.ConnectEvent}, Needed: []string{"MsgStruct", "ConnId"}},
	{States: am.S{ss.DisconnectEvent}, Needed: []string{"ConnId"}},
	{
		States: am.S{ss.ClientMsg},
		Needed: []string{"MsgsTx", "ConnIds"},
	},
	{
		States: am.S{ss.RemoveClient},
		Needed: []string{"ClientId"},
	},
	{
		States: am.S{ss.SetGroup},
		Needed: []string{"Group"},
	},
	{
		States: am.S{ss.SelectingClient},
		Needed: []string{"ClientId"},
		Args:   []string{"Group", "FromConnected"},
	},
	{
		States: am.S{ss.ClientSelected},
		Args:   []string{"Ctx", "FromConnected", "FromPlaying"},
	},
	{
		States: am.S{ss.ScrollToTx},
		Args:   []string{"CursorTx1", "TxId", "CursorStep1", "TrimHistory"},
	},
	{
		States: am.S{ss.ScrollToStep},
		Needed: []string{"CursorStep1"},
	},
	{
		States: am.S{ss.ToggleTool},
		Needed: []string{"ToolName"},
		Values: map[string][]string{
			"ToolName": ToolNames.Values(),
		},
	},
	{
		States: am.S{ss.ToolToggled},
		Args:   []string{"FilterTxs", "BuildClientList"},
	},
	{
		States: am.S{ss.SwitchingClientTx},
		Needed: []string{"ClientId", "CursorTx1"},
	},
	{
		States: am.S{ss.ScrollToMutTx},
		Needed: []string{"State"},
		Args:   []string{"Fwd"},
	},
	{
		States: am.S{ss.AfterFocus},
		Needed: []string{"FocusPrimitive"},
		Args:   []string{"MouseFocus"},
	},
	{
		States: am.S{ss.Resized},
		Args:   []string{"LogRebuildEnd"},
	},
	{
		States: am.S{ss.WebReq},
		Needed: []string{"HttpRequest", "HttpResponseWriter", "DoneChan"},
		Args:   []string{"Uri", "Addr"},
	},
	{
		States: am.S{ss.WebSocketDiag},
		Needed: []string{"WebSocketConn", "HttpRequest", "HttpResponseWriter",
			"DoneChan"},
		Args: []string{"Addr"},
	},
	{
		States: am.S{ss.MatrixRainSelected},
		Needed: []string{"Row", "Column", "CurrTxRow"},
	},
}

Functions

func GetLogger

func GetLogger(params *Params, dir string) *log.Logger

GetLogger returns a file logger, according to params.

func HandleProfMem

func HandleProfMem(logger *log.Logger, p *Params)

func LogArgs added in v0.18.8

func LogArgs(args am.A) map[string]string

LogArgs is an args logger for A.

func ParseRpc added in v0.18.8

func ParseRpc(args am.A) am.A

ParseRpc parses am.A to *ARpc namespaced in am.A. Useful for REPLs.

func Pass added in v0.18.8

func Pass(args *A) am.A

Pass prepares am.A from A to pass to further mutations.

func StartCpuProfile

func StartCpuProfile(logger *log.Logger, p *Params) func()

func StartCpuProfileSrv

func StartCpuProfileSrv(ctx context.Context, logger *log.Logger, p *Params)

Types

type A added in v0.18.8

type A struct {
	ClientId string `log:"client_id"`
	TxId     string `log:"tx_id"`
	ConnId   string `log:"conn_id"`
	ConnIds  []string

	Cursor1     int `log:"cursor1"`
	CursorStep1 int `log:"cursor_step1"`
	// TODO merge with Cursor1
	CursorTx1 int `log:"cursor_tx1"`

	Amount int  `log:"amount" json:",string"`
	Fwd    bool `log:"fwd" json:",string"`

	State string `log:"state"`
	Group string

	ToolName ToolName `log:"tool_name"`

	Id string `log:"id"`

	LogRebuildEnd int `json:",string"`
	LogBuffer     string
	LogLevel      am.LogLevel `json:",string"`

	SkipHistory bool
	TrimHistory bool
	FilterBack  bool

	FilterTxs       bool
	BuildClientList bool
	Immediate       bool
	FromConnected   bool
	FromPlaying     bool
	MouseFocus      bool

	Text string `log:"text"`
	Uri  string `log:"uri"`
	Addr string `log:"addr"`

	Row       int `json:",string"`
	Column    int `json:",string"`
	CurrTxRow int `json:",string"`

	// FocusPrimitive is the UI element receiving focus.
	FocusPrimitive cview.Primitive
	// DiagramCache is parsed HTML for diagram generation.
	DiagramCache *goquery.Document
	// DiagramName is the name of the diagram being generated.
	DiagramName string
	// HttpRequest is for web server route handlers.
	HttpRequest *http.Request
	// HttpResponseWriter is for web server route handlers.
	HttpResponseWriter http.ResponseWriter
	// DoneChan signals completion of a web handler.
	DoneChan chan struct{}
	// WebSocketConn is for WebSocket handlers.
	WebSocketConn *websocket.Conn
	// MsgStruct is the schema message from am-dbg protocol.
	MsgStruct *dbg.DbgMsgStruct
	// MsgsTx is a batch of transaction messages.
	MsgsTx []*dbg.DbgMsgTx
	// Ctx is a context passed into handlers.
	Ctx context.Context
}

A is a struct for debugger arguments. It's a typesafe alternative to am.A.

func ParseArgs added in v0.18.8

func ParseArgs(args am.A) *A

ParseArgs extracts A from am.Event.ArgsAPrefix.

type ARpc added in v0.18.8

type ARpc struct {
	ClientId string `log:"client_id"`
	TxId     string `log:"tx_id"`
	ConnId   string `log:"conn_id"`
	ConnIds  []string

	Cursor1     int `log:"cursor1"`
	CursorStep1 int `log:"cursor_step1"`
	// TODO merge with Cursor1
	CursorTx1 int `log:"cursor_tx1"`

	Amount int  `log:"amount" json:",string"`
	Fwd    bool `log:"fwd" json:",string"`

	State string `log:"state"`
	Group string

	ToolName ToolName `log:"tool_name"`

	Id string `log:"id"`

	LogRebuildEnd int `json:",string"`
	LogBuffer     string
	LogLevel      am.LogLevel `json:",string"`

	SkipHistory bool
	TrimHistory bool
	FilterBack  bool

	FilterTxs       bool
	BuildClientList bool
	Immediate       bool
	FromConnected   bool
	FromPlaying     bool
	MouseFocus      bool

	Text string `log:"text"`
	Uri  string `log:"uri"`
	Addr string `log:"addr"`

	Row       int `json:",string"`
	Column    int `json:",string"`
	CurrTxRow int `json:",string"`
}

ARpc is a subset of A, that can be passed over RPC.

type Filters added in v0.18.4

type Filters struct {
	SkipCanceledTx     bool
	SkipAutoTx         bool
	SkipAutoCanceledTx bool
	SkipEmptyTx        bool
	SkipHealthTx       bool
	SkipQueuedTx       bool
	SkipOutGroup       bool
	SkipChecks         bool
	LogLevel           am.LogLevel
}

Filters controls which transitions and log entries are shown.

func (*Filters) Equal added in v0.18.4

func (f *Filters) Equal(filters *Filters) bool

type LogReaderEntry

type LogReaderEntry struct {
	Kind LogReaderKind
	// states are empty for logReaderWhenQueue
	States []int
	// CreatedAt is machine time when this entry was created
	CreatedAt uint64
	// ClosedAt is human time when this entry was closed, so it can be disposed.
	ClosedAt time.Time

	// Pipe is for logReaderPipeIn, logReaderPipeOut
	Pipe am.MutationType
	// Mach is for logReaderPipeIn, logReaderPipeOut, logReaderMention
	Mach string
	// Ticks is for logReaderWhenTime only
	Ticks am.Time
	// Args is for logReaderWhenArgs only
	Args string
	// QueueTick is for logReaderWhenQueue only
	QueueTick int
}

type LogReaderEntryPtr

type LogReaderEntryPtr struct {
	TxId     string
	EntryIdx int
}

type LogReaderKind

type LogReaderKind int
const (
	LogReaderCtx LogReaderKind = iota + 1
	LogReaderWhen
	LogReaderWhenNot
	LogReaderWhenTime
	LogReaderWhenArgs
	LogReaderWhenQueue
	LogReaderPipeIn
	LogReaderPipeOut
)

type MachAddress

type MachAddress struct {
	MachId    string
	TxId      string
	MachTime  uint64
	HumanTime time.Time
	Step      int

	// TODO
	QueueTick uint64

	Group    string
	State    string
	Relation string
	RelState string
}

func ParseMachUrl

func ParseMachUrl(u string) (*MachAddress, error)

func (*MachAddress) Clone

func (a *MachAddress) Clone() *MachAddress

func (*MachAddress) String

func (a *MachAddress) String() string

type MachTime

type MachTime struct {
	Id   string
	Time uint64
}

type MsgSchemaParsed

type MsgSchemaParsed struct {
	Groups      map[string]am.S
	GroupsOrder []string
}

type MsgTxParsed

type MsgTxParsed struct {
	StatesAdded   []int
	StatesRemoved []int
	StatesTouched []int
	// TimeSum is machine time after this transition.
	TimeSum       uint64
	TimeDiff      uint64
	ReaderEntries []*LogReaderEntryPtr
	// Transitions which reported this one as their source
	Forks       []MachAddress
	ForksLabels []string
	// QueueTick when this tx should be executed
	ResultTick uint64
}

type Params

type Params struct {
	MachUrl string `arg:"positional" help:"Machine URL to connect to"`

	ListenAddr     string   `arg:"-l,--listen-addr" default:"localhost:6831" help:"Host and port for the debugger to listen on"`
	OutputDir      string   `arg:"-d,--dir" default:"." help:"Output directory for generated files"`
	CleanOnConnect bool     `arg:"--clean-on-connect" default:"true" help:"Clean up disconnected clients on the 1st connection"`
	ImportData     string   `arg:"-i,--import-data" help:"Import an exported gob.br file"`
	FwdData        []string `arg:"-f,--fwd-data,separate" help:"Forward incoming data to other instances (repeatable)"`

	SelectConnected bool   `arg:"-c,--select-connected" help:"Select the newly connected machine, if no other is connected"`
	SelectGroup     string `arg:"--select-group" help:"Default group to select"`

	EnableClipboard      bool        `arg:"--enable-clipboard" default:"true" help:"Enable clipboard support"`
	EnableMouse          bool        `arg:"--enable-mouse" default:"true" help:"Enable mouse support"`
	FilterAutoTx         bool        `arg:"--filter-auto" help:"Filter automatic transitions"`
	FilterAutoCanceledTx bool        `arg:"--filter-auto-canceled" help:"Filter automatic canceled transitions"`
	FilterCanceledTx     bool        `arg:"--filter-canceled" help:"Filter canceled transitions"`
	FilterChecks         bool        `arg:"--filter-checks" help:"Filter check (read-only) transitions"`
	FilterDisconn        bool        `arg:"--filter-disconn" help:"Filter disconnected clients"`
	FilterEmptyTx        bool        `arg:"--filter-empty" help:"Filter empty transitions"`
	FilterGroup          bool        `arg:"--filter-group" default:"true" help:"Filter transitions by a selected group"`
	FilterHealthTx       bool        `arg:"--filter-health" help:"Filter health-check transitions"`
	FilterLogLevel       am.LogLevel `arg:"--filter-log-level" default:"2" help:"Filter transitions up to this log level, 0-5 (silent-everything)"`
	FilterQueuedTx       bool        `arg:"--filter-queued" help:"Filter queued transitions"`

	OutputClients   bool                 `arg:"--output-clients" help:"Write a detailed client list into am-dbg-clients.txt inside --dir"`
	OutputDiagrams  ParamsOutputDiagrams `` /* 133-byte string literal not displayed */
	OutputDiagGroup ParamsOutDiagGroup   `arg:"--output-diag-group" help:"Only show states from the selected group (valid: hide, skip)" default:"hide"`
	OutputDiagTx    ParamsOutDiagTx      `` /* 140-byte string literal not displayed */
	OutputLog       bool                 `arg:"--output-log" help:"Write the current log buffer to log.txt inside --dir"`
	OutputTx        bool                 `` /* 139-byte string literal not displayed */

	UiSsh bool `arg:"--ui-ssh" help:"Enable SSH headless mode on port --listen-addr +2 (EXPERIMENTAL)"`
	UiWeb bool `arg:"--ui-web" default:"true" help:"Start a web server for --dir and diagrams on --listen-addr +1 (EXPERIMENTAL)"`

	PrintVersion  bool                `arg:"--version" help:"Print version and exit"`
	StartupView   string              `arg:"-v,--view" default:"tree-log" help:"Initial view (tree-log, tree-matrix, matrix)"`
	ViewLogWrap   bool                `arg:"--view-log-wrap" help:"Wrap log lines"`
	ViewNarrow    bool                `arg:"--view-narrow" help:"Force a narrow view, independently of the viewport size"`
	ViewRain      bool                `arg:"--view-rain" help:"Show the rain view"`
	ViewReader    bool                `arg:"-r,--view-reader" help:"Show the log reader view"`
	TailMode      bool                `arg:"--view-tail" default:"true" help:"Start from the latest tx"`
	ViewTheme     string              `arg:"--view-theme" default:"dark" help:"Color theme (dark, light)"`
	ViewTimelines ParamsViewTimelines `arg:"--view-timelines" default:"2" help:"Number of timelines to show (0-2)"`

	LogOpsTtl time.Duration `arg:"--log-ops-ttl" default:"24h" help:"Max time to live for logs level LogOps"`
	MaxMemMb  int           `arg:"--max-mem" default:"1000" help:"Max memory usage (in MB) to flush old transitions"`

	DebugAddr    string `arg:"--dbg-am-dbg-addr" help:"Debug this instance of am-dbg with another one"`
	RaceDetector bool   `arg:"--dbg-go-race" help:"Go race detector is enabled"`
	// Id is the ID of this asyncmachine (for debugging).
	Id string `arg:"--dbg-id" default:"am-dbg" help:"ID of this instance"`
	// LogLevel is the log level of this instance (for debugging).
	LogLevel am.LogLevel `arg:"--dbg-log-level" default:"0" help:"Log level produced by this instance, 0-5 (silent-everything)"`
	DbgOtel  bool        `arg:"--dbg-otel" help:"Enable OpenTelemetry tracing for this instance"`
	ProfSrv  string      `arg:"--dbg-prof-srv" help:"Start pprof server"`

	// AddrHttp is the computed HTTP server address (ListenAddr port+1).
	AddrHttp string `arg:"-"`
	// AddrRpc is the RPC listen address (same as ListenAddr).
	AddrRpc string `arg:"-"`
	// AddrSsh is the computed SSH server address (ListenAddr port+2).
	AddrSsh string `arg:"-"`
	// DbgLogger is the file logger for this instance.
	DbgLogger *log.Logger `arg:"-"`
	// Filters is the active set of transition filters.
	Filters *Filters `arg:"-"`
	// Print is the output function for status messages
	Print   func(txt string, args ...any) `arg:"-"`
	ProfCpu bool                          `arg:"-"`
	ProfMem bool                          `arg:"-"`
	// Screen is an optional tcell screen override (tests, SSH).
	Screen tcell.Screen `arg:"-"`
	// Version is the computed build version string.
	Version string `arg:"-"`
}

Params are CLI params for am-dbg, also used as internal state via Debugger.Params.

type ParamsOutDiagGroup added in v0.18.8

type ParamsOutDiagGroup enum.Member[string]

ParamsOutDiagGroup is an enum for --output-diagrams-group

func (*ParamsOutDiagGroup) UnmarshalText added in v0.18.8

func (p *ParamsOutDiagGroup) UnmarshalText(b []byte) error

type ParamsOutDiagTx added in v0.18.8

type ParamsOutDiagTx enum.Member[string]

ParamsOutDiagTx is an enum for --output-diagrams-group

func (*ParamsOutDiagTx) UnmarshalText added in v0.18.8

func (p *ParamsOutDiagTx) UnmarshalText(b []byte) error

type ParamsOutputDiagrams added in v0.18.8

type ParamsOutputDiagrams enum.Member[int]

ParamsOutputDiagrams is an enum for --output-diagrams

func (*ParamsOutputDiagrams) UnmarshalText added in v0.18.8

func (p *ParamsOutputDiagrams) UnmarshalText(b []byte) error

type ParamsViewTimelines added in v0.18.8

type ParamsViewTimelines enum.Member[int]

ParamsViewTimelines is an enum for --view-timelines

func (*ParamsViewTimelines) UnmarshalText added in v0.18.8

func (p *ParamsViewTimelines) UnmarshalText(b []byte) error

type ToolName added in v0.18.8

type ToolName enum.Member[string]

ToolName is a debugger's toolbar button.

Jump to

Keyboard shortcuts

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