/tools/cmd/am-vis/README.md
am-vis
am-vis renders diagrams from dbg telemetry by creating a graph of interconnected
state machines. The graph is based on fragmented data they provide via:
- state schema
- states
- relations
- tags
LogOps(level3)- pipes
- RPC connections
- transitions
- active states
The rendering uses ELK (Eclipse Layout Kernel) and is done by D2
(embedded). At the moment it can render from file dumps and YAML schemas, with the live-server version is yet to come.
Installation
go install github.com/pancsta/asyncmachine-go/tools/cmd/am-vis@latest
go run github.com/pancsta/asyncmachine-go/tools/cmd/am-vis@latest
Features
$ am-vis render-dump --help
Render diagrams of interconnected state machines.
Examples:
# single machine
am-vis render-dump mymach.gob.br mach://MyMach1/t234
# bird's view with distance of 2 from MyMach1
am-vis --bird -d 2 \
render-dump mymach.gob.br mach://MyMach1/TX-ID
# bird's view with grouped pipes
am-vis --bird --render-pipes --render-detailed-pipes=false \
render-dump mymach.gob.br mach://MyMach1/TX-ID
# map view with inherited states
am-vis --render-inherited \
render-dump mymach.gob.br mach://MyMach1/t234
# map view
am-vis --map render-dump mymach.gob.br
# TALA layout for the D2 output
am-vis --output-d2 tala render-dump mymach.gob.br mach://MyMach1/t234
# inspect a dump file as Markdown and XML
am-vis inspect-dump mymach.gob.br
# render a YAML schema
am-vis render-schema schema.yml
Usage: am-vis [--render-distance RENDER-DISTANCE] [--render-depth RENDER-DEPTH] [--render-start] [--render-ready] [--render-exception] [--render-states] [--render-inherited] [--render-pipes] [--render-detailed-pipes] [--render-relations] [--render-conns] [--render-parent-rel] [--render-half-conns] [--render-half-pipes] [--render-nest-submachines] [--render-tags] [--bird] [--map] [--output-png] [--output-d2 tala|none|elk|dagre] [--output-filename OUTPUT-FILENAME] [--debug] [--version] <command> [<args>]
Options:
--render-distance RENDER-DISTANCE, -d RENDER-DISTANCE [default: 0]
--render-depth RENDER-DEPTH [default: 0]
--render-start [default: false]
--render-ready [default: false]
--render-exception [default: false]
--render-states [default: true]
--render-inherited [default: true]
--render-pipes [default: false]
--render-detailed-pipes [default: true]
--render-relations [default: true]
--render-conns [default: true]
--render-parent-rel [default: true]
--render-half-conns [default: true]
--render-half-pipes [default: true]
--render-nest-submachines [default: false]
--render-tags [default: false]
--bird, -b Use the bird's view preset
--map, -b Use the map view preset
--output-png Output also PNG
--output-d2 tala|none|elk|dagre
D2 layout engine (tala, none, elk, dagre) [default: elk]
--output-filename OUTPUT-FILENAME, -o OUTPUT-FILENAME [default: am-vis]
--debug Enable debugging for asyncmachine
--version, -v Print version and exit
--help, -h display this help and exit
Commands:
render-dump Render from a debugger dump file
render-schema Render from a YAML schema file
inspect-dump Render text form from a debugger dump file
Graphs can be programmatically filtered using the rendering config:
type Renderer struct {
// Render only these machines as starting points.
RenderMachs []string
// Render only machines matching the regular expressions as starting points.
RenderMachsRe []*regexp.Regexp
// Skip rendering of these machines.
RenderSkipMachs []string
// Distance to render from starting machines.
RenderDistance int
// How deep to render from starting machines. Same as RenderDistance, but only
// for submachines.
RenderDepth int
// Render states bubbles.
RenderStates bool
// With RenderStates, false will hide Start, and without RenderStates true
// will render Start.
RenderStart bool
// With RenderStates, false will hide Exception, and without RenderStates true
// will render Exception.
RenderException bool
// With RenderStates, false will hide Ready, and without RenderStates true
// will render Ready.
RenderReady bool
// Render states which have pipes being rendered, even if the state should
// not be rendered.
RenderPipeStates bool
// Render group of pipes as mach->mach
RenderPipes bool
// Render pipes to non-rendered machines / states.
RenderHalfPipes bool
// Render detailed pipes as state -> state
RenderDetailedPipes bool
// Render relation between states.
RenderRelations bool
// Style currently active states.
RenderActive bool
// Render the parent relation. Ignored when RenderNestSubmachines.
RenderParentRel bool
// Render submachines nested inside their parents. See also RenderDepth.
RenderNestSubmachines bool
// Render a tags box for machines having some.
RenderTags bool
// Render RPC connections
RenderConns bool
// Render RPC connections to non-rendered machines.
RenderHalfConns bool
// Render a parent relation to and from non-rendered machines.
RenderHalfHierarchy bool
// Render inherited states.
RenderInherited bool
// Mark inherited states.
RenderMarkInherited bool
}
TODO
- rendering from live connections
- browser viewer with auto-reload
- add a TUI version of the rendering config
- use D2 API instead of gluing strings
- support GC, store machine time for enter / exit
- add G6 renderer for large graphs
Legend
- yellow border = machine requested by ID
- white border = machine close or deep enough from a requested one
- no border = not fully rendered machine for grouped inbound and outbound edges
- yellow state = active
- double border state = own / non-inherited state
- blue state = Ready active
- green state = Start active
Gallery
It’s recommended to view the SVGs using SVG Navigator or imv.
Transition Sequence
Transitions can be plotted as sequence diagrams and rendered to SVG and ASCII. Currently am-dbg
does it automatically with --output-tx and places files inside --dir. Support in am-vis CLI coming soon.
This is the same steps diagram as the second timeline of am-dbg and includes:
- all called and touched states
- called steps
- relation steps
- handler calls
- cancellations
┌────────────────┐ ┌───────┐ ┌───────┐
│ ReplaceStories │ │ Start │ │ Ready │
└────────┬───────┘ └───┬───┘ └───┬───┘
│ │ │
│ called │ │
├──┐ │ │
│ │ │ │
│◄─┘ │ │
│ │ │
│ activate │ │
├──┐ │ │
│ │ │ │
│◄─┘ │ │
│ │ │
│ │ require │
│ │◄────────────┤
│ │ │
│ │ require │
│ │◄────────────┤
│ │ │
│ ReplaceStoriesState │
├──┐ │ │
│ │ │ │
│◄─┘ │ │
│ │ │
Graphs as Markdown
The am-vis inspect-dump command outputs a Markdown form of the graph, for easier processing.
See machine schema and relations
-----
## rc-srv-browser2
Parent: orchestrator
### States
- CallRetryFailed
- ConnRetryFailed
- Connected
- Connecting
- Disconnected
- Disconnecting
- ErrConnecting
- ErrDelivery
- ErrHandlerTimeout
- ErrNetwork
- ErrNetworkTimeout
- ErrOnClient
- ErrRpc
- Exception
- HandshakeDone
- Handshaking
- Healthcheck
- Heartbeat
- MetricSync
- Ready
- RetryingCall
- RetryingConn
- ServerDelivering
- ServerPayload
- Start
### RPC
- rs-browser2
### Pipes
#### orchestrator
- [add] Exception -> ErrRpc
- [add] Ready -> Browser2Conn
- [remove] Exception -> ErrRpc
- [remove] Ready -> Browser2Conn
-----
Credits
monorepo
Go back to the monorepo root to continue reading.
