Module: RedShift::World::ZenoDebugger

Defined in:
lib/redshift/mixins/zeno-debugger.rb

Overview

Include this module in a World class. See example in examples/zeno.rb. Has a very small performance cost, so don’t use it in production runs. Note that, even without ZenoDebugger, RedShift will still detect zeno problems by raising a ZenoError when world.zeno_counter > world.zeno_limit, if zeno_limit >= 0.

ZenoDebugger is compatible with other kinds of debuggers.

Constant Summary collapse

HEADER =
'-'*10 + " Zeno step: %d; Components: %d; Active: %d " + '-'*10 + "\n"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#debug_zenoObject

Can be used to turn on and off this module, set to $REDSHIFT_DEBUG_ZENO by default.



15
16
17
# File 'lib/redshift/mixins/zeno-debugger.rb', line 15

def debug_zeno
  @debug_zeno
end

#debug_zeno_limitObject

How many zeno steps before the debugger gives up. Set to ZENO_UNLIMITED to debug indefinitely, e.g., for interactive mode. By default, equal to 3 times world.zeno_limit, so that batch runs will terminate.



28
29
30
# File 'lib/redshift/mixins/zeno-debugger.rb', line 28

def debug_zeno_limit
  @debug_zeno_limit
end

#zeno_outputObject

Zeno output goes to this object, $stderr by default, using #<<.



18
19
20
# File 'lib/redshift/mixins/zeno-debugger.rb', line 18

def zeno_output
  @zeno_output
end

#zeno_watch_listObject

Can be used to see which components are causing trouble. Ny default, the output covers all compontents taking transitions. However, you can use this attr to focus more narrowly.



23
24
25
# File 'lib/redshift/mixins/zeno-debugger.rb', line 23

def zeno_watch_list
  @zeno_watch_list
end

Instance Method Details

#initializeObject



30
31
32
33
34
# File 'lib/redshift/mixins/zeno-debugger.rb', line 30

def initialize
  @debug_zeno       ||= $REDSHIFT_DEBUG_ZENO ## why ||= ?
  @zeno_output      ||= $stderr
  super
end

#report_zenoObject

Reports to zeno_output the list of active components.



61
62
63
64
65
66
67
# File 'lib/redshift/mixins/zeno-debugger.rb', line 61

def report_zeno
  f = zeno_output
  active = zeno_watch_list || curr_T

  f << HEADER % [zeno_counter, components.size, curr_T.size]
  f << '  ' + active.map{|c|c.inspect}.join("\n  ") + "\n"
end

#step_zenoObject

This method is called for each discrete step after the zeno_limit has been exceeded. This implementation is just one possibility, useful for debugging. One other useful behavior might be to shuffle guards in the active components.

In this implementation, when the zeno_counter exceeds zeno_limit, we start to add active objects to the zeno_watch_list. When the counter exceeds two times the zeno_limit, we call report_zeno. When the counter exceeds three times the zeno_limit, we fall back to the super definition of step_zeno, which is typically to raise a ZenoError.



47
48
49
50
51
52
53
54
55
56
# File 'lib/redshift/mixins/zeno-debugger.rb', line 47

def step_zeno
  self.debug_zeno_limit ||= zeno_limit*3
  if debug_zeno and
     (debug_zeno_limit == RedShift::ZENO_UNLIMITED or
      zeno_counter < debug_zeno_limit)
    report_zeno if zeno_counter >= 2*zeno_limit
  else
    super
  end
end