ddmetrics 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -1
- data/LICENSE.txt +1 -1
- data/NEWS.md +6 -0
- data/README.md +9 -9
- data/lib/ddmetrics/printer.rb +12 -12
- data/lib/ddmetrics/table.rb +10 -4
- data/lib/ddmetrics/version.rb +1 -1
- data/spec/ddmetrics/counter_spec.rb +4 -4
- data/spec/ddmetrics/summary_spec.rb +35 -12
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc9eff515c2d5ddd9cf35e2185643a05291e3590636ae9dcee272ca4982aa9d4
|
4
|
+
data.tar.gz: a60d517b811fa2b421789138956d7580755a41c63fc844955dd7190d62489ea0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cf2f5dd6f2a5f2e7dba26737f644d3c96589d8e4249adc83a4124d4859cab419b6513a593004a1c6e2650093742dcd1481bd1c1d73d048ceea20aa0316cc1d6
|
7
|
+
data.tar.gz: bdd81032dc806a0ae195dd52d0def6dad76b2a7c308b24aebfb02608155db1f06dc77cf0996c0f7f56d3a155d1419ca82adac930b37258f60d7a241119a3553a
|
data/.rubocop.yml
CHANGED
@@ -7,7 +7,10 @@ AllCops:
|
|
7
7
|
Style/TrailingCommaInArguments:
|
8
8
|
EnforcedStyleForMultiline: comma
|
9
9
|
|
10
|
-
Style/
|
10
|
+
Style/TrailingCommaInArrayLiteral:
|
11
|
+
EnforcedStyleForMultiline: comma
|
12
|
+
|
13
|
+
Style/TrailingCommaInHashLiteral:
|
11
14
|
EnforcedStyleForMultiline: comma
|
12
15
|
|
13
16
|
Layout/IndentArray:
|
data/LICENSE.txt
CHANGED
data/NEWS.md
CHANGED
data/README.md
CHANGED
@@ -89,11 +89,11 @@ puts cache.counter
|
|
89
89
|
```
|
90
90
|
|
91
91
|
```
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
92
|
+
type │ count
|
93
|
+
─────────┼──────
|
94
|
+
get_hit │ 3
|
95
|
+
get_miss │ 2
|
96
|
+
set │ 1
|
97
97
|
```
|
98
98
|
|
99
99
|
## Scope
|
@@ -205,10 +205,10 @@ puts summary
|
|
205
205
|
Output:
|
206
206
|
|
207
207
|
```
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
208
|
+
filter │ count min .50 .90 .95 max tot
|
209
|
+
───────┼────────────────────────────────────────────────
|
210
|
+
erb │ 2 2.10 3.10 3.90 4.00 4.10 6.20
|
211
|
+
haml │ 1 5.30 5.30 5.30 5.30 5.30 5.30
|
212
212
|
```
|
213
213
|
|
214
214
|
### Stopwatch
|
data/lib/ddmetrics/printer.rb
CHANGED
@@ -3,23 +3,21 @@
|
|
3
3
|
module DDMetrics
|
4
4
|
class Printer
|
5
5
|
def summary_to_s(summary)
|
6
|
-
|
6
|
+
table_for_summary(summary).to_s
|
7
7
|
end
|
8
8
|
|
9
9
|
def counter_to_s(counter)
|
10
|
-
|
10
|
+
table_for_counter(counter).to_s
|
11
11
|
end
|
12
12
|
|
13
13
|
private
|
14
14
|
|
15
|
-
def label_to_s(label)
|
16
|
-
label.to_a.sort.map { |pair| pair.join('=') }.join(' ')
|
17
|
-
end
|
18
|
-
|
19
15
|
def table_for_summary(summary)
|
20
|
-
|
16
|
+
header_labels = nil
|
17
|
+
headers = ['count', 'min', '.50', '.90', '.95', 'max', 'tot']
|
21
18
|
|
22
19
|
rows = summary.labels.map do |label|
|
20
|
+
header_labels ||= label.to_a.sort.map(&:first).map(&:to_s)
|
23
21
|
stats = summary.get(label)
|
24
22
|
|
25
23
|
count = stats.count
|
@@ -30,20 +28,22 @@ module DDMetrics
|
|
30
28
|
tot = stats.sum
|
31
29
|
max = stats.max
|
32
30
|
|
33
|
-
|
31
|
+
label.to_a.sort.map(&:last).map(&:to_s) + [count.to_s] + [min, p50, p90, p95, max, tot].map { |r| format('%4.2f', r) }
|
34
32
|
end
|
35
33
|
|
36
|
-
[headers] + rows
|
34
|
+
DDMetrics::Table.new([header_labels + headers] + rows, num_headers: header_labels.size)
|
37
35
|
end
|
38
36
|
|
39
37
|
def table_for_counter(counter)
|
40
|
-
|
38
|
+
header_labels = nil
|
39
|
+
headers = ['count']
|
41
40
|
|
42
41
|
rows = counter.labels.map do |label|
|
43
|
-
|
42
|
+
header_labels ||= label.to_a.sort.map(&:first).map(&:to_s)
|
43
|
+
label.to_a.sort.map(&:last).map(&:to_s) + [counter.get(label).to_s]
|
44
44
|
end
|
45
45
|
|
46
|
-
[headers] + rows
|
46
|
+
DDMetrics::Table.new([header_labels + headers] + rows, num_headers: header_labels.size)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
data/lib/ddmetrics/table.rb
CHANGED
@@ -2,8 +2,9 @@
|
|
2
2
|
|
3
3
|
module DDMetrics
|
4
4
|
class Table
|
5
|
-
def initialize(rows)
|
5
|
+
def initialize(rows, num_headers: 1)
|
6
6
|
@rows = rows
|
7
|
+
@num_headers = num_headers
|
7
8
|
end
|
8
9
|
|
9
10
|
def to_s
|
@@ -11,8 +12,13 @@ module DDMetrics
|
|
11
12
|
column_lengths = columns.map { |c| c.map(&:size).max }
|
12
13
|
|
13
14
|
[].tap do |lines|
|
15
|
+
# header
|
14
16
|
lines << row_to_s(@rows[0], column_lengths)
|
17
|
+
|
18
|
+
# separator
|
15
19
|
lines << separator(column_lengths)
|
20
|
+
|
21
|
+
# body
|
16
22
|
rows = sort_rows(@rows.drop(1))
|
17
23
|
lines.concat(rows.map { |r| row_to_s(r, column_lengths) })
|
18
24
|
end.join("\n")
|
@@ -26,14 +32,14 @@ module DDMetrics
|
|
26
32
|
|
27
33
|
def row_to_s(row, column_lengths)
|
28
34
|
values = row.zip(column_lengths).map { |text, length| text.rjust(length) }
|
29
|
-
values
|
35
|
+
values.take(@num_headers).join(' ') + ' │ ' + values.drop(@num_headers).join(' ')
|
30
36
|
end
|
31
37
|
|
32
38
|
def separator(column_lengths)
|
33
39
|
(+'').tap do |s|
|
34
|
-
s << '─' *
|
40
|
+
s << column_lengths.take(@num_headers).map { |l| '─' * l }.join('───')
|
35
41
|
s << '─┼─'
|
36
|
-
s << column_lengths
|
42
|
+
s << column_lengths.drop(@num_headers).map { |l| '─' * l }.join('───')
|
37
43
|
end
|
38
44
|
end
|
39
45
|
end
|
data/lib/ddmetrics/version.rb
CHANGED
@@ -97,10 +97,10 @@ describe DDMetrics::Counter do
|
|
97
97
|
|
98
98
|
it 'returns table' do
|
99
99
|
expected = <<~TABLE
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
100
|
+
filter │ count
|
101
|
+
───────┼──────
|
102
|
+
erb │ 2
|
103
|
+
haml │ 1
|
104
104
|
TABLE
|
105
105
|
|
106
106
|
expect(subject.strip).to eq(expected.strip)
|
@@ -64,21 +64,44 @@ describe DDMetrics::Summary do
|
|
64
64
|
describe '#to_s' do
|
65
65
|
subject { summary.to_s }
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
context 'one label' do
|
68
|
+
before do
|
69
|
+
summary.observe(2.1, filter: :erb)
|
70
|
+
summary.observe(4.1, filter: :erb)
|
71
|
+
summary.observe(5.3, filter: :haml)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'returns table' do
|
75
|
+
expected = <<~TABLE
|
76
|
+
filter │ count min .50 .90 .95 max tot
|
77
|
+
───────┼────────────────────────────────────────────────
|
78
|
+
erb │ 2 2.10 3.10 3.90 4.00 4.10 6.20
|
79
|
+
haml │ 1 5.30 5.30 5.30 5.30 5.30 5.30
|
80
|
+
TABLE
|
81
|
+
|
82
|
+
expect(subject.strip).to eq(expected.strip)
|
83
|
+
end
|
71
84
|
end
|
72
85
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
filter
|
79
|
-
|
86
|
+
context 'multiple labels' do
|
87
|
+
before do
|
88
|
+
summary.observe(2.1, filter: :erb, stage: :pre)
|
89
|
+
summary.observe(4.1, filter: :erb, stage: :pre)
|
90
|
+
summary.observe(1.2, filter: :erb, stage: :post)
|
91
|
+
summary.observe(5.3, filter: :haml, stage: :post)
|
92
|
+
end
|
80
93
|
|
81
|
-
|
94
|
+
it 'returns table' do
|
95
|
+
expected = <<~TABLE
|
96
|
+
filter stage │ count min .50 .90 .95 max tot
|
97
|
+
───────────────┼────────────────────────────────────────────────
|
98
|
+
erb pre │ 2 2.10 3.10 3.90 4.00 4.10 6.20
|
99
|
+
erb post │ 1 1.20 1.20 1.20 1.20 1.20 1.20
|
100
|
+
haml post │ 1 5.30 5.30 5.30 5.30 5.30 5.30
|
101
|
+
TABLE
|
102
|
+
|
103
|
+
expect(subject.strip).to eq(expected.strip)
|
104
|
+
end
|
82
105
|
end
|
83
106
|
end
|
84
107
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ddmetrics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Defreyne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
70
|
version: '0'
|
71
71
|
requirements: []
|
72
72
|
rubyforge_project:
|
73
|
-
rubygems_version: 2.7.
|
73
|
+
rubygems_version: 2.7.7
|
74
74
|
signing_key:
|
75
75
|
specification_version: 4
|
76
76
|
summary: Non-timeseries measurements for Ruby programs
|