package debugger
import (
"log"
"sync"
"time"
"github.com/gdamore/tcell/v2"
"github.com/pancsta/cview"
"github.com/pancsta/asyncmachine-go/tools/debugger/server"
"github.com/pancsta/asyncmachine-go/tools/debugger/types"
am "github.com/pancsta/asyncmachine-go/pkg/machine"
)
const (
colorActive = tcell .ColorOlive
colorActive2 = tcell .ColorGreenYellow
colorInactive = tcell .ColorLimeGreen
colorHighlight = tcell .ColorDarkSlateGray
colorHighlight2 = tcell .ColorDimGray
colorHighlight3 = tcell .Color233
colorErr = tcell .ColorRed
playInterval = 500 * time .Millisecond
maxClients = 5000
timeFormat = "15:04:05.000000000"
fastJumpAmount = 50
arrowThrottleMs = 200
logUpdateDebounce = 300 * time .Millisecond
sidebarUpdateDebounce = time .Second
searchAsTypeWindow = 1500 * time .Millisecond
heartbeatInterval = 1 * time .Minute
maxMemMb = 50
msgMaxThreshold = 300
scrollTxThrottle = 3
)
var colorDefault = cview .Styles .PrimaryTextColor
const (
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"
ToolLogTimestamps ToolName = "hide-timestamps"
ToolFilterTraces ToolName = "hide-traces"
toolLog ToolName = "log"
toolDiagrams ToolName = "diagrams"
toolTimelines ToolName = "timelines"
toolReader ToolName = "reader"
toolRain ToolName = "rain"
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"
)
type Opts struct {
MachUrl string
SelectConnected bool
CleanOnConnect bool
EnableMouse bool
ShowReader bool
AddrRpc string
AddrHttp string
DbgLogLevel am .LogLevel
DbgRace bool
DbgLogger *log .Logger
Filters *OptsFilters
Timelines int
ImportData string
OutputClients bool
OutputDir string
OutputDiagrams int
Screen tcell .Screen
Id string
Version string
MaxMemMb int
Log2Ttl time .Duration
ViewNarrow bool
ViewRain bool
TailMode bool
OutputTx bool
EnableClipboard bool
}
type OptsFilters struct {
SkipCanceledTx bool
SkipAutoTx bool
SkipAutoCanceledTx bool
SkipEmptyTx bool
SkipHealthTx bool
SkipQueuedTx bool
SkipOutGroup bool
SkipChecks bool
LogLevel am .LogLevel
}
func (f *OptsFilters ) Equal (filters *OptsFilters ) bool {
if filters == nil {
return false
}
return f .SkipCanceledTx == filters .SkipCanceledTx &&
f .SkipAutoTx == filters .SkipAutoTx &&
f .SkipAutoCanceledTx == filters .SkipAutoCanceledTx &&
f .SkipEmptyTx == filters .SkipEmptyTx &&
f .SkipHealthTx == filters .SkipHealthTx &&
f .SkipQueuedTx == filters .SkipQueuedTx &&
f .SkipOutGroup == filters .SkipOutGroup &&
f .SkipChecks == filters .SkipChecks &&
f .LogLevel == filters .LogLevel
}
type ToolName string
type Client struct {
*server .Client
CursorTx1 int
ReaderCollapsed bool
CursorStep1 int
SelectedState string
SelectedReaderEntry *types .LogReaderEntryPtr
LogReader map [string ][]*types .LogReaderEntry
logRenderedCursor1 int
logRenderedLevel am .LogLevel
logRenderedFilters *OptsFilters
logRenderedTimestamps bool
logReaderMx sync .Mutex
}
func newClient(id , connId , schemaHash string , data *server .Exportable ) *Client {
c := &Client {
Client : &server .Client {
Id : id ,
ConnId : connId ,
SchemaHash : schemaHash ,
Exportable : data ,
},
LogReader : make (map [string ][]*types .LogReaderEntry ),
}
c .ParseSchema ()
return c
}
func (c *Client ) AddReaderEntry (txId string , entry *types .LogReaderEntry ) int {
c .logReaderMx .Lock ()
defer c .logReaderMx .Unlock ()
c .LogReader [txId ] = append (c .LogReader [txId ], entry )
return len (c .LogReader [txId ]) - 1
}
func (c *Client ) GetReaderEntry (txId string , idx int ) *types .LogReaderEntry {
c .logReaderMx .Lock ()
defer c .logReaderMx .Unlock ()
ptrTx , ok := c .LogReader [txId ]
if !ok || idx >= len (ptrTx ) {
return nil
}
return ptrTx [idx ]
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .