flagger 2.0.9 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,56 +0,0 @@
1
- require 'json'
2
-
3
- module FlaggerUtils
4
- class Stat
5
- attr_reader :name
6
- attr_accessor :duration
7
- attr_accessor :count
8
-
9
- def self.compact(stats)
10
- groups = stats.group_by {|stat| stat.name}
11
- groups.values.map do |same_stats|
12
- new_stat = Stat.new(same_stats[0].name)
13
- new_stat.count = same_stats.reduce(0) {|count, stat| count + stat.count}
14
- if same_stats[0].duration then
15
- new_stat.duration = same_stats.reduce(0) {|duration, stat| duration + stat.duration * stat.count} / new_stat.count
16
- end
17
- new_stat
18
- end
19
- end
20
-
21
- def initialize(name)
22
- @name = name
23
- @count = 0
24
- end
25
-
26
- def start()
27
- @start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
28
- end
29
-
30
- def stop()
31
- @end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
32
- @duration = (@end_time - @start_time) * 1e9
33
- @count = 1
34
- end
35
-
36
- def to_json(options={})
37
- to_h.to_json(options)
38
- end
39
-
40
- def to_h()
41
- if @duration then
42
- {
43
- name: name,
44
- duration: @duration,
45
- unit: 'ns',
46
- count: @count
47
- }
48
- else
49
- {
50
- name: name,
51
- count: @count
52
- }
53
- end
54
- end
55
- end
56
- end