// 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) { , := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) defer () // print the version := utils.GetVersion() if .Version { println() os.Exit(0) } // logger and profiler := types.GetLogger(&, .OutputDir) types.StartCpuProfileSrv(, , &) := types.StartCpuProfile(, &) if != nil { defer () } log.SetOutput(.Writer()) := "" := "" if .ListenAddr != "-1" { , , := net.SplitHostPort(.ListenAddr) if != nil { panic() } , := strconv.Atoi() := + 1 := + 1 = + ":" + strconv.Itoa() = + ":" + strconv.Itoa() } if !.UiSsh { = "" } if !.UiWeb { = "" } // init the debugger , := debugger.New(, debugger.Opts{ Id: .Id, DbgLogLevel: .LogLevel, DbgLogger: , ImportData: .ImportData, OutputClients: .OutputClients, // TODO expose levels as states OutputDiagrams: .OutputDiagrams, OutputTx: .OutputTx, OutputLog: .OutputLog, Timelines: .ViewTimelines, // ...: p.FilterLogLevel, OutputDir: .OutputDir, AddrRpc: .ListenAddr, AddrHttp: , AddrSsh: , UiSsh: .UiSsh && != "", UiWeb: .UiWeb && != "", EnableMouse: .EnableMouse, EnableClipboard: .EnableClipboard, MachUrl: .MachUrl, SelectConnected: .SelectConnected, ShowReader: .ViewReader, 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.SemConfigEnv(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, ) } // start and wait till the end // TODO move to params .Start(.StartupMachine, .StartupTx, .StartupView, .StartupGroup) select { case <-.Mach.WhenDisposed(): case <-.Mach.WhenNot1(ss.Start, nil): } // show footer stats printStats() // 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) }