// am-dbg is a lightweight, multi-client debugger for asyncmachine-go.
package main import ( amhelp ss ) func main() { := types.RootCmd(cliRun) := .Execute() if != nil { panic() } } // TODO error msgs func cliRun( *cobra.Command, []string, types.Params) { := context.Background() // print the version := utils.GetVersion() if .Version { println() os.Exit(0) } // logger and profiler := types.GetLogger(&, .OutputDir) types.StartCpuProfileSrv(, , &) := types.StartCpuProfile(, &) if != nil { defer () } := "" if .ListenAddr != "-1" { := strings.Split(.ListenAddr, ":") , := strconv.Atoi([1]) += 1 = [0] + ":" + strconv.Itoa() } // init the debugger , := debugger.New(, debugger.Opts{ Id: .Id, DbgLogLevel: .LogLevel, DbgLogger: , ImportData: .ImportData, OutputClients: .OutputClients, OutputDiagrams: .OutputDiagrams, Timelines: .Timelines, // ...: p.FilterLogLevel, OutputDir: .OutputDir, AddrRpc: .ListenAddr, AddrHttp: , EnableMouse: .EnableMouse, EnableClipboard: .EnableClipboard, MachUrl: .MachUrl, SelectConnected: .SelectConnected, ShowReader: .Reader, CleanOnConnect: .CleanOnConnect, MaxMemMb: .MaxMemMb, Log2Ttl: .LogOpsTtl, ViewNarrow: .ViewNarrow, ViewRain: .ViewRain, TailMode: .TailMode && .StartupTx == 0, Version: , Filters: &debugger.OptsFilters{ SkipOutGroup: .FilterGroup, LogLevel: .FilterLogLevel, }, }) if != nil { panic() } // rpc client if .DebugAddr != "" { amhelp.MachDebug(.Mach, .DebugAddr, .LogLevel, false, amhelp.SemConfig(true)) // TODO --otel flag // os.Setenv(telemetry.EnvService, "dbg") // os.Setenv(telemetry.EnvOtelTrace, "1") // os.Setenv(telemetry.EnvOtelTraceTxs, "1") // err = telemetry.MachBindOtelEnv(dbg.Mach) // if err != nil { // panic(err) // } } // rpc server if .ListenAddr != "-1" { go server.StartRpc(.Mach, .ListenAddr, nil, .FwdData, .UiDiagrams) } // start and wait till the end .Start(.StartupMachine, .StartupTx, .StartupView, .StartupGroup) := make(chan os.Signal, 1) signal.Notify(, os.Interrupt, syscall.SIGTERM) select { case <-.Mach.WhenDisposed(): case <-: case <-.Mach.WhenNot1(ss.Start, nil): } // show footer stats printStats() .Dispose() // pprof memory profile types.HandleProfMem(, &) } func printStats( *debugger.Debugger) { := 0 for , := range .Clients { += len(.MsgTxs) } _, _ = .P.Printf("Clients: %d\n", len(.Clients)) _, _ = .P.Printf("Transitions: %d\n", ) _, _ = .P.Printf("Memory: %dmb\n", debugger.AllocMem()/1024/1024) }