Class: Roby::EventLogging::IOEventLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/roby/event_logging/io_event_logger.rb

Overview

A simple event logger that displays a textual representation of the events on plain I/O (e.g. log file or stdout)

Defined Under Namespace

Classes: Event, TimepointGroupDisplay, TimepointGroupStats

Constant Summary collapse

TIMEPOINT_GROUP_FORMAT =
"timegroup %<name>s: %<duration>.3f - %<stats>s"

Instance Method Summary collapse

Constructor Details

#initialize(out: $stdout) ⇒ IOEventLogger

Returns a new instance of IOEventLogger.



8
9
10
11
12
13
14
15
# File 'lib/roby/event_logging/io_event_logger.rb', line 8

def initialize(out: $stdout)
    @out = out

    @displayed_timepoints = Set.new
    @displayed_timegroups = Set.new
    @displayed_events = Set.new
    @timepoint_group_start = {}
end

Instance Method Details

#closeObject



248
# File 'lib/roby/event_logging/io_event_logger.rb', line 248

def close; end

#display_event(name, time, args) ⇒ Object



168
169
170
# File 'lib/roby/event_logging/io_event_logger.rb', line 168

def display_event(name, time, args)
    @out.puts PP.pp(Event.new(name, time, args), +"")
end

#display_event?(name) ⇒ Boolean

Returns:

  • (Boolean)


172
173
174
175
# File 'lib/roby/event_logging/io_event_logger.rb', line 172

def display_event?(name)
    name = name.to_s
    @displayed_events.any? { |matcher| matcher === name }
end

#display_timepoint?(name) ⇒ Boolean

Tests whether the given timepoint name is selected for display

Returns:

  • (Boolean)


237
238
239
240
# File 'lib/roby/event_logging/io_event_logger.rb', line 237

def display_timepoint?(name)
    name = name.to_s
    @displayed_timepoints.any? { |m| m === name }
end

#dump(name, time, args) ⇒ Object

Called whenever there is a non-timepoint event

Parameters:

  • name (Symbol)
  • time (Time)
  • args (Array)

    the event arguments



182
183
184
185
186
# File 'lib/roby/event_logging/io_event_logger.rb', line 182

def dump(name, time, args)
    return unless display_event?(name)

    display_event(name, time, args)
end

#dump_timeObject



254
255
256
# File 'lib/roby/event_logging/io_event_logger.rb', line 254

def dump_time
    0
end

#dump_timepoint(timepoint_event, time, args) ⇒ Object

Called whenever there is a timepoint event

Parameters:

  • the (:timepoint, :timepoint_group_start, :timepoint_group_end)

    timepoint type

  • time (Time)
  • args (Array)

    the timepoint arguments, dependent on the timepoint type



195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/roby/event_logging/io_event_logger.rb', line 195

def dump_timepoint(timepoint_event, time, args)
    timepoint_name = args[-1]
    case timepoint_event
    when :timepoint
        if display_timepoint?(timepoint_name)
            display_event(timepoint_name, time, [])
        end
    when :timepoint_group_start
        dump_timepoint_group_start(timepoint_name, time)
    when :timepoint_group_end
        dump_timepoint_group_end(timepoint_name, time)
    end
end

#dump_timepoint_group_end(timepoint_name, time) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Helper for #dump_timepoint to handle timepoint group end events



225
226
227
228
229
230
231
232
233
234
# File 'lib/roby/event_logging/io_event_logger.rb', line 225

def dump_timepoint_group_end(timepoint_name, time)
    if (dis = find_timegroup_display(timepoint_name))
        dis.update(timepoint_name, time)
        @out.puts dis.message(timepoint_name, time)
    end

    return unless dis || display_timepoint?(timepoint_name)

    display_event("#{timepoint_name}:group-end", time, [])
end

#dump_timepoint_group_start(timepoint_name, time) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Helper for #dump_timepoint to handle timepoint group start events



212
213
214
215
216
217
218
219
220
# File 'lib/roby/event_logging/io_event_logger.rb', line 212

def dump_timepoint_group_start(timepoint_name, time)
    if (dis = find_timegroup_display(timepoint_name))
        dis.push(timepoint_name, time)
    end

    return unless dis || display_timepoint?(timepoint_name)

    display_event("#{timepoint_name}:group-start", time, [])
end

#event_display(matcher) ⇒ Object

Configure the logger to display events as they happen

Parameters:

  • matcher (#===)

    an object against which the event name will be tested, usually either a string or a regular expression

See Also:



55
56
57
# File 'lib/roby/event_logging/io_event_logger.rb', line 55

def event_display(matcher)
    @displayed_events << matcher
end

#find_timegroup_display(name) ⇒ Object

Looks for the timegroup display structure for the given group name



243
244
245
246
# File 'lib/roby/event_logging/io_event_logger.rb', line 243

def find_timegroup_display(name)
    name = name.to_s
    @displayed_timegroups.find { |d| d.matcher === name }
end

#flush_cycle(name, *args) ⇒ Object



258
259
260
# File 'lib/roby/event_logging/io_event_logger.rb', line 258

def flush_cycle(name, *args)
    dump(name, *args)
end

#log_queue_sizeObject



250
251
252
# File 'lib/roby/event_logging/io_event_logger.rb', line 250

def log_queue_size
    0
end

#log_timepoints?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/roby/event_logging/io_event_logger.rb', line 17

def log_timepoints?
    true
end

#timegroup_display(matcher, skip: 0) ⇒ Object

Configure the logger to display statistics information about time groups

Parameters:

  • matcher (#===)

    an object against which the timegroup name will be tested. Statistics will be shown for groups with matching names. Generally a string or a regular expression.

  • skip (Integer) (defaults to: 0)

    skip this many start/end cycles before starting to gather statistics. Meant to "pass" a warmup period.

See Also:



43
44
45
46
47
# File 'lib/roby/event_logging/io_event_logger.rb', line 43

def timegroup_display(matcher, skip: 0)
    @displayed_timegroups << TimepointGroupDisplay.new(
        matcher: matcher, skip: skip, stats: {}
    )
end

#timepoint_display(name) ⇒ Object

Configure the logger to display timepoints as they happen

The method shows the time (with a ms resolution) and the name

Parameters:

  • matcher (#===)

    an object against which the timepoint name will be tested. Statistics will be shown for groups with matching names. Generally a string or a regular expression.

See Also:



30
31
32
# File 'lib/roby/event_logging/io_event_logger.rb', line 30

def timepoint_display(name)
    @displayed_timepoints << name
end