ddmetrics 1.0.0 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b88f4608168f197c67e407f072a257e5fd6b76839c72a3dc0f63b326bc363534
4
- data.tar.gz: 043c06c1a3414422f5f8a442dbec24e634a086f09265a60dc9bb1dd22ef12b7f
3
+ metadata.gz: cc9eff515c2d5ddd9cf35e2185643a05291e3590636ae9dcee272ca4982aa9d4
4
+ data.tar.gz: a60d517b811fa2b421789138956d7580755a41c63fc844955dd7190d62489ea0
5
5
  SHA512:
6
- metadata.gz: c36890a111a870ec0286c02e8d5320ddd5b9ec5d7b3fa7d6809065d7c655a806698a8787e9a07f69468c727c8222775e44ac2935ac357c9fdec896387fe7b69b
7
- data.tar.gz: cf4122e405770d4fc787628660366bc634bbd0d29d41e9002b8564cf56dbccf7a74936a602119e01fb5505d41aff01df9cc3008f8fc72d06685c37f8b19f69d0
6
+ metadata.gz: 0cf2f5dd6f2a5f2e7dba26737f644d3c96589d8e4249adc83a4124d4859cab419b6513a593004a1c6e2650093742dcd1481bd1c1d73d048ceea20aa0316cc1d6
7
+ data.tar.gz: bdd81032dc806a0ae195dd52d0def6dad76b2a7c308b24aebfb02608155db1f06dc77cf0996c0f7f56d3a155d1419ca82adac930b37258f60d7a241119a3553a
@@ -7,7 +7,10 @@ AllCops:
7
7
  Style/TrailingCommaInArguments:
8
8
  EnforcedStyleForMultiline: comma
9
9
 
10
- Style/TrailingCommaInLiteral:
10
+ Style/TrailingCommaInArrayLiteral:
11
+ EnforcedStyleForMultiline: comma
12
+
13
+ Style/TrailingCommaInHashLiteral:
11
14
  EnforcedStyleForMultiline: comma
12
15
 
13
16
  Layout/IndentArray:
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2017 Denis Defreyne
3
+ Copyright (c) 2017–2018 Denis Defreyne
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/NEWS.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # DDMetrics news
2
2
 
3
+ ## 1.0.1 (2018-07-19)
4
+
5
+ Enhancements:
6
+
7
+ * Improved formatting of labels in tables (#7)
8
+
3
9
  ## 1.0.0 (2018-01-07)
4
10
 
5
11
  (identical to 1.0.0rc1)
data/README.md CHANGED
@@ -89,11 +89,11 @@ puts cache.counter
89
89
  ```
90
90
 
91
91
  ```
92
- │ count
93
- ──────────────┼──────
94
- type=get_miss2
95
- type=set1
96
- type=get_hit 3
92
+ type │ count
93
+ ─────────┼──────
94
+ get_hit 3
95
+ get_miss2
96
+ set1
97
97
  ```
98
98
 
99
99
  ## Scope
@@ -205,10 +205,10 @@ puts summary
205
205
  Output:
206
206
 
207
207
  ```
208
- │ count min .50 .90 .95 max tot
209
- ────────────┼────────────────────────────────────────────────
210
- filter=erb │ 2 2.10 3.10 3.90 4.00 4.10 6.20
211
- filter=haml │ 1 5.30 5.30 5.30 5.30 5.30 5.30
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
@@ -3,23 +3,21 @@
3
3
  module DDMetrics
4
4
  class Printer
5
5
  def summary_to_s(summary)
6
- DDMetrics::Table.new(table_for_summary(summary)).to_s
6
+ table_for_summary(summary).to_s
7
7
  end
8
8
 
9
9
  def counter_to_s(counter)
10
- DDMetrics::Table.new(table_for_counter(counter)).to_s
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
- headers = ['', 'count', 'min', '.50', '.90', '.95', 'max', 'tot']
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
- [label_to_s(label), count.to_s] + [min, p50, p90, p95, max, tot].map { |r| format('%4.2f', r) }
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
- headers = ['', 'count']
38
+ header_labels = nil
39
+ headers = ['count']
41
40
 
42
41
  rows = counter.labels.map do |label|
43
- [label_to_s(label), counter.get(label).to_s]
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
@@ -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[0] + ' │ ' + values[1..-1].join(' ')
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 << '─' * column_lengths[0]
40
+ s << column_lengths.take(@num_headers).map { |l| '─' * l }.join('───')
35
41
  s << '─┼─'
36
- s << column_lengths[1..-1].map { |l| '─' * l }.join('───')
42
+ s << column_lengths.drop(@num_headers).map { |l| '─' * l }.join('───')
37
43
  end
38
44
  end
39
45
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DDMetrics
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
5
5
  end
@@ -97,10 +97,10 @@ describe DDMetrics::Counter do
97
97
 
98
98
  it 'returns table' do
99
99
  expected = <<~TABLE
100
- │ count
101
- ────────────┼──────
102
- filter=erb │ 2
103
- filter=haml │ 1
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
- before do
68
- summary.observe(2.1, filter: :erb)
69
- summary.observe(4.1, filter: :erb)
70
- summary.observe(5.3, filter: :haml)
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
- it 'returns table' do
74
- expected = <<~TABLE
75
- │ count min .50 .90 .95 max tot
76
- ────────────┼────────────────────────────────────────────────
77
- filter=erb │ 2 2.10 3.10 3.90 4.00 4.10 6.20
78
- filter=haml │ 1 5.30 5.30 5.30 5.30 5.30 5.30
79
- TABLE
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
- expect(subject.strip).to eq(expected.strip)
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.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-01-07 00:00:00.000000000 Z
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.4
73
+ rubygems_version: 2.7.7
74
74
  signing_key:
75
75
  specification_version: 4
76
76
  summary: Non-timeseries measurements for Ruby programs