Class: Diagnosticism::DOOMGram

Inherits:
Object
  • Object
show all
Defined in:
lib/diagnosticism/doomgram.rb

Overview

Decimal Order-Of-Magnitude frequency histoGRAM

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDOOMGram

Returns a new instance of DOOMGram.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/diagnosticism/doomgram.rb', line 48

def initialize

  @event_count          = 0

  @total_event_time_ns  = 0

  @min_event_time_ns    = nil
  @max_event_time_ns    = nil

  @num_events_in_1ns    = 0
  @num_events_in_10ns   = 0
  @num_events_in_100ns  = 0
  @num_events_in_1us    = 0
  @num_events_in_10us   = 0
  @num_events_in_100us  = 0
  @num_events_in_1ms    = 0
  @num_events_in_10ms   = 0
  @num_events_in_100ms  = 0
  @num_events_in_1s     = 0
  @num_events_in_10s    = 0
  @num_events_ge_100s   = 0
end

Instance Attribute Details

#event_countObject (readonly)

Number of events counted



72
73
74
# File 'lib/diagnosticism/doomgram.rb', line 72

def event_count
  @event_count
end

#max_event_time_nsObject (readonly)

Obtain the maximum event time (in nanoseconds), or nil if no events



78
79
80
# File 'lib/diagnosticism/doomgram.rb', line 78

def max_event_time_ns
  @max_event_time_ns
end

#min_event_time_nsObject (readonly)

Obtain the minimum event time (in nanoseconds), or nil if no events



76
77
78
# File 'lib/diagnosticism/doomgram.rb', line 76

def min_event_time_ns
  @min_event_time_ns
end

#num_events_ge_100sObject (readonly)

Number of events counted in the interval [100s, ∞)



102
103
104
# File 'lib/diagnosticism/doomgram.rb', line 102

def num_events_ge_100s
  @num_events_ge_100s
end

#num_events_in_100msObject (readonly)

Number of events counted in the interval [100ms, 1s)



96
97
98
# File 'lib/diagnosticism/doomgram.rb', line 96

def num_events_in_100ms
  @num_events_in_100ms
end

#num_events_in_100nsObject (readonly)

Number of events counted in the interval [100ns, 1µs)



84
85
86
# File 'lib/diagnosticism/doomgram.rb', line 84

def num_events_in_100ns
  @num_events_in_100ns
end

#num_events_in_100usObject (readonly)

Number of events counted in the interval [100µs, 1ms)



90
91
92
# File 'lib/diagnosticism/doomgram.rb', line 90

def num_events_in_100us
  @num_events_in_100us
end

#num_events_in_10msObject (readonly)

Number of events counted in the interval [10ms, 100ms)



94
95
96
# File 'lib/diagnosticism/doomgram.rb', line 94

def num_events_in_10ms
  @num_events_in_10ms
end

#num_events_in_10nsObject (readonly)

Number of events counted in the interval [10ns, 100ns)



82
83
84
# File 'lib/diagnosticism/doomgram.rb', line 82

def num_events_in_10ns
  @num_events_in_10ns
end

#num_events_in_10sObject (readonly)

Number of events counted in the interval [10s, 100s)



100
101
102
# File 'lib/diagnosticism/doomgram.rb', line 100

def num_events_in_10s
  @num_events_in_10s
end

#num_events_in_10usObject (readonly)

Number of events counted in the interval [10µs, 100µs)



88
89
90
# File 'lib/diagnosticism/doomgram.rb', line 88

def num_events_in_10us
  @num_events_in_10us
end

#num_events_in_1msObject (readonly)

Number of events counted in the interval [1ms, 10ms)



92
93
94
# File 'lib/diagnosticism/doomgram.rb', line 92

def num_events_in_1ms
  @num_events_in_1ms
end

#num_events_in_1nsObject (readonly)

Number of events counted in the interval [1ns, 10ns)



80
81
82
# File 'lib/diagnosticism/doomgram.rb', line 80

def num_events_in_1ns
  @num_events_in_1ns
end

#num_events_in_1sObject (readonly)

Number of events counted in the interval [1s, 10s)



98
99
100
# File 'lib/diagnosticism/doomgram.rb', line 98

def num_events_in_1s
  @num_events_in_1s
end

#num_events_in_1usObject (readonly)

Number of events counted in the interval [1µs, 10µs)



86
87
88
# File 'lib/diagnosticism/doomgram.rb', line 86

def num_events_in_1us
  @num_events_in_1us
end

#total_event_time_nsObject (readonly)

Obtains the total event time (in nanoseconds)



74
75
76
# File 'lib/diagnosticism/doomgram.rb', line 74

def total_event_time_ns
  @total_event_time_ns
end

Instance Method Details

#push_event_time_ms(time_in_ms) ⇒ Object

Pushes an event with the given number of milliseconds



199
200
201
202
# File 'lib/diagnosticism/doomgram.rb', line 199

def push_event_time_ms(time_in_ms)

  push_event_time_ns time_in_ms * 1_000_000
end

#push_event_time_ns(time_in_ns) ⇒ Object

Pushes an event with the given number of nanoseconds



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/diagnosticism/doomgram.rb', line 105

def push_event_time_ns(time_in_ns)

  @event_count += 1

  @total_event_time_ns += time_in_ns


  if @min_event_time_ns.nil? || time_in_ns < @min_event_time_ns

    @min_event_time_ns = time_in_ns
  end

  if @max_event_time_ns.nil? || @max_event_time_ns < time_in_ns

    @max_event_time_ns = time_in_ns
  end


  if time_in_ns >= 100_000_000

    if time_in_ns >= 10_000_000_000

      if time_in_ns >= 100_000_000_000

        @num_events_ge_100s += 1
      else

        @num_events_in_10s += 1
      end
    else

      if time_in_ns >= 1_000_000_000

        @num_events_in_1s += 1
      else

        @num_events_in_100ms += 1
      end
    end
  else

    if time_in_ns >= 10_000

      if time_in_ns >= 1_000_000

        if time_in_ns >= 10_000_000

          @num_events_in_10ms += 1
        else

          @num_events_in_1ms += 1
        end
      else

        if time_in_ns >= 100_000

          @num_events_in_100us += 1
        else

          @num_events_in_10us += 1
        end
      end
    else

      if time_in_ns >= 100

        if time_in_ns >= 1_000

          @num_events_in_1us += 1
        else

          @num_events_in_100ns += 1
        end
      else

        if time_in_ns >= 10

          @num_events_in_10ns += 1
        elsif time_in_ns >= 1

          @num_events_in_1ns += 1
        end
      end
    end
  end
end

#push_event_time_s(time_in_s) ⇒ Object

Pushes an event with the given number of seconds



205
206
207
208
# File 'lib/diagnosticism/doomgram.rb', line 205

def push_event_time_s(time_in_s)

  push_event_time_ns time_in_s * 1_000_000_000
end

#push_event_time_us(time_in_us) ⇒ Object

Pushes an event with the given number of microseconds



193
194
195
196
# File 'lib/diagnosticism/doomgram.rb', line 193

def push_event_time_us(time_in_us)

  push_event_time_ns time_in_us * 1_000
end

#to_sObject

Converts to string form according to default options



267
268
269
270
# File 'lib/diagnosticism/doomgram.rb', line 267

def to_s

  to_strip
end

#to_strip(**options) ⇒ Object

Converts to string form according to given options

Signature

  • Parameters:

    • options (+Hash+, Integer) Combination of flags (with behaviour as described below for the flags option), or an options hash;
  • Options:

    • overflow_character (+String+) A string (of length 1) that specifies the symbol for counts outside the available range. Defaults to '*';
    • range (+String+) A string whose characters specificy the symbols to use for counts in orders of magnitude. Defaults to 'abcdefghijklmnopqrstuvwxyz', which caters to the counts 1-9 => +'a', 10-99 => 'b', 100-999 => 'c', ... 10^25-(10^26-1) => 'z';
    • zero_character (+String+) A string (of length 1) that specifies the symbol for a count of 0. Defaults to ' ';

Return

(+String+) A string (of length 12) containing symbols representing the counts in the ranges 1ns, 10ns, ..., 10s, 100+s.



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/diagnosticism/doomgram.rb', line 224

def to_strip **options

  ch_zero     = options[:zero_character] || options[:zero_char] || '_'
  ch_overflow = options[:overflow_character] || options[:overflow_char] || '*'
  range_chars = options[:range] || 'abcdefghijklmnopqrstuvwxyz'

  counts = [
    num_events_in_1ns,
    num_events_in_10ns,
    num_events_in_100ns,
    num_events_in_1us,
    num_events_in_10us,
    num_events_in_100us,
    num_events_in_1ms,
    num_events_in_10ms,
    num_events_in_100ms,
    num_events_in_1s,
    num_events_in_10s,
    num_events_ge_100s,
  ]

  s = ch_zero[0] * 12 # "____________"

  counts.each_with_index do |count, index|

    next if 0 == count

    # TODO: get a faster way to count digits
    oom = Math.log10(count).to_i

    if oom < range_chars.size

      s[index] = range_chars[oom]
    else

      s[index] = ch_overflow[0]
    end
  end

  s
end