From ffa09456af9674a4dd2645b2067e9c2c3e379df3 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Thu, 10 Aug 2023 21:21:43 -0400 Subject: Move display to virtual program Mostly to make it easier to debug the error spam, but it's nice that it's more consistent too --- virtual-programs/display.folk | 83 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 virtual-programs/display.folk (limited to 'virtual-programs/display.folk') diff --git a/virtual-programs/display.folk b/virtual-programs/display.folk new file mode 100644 index 00000000..ce7c0c2c --- /dev/null +++ b/virtual-programs/display.folk @@ -0,0 +1,83 @@ +if {$::isLaptop} return + +namespace eval Display { + variable WIDTH + variable HEIGHT + variable LAYER 0 + regexp {mode "(\d+)x(\d+)"} [exec fbset] -> WIDTH HEIGHT + + proc drawOnTop {func args} { + set Display::LAYER 1 + uplevel [list $func {*}$args] + set Display::LAYER 0 + } + + proc stroke {points width color} { + uplevel [list Wish display runs [list Display::stroke $points $width $color] on layer $Display::LAYER] + } + + proc circle {x y radius thickness color} { + uplevel [list Wish display runs [list Display::circle $x $y $radius $thickness $color] on layer $Display::LAYER] + } + + proc text args { + uplevel [list Wish display runs [list Display::text {*}$args] on layer $Display::LAYER] + } + + proc fillTriangle args { + uplevel [list Wish display runs [list Display::fillTriangle {*}$args] on layer $Display::LAYER] + } + + proc fillQuad args { + uplevel [list Wish display runs [list Display::fillQuad {*}$args] on layer $Display::LAYER] + } + + proc fillPolygon args { + uplevel [list Wish display runs [list Display::fillPolygon {*}$args] on layer $Display::LAYER] + } + + variable displayTime none +} + +On process { + source pi/Display.tcl + Display::init + puts "Display tid: [getTid]" + + # TODO: Clean this up. We retract these so that we don't bounce + # statements back to the main Folk process that it sends us. + Retract /anyone/ wishes $::thisProcess shares all wishes + Retract /anyone/ wishes $::thisProcess shares all claims + Wish $::thisProcess shares statements like \ + [list /someone/ wishes /process/ receives statements like /pattern/] + Wish $::thisProcess shares statements like \ + [list /someone/ claims $::thisProcess has pid /pid/] + Wish $::thisProcess receives statements like \ + [list /someone/ wishes display runs /command/ on layer /layer/] + Wish $::thisProcess receives statements like \ + [list /someone/ wishes display runs /command/] + + forever { + set displayList [list] + foreach match [Statements::findMatches {/someone/ wishes display runs /command/ on layer /layer/}] { + lappend displayList [list [dict get $match layer] [dict get $match command]] + } + foreach match [Statements::findMatches {/someone/ wishes display runs /command/}] { + lappend displayList [list 0 [dict get $match command]] + } + + proc lcomp {a b} { + set layerA [lindex $a 0] + set layerB [lindex $b 0] + if {$layerA == $layerB} { + expr {[lindex $a 1 0] == "Display::text"} + } else { + expr {$layerA - $layerB} + } + } + + set displayCommands [join [lmap sublist [lsort -command lcomp $displayList] {lindex $sublist 1}] "\n"] + append displayCommands "\ncommitThenClearStaging" + set displayTime [time $displayCommands] + } +} -- cgit v1.2.3 From 6635ab4466548a2f9e370424f17cf68c1799605d Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Thu, 10 Aug 2023 21:25:17 -0400 Subject: Report display time --- virtual-programs/display.folk | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'virtual-programs/display.folk') diff --git a/virtual-programs/display.folk b/virtual-programs/display.folk index ce7c0c2c..a771b045 100644 --- a/virtual-programs/display.folk +++ b/virtual-programs/display.folk @@ -56,6 +56,8 @@ On process { [list /someone/ wishes display runs /command/ on layer /layer/] Wish $::thisProcess receives statements like \ [list /someone/ wishes display runs /command/] + Wish $::thisProcess shares statements like \ + [list /someone/ claims the display time is /displayTime/] forever { set displayList [list] @@ -79,5 +81,10 @@ On process { set displayCommands [join [lmap sublist [lsort -command lcomp $displayList] {lindex $sublist 1}] "\n"] append displayCommands "\ncommitThenClearStaging" set displayTime [time $displayCommands] + Commit { Claim the display time is $displayTime } } } +# TODO: remove this compatibility hack +When the display time is /displayTime/ { + set ::Display::displayTime $displayTime +} -- cgit v1.2.3 From 55f9cd4cc30e4fe157419315945d083184ecb871 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Fri, 11 Aug 2023 19:47:04 -0400 Subject: Measure display fps --- virtual-programs/display.folk | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'virtual-programs/display.folk') diff --git a/virtual-programs/display.folk b/virtual-programs/display.folk index a771b045..b1d16be7 100644 --- a/virtual-programs/display.folk +++ b/virtual-programs/display.folk @@ -59,6 +59,7 @@ On process { Wish $::thisProcess shares statements like \ [list /someone/ claims the display time is /displayTime/] + set ::frames [list] forever { set displayList [list] foreach match [Statements::findMatches {/someone/ wishes display runs /command/ on layer /layer/}] { @@ -78,10 +79,20 @@ On process { } } - set displayCommands [join [lmap sublist [lsort -command lcomp $displayList] {lindex $sublist 1}] "\n"] - append displayCommands "\ncommitThenClearStaging" - set displayTime [time $displayCommands] - Commit { Claim the display time is $displayTime } + set displayCommands [lmap sublist [lsort -command lcomp $displayList] {lindex $sublist 1}] + lappend displayCommands "commitThenClearStaging" + set displayTime [baretime [list foreach command $displayCommands { {*}$command }]] + + set inLastSecond 0 + set now [clock milliseconds] + lappend frames $now + foreach frame $frames { + if {$frame > $now - 1000} { + incr inLastSecond + } + } + set frames [lreplace $frames 0 end-$inLastSecond] + Commit { Claim the display time is "$displayTime us ($inLastSecond fps)" } } } # TODO: remove this compatibility hack -- cgit v1.2.3 From 7d462c3bd10b29da1063c338ae66ab253a1e71d8 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Sun, 13 Aug 2023 19:26:00 -0400 Subject: display: Show render/commit split --- virtual-programs/display.folk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'virtual-programs/display.folk') diff --git a/virtual-programs/display.folk b/virtual-programs/display.folk index b1d16be7..d5623d10 100644 --- a/virtual-programs/display.folk +++ b/virtual-programs/display.folk @@ -80,8 +80,8 @@ On process { } set displayCommands [lmap sublist [lsort -command lcomp $displayList] {lindex $sublist 1}] - lappend displayCommands "commitThenClearStaging" - set displayTime [baretime [list foreach command $displayCommands { {*}$command }]] + set renderTime [baretime [list foreach command $displayCommands { {*}$command }]] + set commitTime [baretime commitThenClearStaging] set inLastSecond 0 set now [clock milliseconds] @@ -92,7 +92,7 @@ On process { } } set frames [lreplace $frames 0 end-$inLastSecond] - Commit { Claim the display time is "$displayTime us ($inLastSecond fps)" } + Commit { Claim the display time is "render $renderTime us + commit $commitTime us ($inLastSecond fps)" } } } # TODO: remove this compatibility hack -- cgit v1.2.3 From 3ddc9e924e7e747f3d75501eaa8cd731d67f5e7c Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Sun, 13 Aug 2023 23:07:57 -0400 Subject: More small monitoring improvements. Remote flamegraph tid --- virtual-programs/display.folk | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'virtual-programs/display.folk') diff --git a/virtual-programs/display.folk b/virtual-programs/display.folk index d5623d10..5e16797f 100644 --- a/virtual-programs/display.folk +++ b/virtual-programs/display.folk @@ -80,19 +80,20 @@ On process { } set displayCommands [lmap sublist [lsort -command lcomp $displayList] {lindex $sublist 1}] + set renderTime [baretime [list foreach command $displayCommands { {*}$command }]] set commitTime [baretime commitThenClearStaging] - set inLastSecond 0 + set framesInLastSecond 0 set now [clock milliseconds] lappend frames $now foreach frame $frames { if {$frame > $now - 1000} { - incr inLastSecond + incr framesInLastSecond } } - set frames [lreplace $frames 0 end-$inLastSecond] - Commit { Claim the display time is "render $renderTime us + commit $commitTime us ($inLastSecond fps)" } + set frames [lreplace $frames 0 end-$framesInLastSecond] + Commit { Claim the display time is "render $renderTime us + commit $commitTime us ($framesInLastSecond fps)" } } } # TODO: remove this compatibility hack -- cgit v1.2.3 From f42902b4cf694a4ec3f4f345699384ab53e32ece Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Tue, 15 Aug 2023 17:14:19 -0400 Subject: WIP: Rewrite peering to use shm instead of websockets Huge performance increases, but crashy. --- virtual-programs/display.folk | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'virtual-programs/display.folk') diff --git a/virtual-programs/display.folk b/virtual-programs/display.folk index 5e16797f..b0b878ca 100644 --- a/virtual-programs/display.folk +++ b/virtual-programs/display.folk @@ -60,7 +60,7 @@ On process { [list /someone/ claims the display time is /displayTime/] set ::frames [list] - forever { + while true { set displayList [list] foreach match [Statements::findMatches {/someone/ wishes display runs /command/ on layer /layer/}] { lappend displayList [list [dict get $match layer] [dict get $match command]] @@ -93,7 +93,9 @@ On process { } } set frames [lreplace $frames 0 end-$framesInLastSecond] - Commit { Claim the display time is "render $renderTime us + commit $commitTime us ($framesInLastSecond fps)" } + + Commit { Claim the display time is "render $renderTime us + commit $commitTime us ($::stepTime) ($framesInLastSecond fps)" } + Step } } # TODO: remove this compatibility hack -- cgit v1.2.3 From d540c5f990b75ed80acfd0c323da052672b8bb4c Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Sun, 3 Sep 2023 17:28:07 -0400 Subject: Use ::Display instead of Display for safety --- virtual-programs/display.folk | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'virtual-programs/display.folk') diff --git a/virtual-programs/display.folk b/virtual-programs/display.folk index b0b878ca..c73b354c 100644 --- a/virtual-programs/display.folk +++ b/virtual-programs/display.folk @@ -1,39 +1,39 @@ if {$::isLaptop} return -namespace eval Display { +namespace eval ::Display { variable WIDTH variable HEIGHT variable LAYER 0 regexp {mode "(\d+)x(\d+)"} [exec fbset] -> WIDTH HEIGHT proc drawOnTop {func args} { - set Display::LAYER 1 + set ::Display::LAYER 1 uplevel [list $func {*}$args] - set Display::LAYER 0 + set ::Display::LAYER 0 } proc stroke {points width color} { - uplevel [list Wish display runs [list Display::stroke $points $width $color] on layer $Display::LAYER] + uplevel [list Wish display runs [list Display::stroke $points $width $color] on layer $::Display::LAYER] } proc circle {x y radius thickness color} { - uplevel [list Wish display runs [list Display::circle $x $y $radius $thickness $color] on layer $Display::LAYER] + uplevel [list Wish display runs [list Display::circle $x $y $radius $thickness $color] on layer $::Display::LAYER] } proc text args { - uplevel [list Wish display runs [list Display::text {*}$args] on layer $Display::LAYER] + uplevel [list Wish display runs [list Display::text {*}$args] on layer $::Display::LAYER] } proc fillTriangle args { - uplevel [list Wish display runs [list Display::fillTriangle {*}$args] on layer $Display::LAYER] + uplevel [list Wish display runs [list Display::fillTriangle {*}$args] on layer $::Display::LAYER] } proc fillQuad args { - uplevel [list Wish display runs [list Display::fillQuad {*}$args] on layer $Display::LAYER] + uplevel [list Wish display runs [list Display::fillQuad {*}$args] on layer $::Display::LAYER] } proc fillPolygon args { - uplevel [list Wish display runs [list Display::fillPolygon {*}$args] on layer $Display::LAYER] + uplevel [list Wish display runs [list Display::fillPolygon {*}$args] on layer $::Display::LAYER] } variable displayTime none -- cgit v1.2.3 From 6b426aa5853d8aa4d389a36f076a8cf416a3c91c Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Wed, 6 Sep 2023 02:11:46 -0400 Subject: Some peering cleanup (receive before Step); build in FPS counting --- virtual-programs/display.folk | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'virtual-programs/display.folk') diff --git a/virtual-programs/display.folk b/virtual-programs/display.folk index c73b354c..d3f6b610 100644 --- a/virtual-programs/display.folk +++ b/virtual-programs/display.folk @@ -59,7 +59,6 @@ On process { Wish $::thisProcess shares statements like \ [list /someone/ claims the display time is /displayTime/] - set ::frames [list] while true { set displayList [list] foreach match [Statements::findMatches {/someone/ wishes display runs /command/ on layer /layer/}] { @@ -84,17 +83,7 @@ On process { set renderTime [baretime [list foreach command $displayCommands { {*}$command }]] set commitTime [baretime commitThenClearStaging] - set framesInLastSecond 0 - set now [clock milliseconds] - lappend frames $now - foreach frame $frames { - if {$frame > $now - 1000} { - incr framesInLastSecond - } - } - set frames [lreplace $frames 0 end-$framesInLastSecond] - - Commit { Claim the display time is "render $renderTime us + commit $commitTime us ($::stepTime) ($framesInLastSecond fps)" } + Commit { Claim the display time is "render $renderTime us + commit $commitTime us ($::stepTime)" } Step } } -- cgit v1.2.3