Skip to content

Commit

Permalink
feat(debugger): Make header of sequence diagram always be shown
Browse files Browse the repository at this point in the history
The boxes above each line for the reactor is now always on top so that it is
easier to track what reactor is sending to whom.
  • Loading branch information
symbiont-daniel-gustafsson committed Apr 7, 2021
1 parent 9244b7f commit d2d349e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
18 changes: 16 additions & 2 deletions src/debugger/cmd/detsys-debug/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ var diagram = tview.NewTextView().
Highlight("focused")
var w2 = tview.ANSIWriter(diagram)

var diagramHeader = tview.NewTextView().
SetWrap(false).
SetDynamicColors(true)
var wDiagramHeader = tview.ANSIWriter(diagramHeader)

var reactorsWidget = tview.NewList()

var messageView = tview.NewTextView().
Expand Down Expand Up @@ -78,12 +83,14 @@ func (da *DebugApplication) setRow(row int) {
func (da *DebugApplication) redraw() {
textView.Clear()
diagram.Clear()
diagramHeader.Clear()
messageView.Clear()
logView.Clear()
row := da.activeRow
{
fmt.Fprintf(w2, "%s", da.diagrams.At(row-1))
diagram.ScrollToHighlight()
fmt.Fprintf(wDiagramHeader, "%s", da.diagrams.Header())
}
reactor := da.reactors[da.activeReactor]
old := da.heaps[row-1][reactor]
Expand Down Expand Up @@ -166,9 +173,16 @@ func main() {
da := MakeDebugApplication(lib.TestId{testId}, lib.RunId{runId})

messageView.SetBorderPadding(1, 1, 2, 0).SetBorder(true).SetTitle("Current Message")
diagram.SetBorderPadding(1, 1, 2, 0).SetBorder(true).SetTitle("Sequence Diagram")
logView.SetBorderPadding(1, 1, 2, 0).SetBorder(true).SetTitle("Reactor Log")

diagramWidget := tview.NewFlex().
SetDirection(tview.FlexRow).
AddItem(diagramHeader, 3, 0, false).
AddItem(diagram, 0, 1, false)
diagramWidget.
SetBorder(true).
SetTitle("Sequence Diagram")

da.redraw()

table := tview.NewTable().
Expand Down Expand Up @@ -245,7 +259,7 @@ func main() {
SetDirection(tview.FlexRow).
AddItem(stateWidget, 0, 1, false).
AddItem(table, 20, 1, false), 0, 1, false).
AddItem(diagram, 0, 1, false), 0, 20, false).
AddItem(diagramWidget, 0, 1, false), 0, 20, false).
AddItem(messageView, 5, 1, false).
AddItem(logView, 10, 1, false)

Expand Down
15 changes: 12 additions & 3 deletions src/debugger/internal/debugger.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,9 @@ func colon(s string) string {
}

type SequenceDiagrams struct {
inner map[int][]byte
net []NetworkEvent
inner map[int][]byte
header []byte
net []NetworkEvent
}

func NewSequenceDiagrams(testId lib.TestId, runId lib.RunId) *SequenceDiagrams {
Expand All @@ -224,15 +225,23 @@ func (s *SequenceDiagrams) At(at int) []byte {
Dropped: event.Dropped,
})
}
gen := DrawDiagram(arrows, DrawSettings{
header, gen := DrawDiagram(arrows, DrawSettings{
MarkerSize: 3,
MarkAt: at,
})

if s.header == nil {
s.header = header
}

s.inner[at] = gen
return gen
}

func (s *SequenceDiagrams) Header() []byte {
return s.header
}

func GetLogMessages(testId lib.TestId, runId lib.RunId, reactor string, at int) [][]byte {
db := lib.OpenDB()
defer db.Close()
Expand Down
11 changes: 6 additions & 5 deletions src/debugger/internal/sequence.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ func appendBoxes(isTop bool, output *strings.Builder, names []string, gaps []int
WriteRepeat(output, hLine, halfPoint)
output.WriteString("╯")
}
output.WriteString("\n")
}
}

Expand Down Expand Up @@ -271,13 +270,14 @@ func appendArrows(output *strings.Builder, names []string, arrows []arrowInterna
}
}

func drawDiagram(names []string, arrows []arrowInternal, gaps []int, nrLoops int) []byte {
func drawDiagram(names []string, arrows []arrowInternal, gaps []int, nrLoops int) ([]byte, []byte) {
if len(names) < 1 {
panic("We need at least one box")
}

boxSize := boxSize(names)

var header strings.Builder
var output strings.Builder
var expectedSize int
{
Expand All @@ -291,12 +291,13 @@ func drawDiagram(names []string, arrows []arrowInternal, gaps []int, nrLoops int
}
output.Grow(expectedSize)

appendBoxes(true, &output, names, gaps)
appendBoxes(true, &header, names, gaps)

appendArrows(&output, names, arrows, gaps, boxSize)
appendBoxes(false, &output, names, gaps)

// remove last newline
return []byte(output.String()[:output.Len()-1])
return []byte(header.String()), []byte(output.String())
}

func index(haystack []string, needle string) int {
Expand All @@ -313,7 +314,7 @@ type DrawSettings struct {
MarkAt int
}

func DrawDiagram(arrows []Arrow, settings DrawSettings) []byte {
func DrawDiagram(arrows []Arrow, settings DrawSettings) ([]byte, []byte) {
var names []string
{
for _, arr := range arrows {
Expand Down
8 changes: 5 additions & 3 deletions src/debugger/internal/sequence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import (

func goldenTest(t *testing.T, settings DrawSettings, arrows []Arrow, outcome string) {
shouldBe := strings.TrimSpace(outcome)
boxes := string(DrawDiagram(arrows, settings))
header, boxes := DrawDiagram(arrows, settings)

whole := strings.Join([]string{string(header), string(boxes)}, "\n")

//sanitize, boxes might have some extra spaces at the end..
boxesLines := strings.Split(boxes, "\n")
boxesLines := strings.Split(whole, "\n")
for i, s := range boxesLines {
boxesLines[i] = strings.TrimRight(s, " ")
}
Expand Down Expand Up @@ -110,7 +112,7 @@ func benchmarkSequence(many int, b *testing.B) {
// away
var r []byte
for i := 0; i < b.N; i++ {
r = DrawDiagram(arrows, settings)
_, r = DrawDiagram(arrows, settings)
}
result = r
}
Expand Down

0 comments on commit d2d349e

Please sign in to comment.