dev.nlited.com

>>

Find State

<<<< prev

2023-03-06 16:41:22 chip Page 2515 📢 PUBLIC

March 6 2023

Creating an efficient way to search for events in the log had eluded me for a long time. I wanted to be able to search for complex events, things like "the rising edge of channel 3 while both channels 1 and 2 are high."

I finally have the solution: A simple scripting language that tests each state. The script allows the user to test for any condition, from very simple to incredibly complex. The trick was to make the script execution very fast, since it would need to run on a large number of states, possibly in the hundreds of thousands or even millions.

This is accomplished by rendering the user's script down to optimized byte-code that can be parsed very quickly.

The script is written using a modified form of RPN (Reverse Polish Notation), something that will be familiar to anyone who has used HP calculators. RPN pushes arguments onto a stack and then functions pop the arguments and push the result. RPN looks strange at first, but it really is the most efficient way to break down complex sequences. And from the computer's perspective it is incredibly fast and efficient.

The script will find the longest time spent inside a function.


LongestTime: ;Find the longest Draw time. ;Channels ; 6 FieldDraw2 HI while inside Field::Draw2() define Draw2 6 ;Registers: ; 0 bool IsInside Set while inside FieldDraw2 ; 1 tick DrawStart FieldDraw2 starting tick ; 2 tick MaxStart Longest span start ; 3 tick MaxSpan Longest span duration define IsInside 0 define DrawStart 1 define MaxStart 2 define MaxSpan 3 ; Is this the start of FieldDraw2? Draw2 rise if true IsInside store ; Set IsInside tick DrawStart store ; Set DrawStart endif ; Is this the end of FieldDraw2? Draw2 fall if ; If falling edge IsInside fetch if ; If IsInside tick DrawStart fetch sub ; Tick delta since rising edge MaxSpan fetch gt if ; If greater than MaxSpan DrawStart fetch start sub MaxStart store ; Set MaxStart to delta since log start. tick DrawStart fetch sub MaxSpan store ; Set MaxSpan to delta since DrawStart endif endif false IsInside store ; Clear IsInside endif ; Return false to keep checking to the end of the view. false


WebV7 (C)2018 nlited | Rendered by tikope in 47.951ms | 3.145.8.2