coverband 0.0.24 → 0.0.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +35 -19
- data/lib/coverband/base.rb +22 -8
- data/lib/coverband/redis_store.rb +1 -1
- data/lib/coverband/tasks.rb +15 -0
- data/lib/coverband/version.rb +1 -1
- metadata +24 -48
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e9024d421423749a38d48b51ffb2e649e4ef7b12
|
4
|
+
data.tar.gz: f2d9072445beb98a2399e82b282b321edbad21c1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bc67df5a997a1a11baed1f28641e19dfd72d7430fd64f64acb79d2ad67baa3e09a29a9112f5049b4221ccc2a7c805777a9af7bed85744e9a8d82d9f86517562c
|
7
|
+
data.tar.gz: ef6211e1506103bf8f7cce7efbad5580f9a58eeeb8c355bfc4a6f32e3f27b46dc9069a17fdb5ab51c1e877d3bc14af1845165fcc6ec8f11f46f061e91a8c285c
|
data/README.md
CHANGED
@@ -72,11 +72,7 @@ You need to configure cover band you can either do that passing in all configura
|
|
72
72
|
```ruby
|
73
73
|
require 'json'
|
74
74
|
|
75
|
-
baseline =
|
76
|
-
JSON.parse(File.read('./tmp/coverband_baseline.json'))
|
77
|
-
else
|
78
|
-
{}
|
79
|
-
end
|
75
|
+
baseline = Coverband.parse_baseline
|
80
76
|
|
81
77
|
Coverband.configure do |config|
|
82
78
|
config.root = Dir.pwd
|
@@ -86,15 +82,18 @@ Coverband.configure do |config|
|
|
86
82
|
config.coverage_baseline = baseline
|
87
83
|
config.root_paths = ['/app/']
|
88
84
|
config.ignore = ['vendor']
|
85
|
+
# Since rails and other frameworks lazy load code. I have found it is bad to allow
|
86
|
+
# initial requests to record with coverband. This ignores first 15 requests
|
87
|
+
config.startup_delay = 15
|
89
88
|
config.percentage = 60.0
|
90
89
|
if defined? Statsd
|
91
90
|
config.stats = Statsd.new('statsd.host.com', 8125)
|
92
91
|
end
|
93
|
-
config.verbose = true
|
92
|
+
config.verbose = Rails.env.production? ? false : true
|
94
93
|
end
|
95
94
|
```
|
96
95
|
|
97
|
-
Here is a alternative configuration example:
|
96
|
+
Here is a alternative configuration example, allowing for production and development settings:
|
98
97
|
|
99
98
|
```ruby
|
100
99
|
Coverband.configure do |config|
|
@@ -103,11 +102,8 @@ Coverband.configure do |config|
|
|
103
102
|
config.coverage_baseline = JSON.parse(File.read('./tmp/coverband_baseline.json'))
|
104
103
|
config.root_paths = ['/app/']
|
105
104
|
config.ignore = ['vendor']
|
106
|
-
|
107
|
-
|
108
|
-
# This allows 10 requests prior to trying to record any activitly.
|
109
|
-
config.startup_delay = 10
|
110
|
-
config.percentage = 15.0
|
105
|
+
config.startup_delay = Rails.env.production? ? 10 : 1
|
106
|
+
config.percentage = Rails.env.production? ? 15.0 : 100.0
|
111
107
|
end
|
112
108
|
```
|
113
109
|
|
@@ -167,7 +163,7 @@ For example if you had a base Resque class, you could use the `before_perform` a
|
|
167
163
|
|
168
164
|
```ruby
|
169
165
|
def before_perform(*args)
|
170
|
-
if (rand * 100.0)
|
166
|
+
if (rand * 100.0) <= Coverband.configuration.percentage
|
171
167
|
@@coverband ||= Coverband::Base.new
|
172
168
|
@recording_samples = true
|
173
169
|
@@coverband.start
|
@@ -225,18 +221,38 @@ Coverband::Reporter.clear_coverage(Redis.new(:host => 'target.com', :port => 678
|
|
225
221
|
You can also do this with the included rake tasks.
|
226
222
|
|
227
223
|
|
224
|
+
## Verbose debug mode for development
|
225
|
+
|
226
|
+
If you are trying to debug locally wondering what code is being run during a request. The verbose modes `config.verbose = true` and `config.verbose = 'debug'` can be useful. With true set it will output the number of lines executed per file, to the passed in log. The files are sorted from least used file to most active file. I have even run that mode in production without much of a problem. The debug verbose mode outputs both file usage and provides the number of calls per line of code. For example if you see something like below which indicates that the `application_helper` has 43150 lines executed. That might seem odd. Then looking at the breakdown of `application_helper` we can see that line `516` was executed 38,577 times. That seems bad, and is likely worth investigating perhaps memoizing or cacheing is required.
|
227
|
+
|
228
|
+
config.verbose = 'debug'
|
229
|
+
|
230
|
+
coverband file usage:
|
231
|
+
[["/Users/danmayer/projects/app_name/lib/facebook.rb", 6],
|
232
|
+
["/Users/danmayer/projects/app_name/app/models/some_modules.rb", 9],
|
233
|
+
...
|
234
|
+
["/Users/danmayer/projects/app_name/app/models/user.rb", 2606],
|
235
|
+
["/Users/danmayer/projects/app_name/app/helpers/application_helper.rb",
|
236
|
+
43150]]
|
237
|
+
|
238
|
+
file:
|
239
|
+
/Users/danmayer/projects/app_name/app/helpers/application_helper.rb =>
|
240
|
+
[[448, 1], [202, 1],
|
241
|
+
...
|
242
|
+
[517, 1617], [516, 38577]]
|
243
|
+
|
244
|
+
|
228
245
|
## TODO
|
229
246
|
|
230
|
-
*
|
231
|
-
|
232
|
-
* Fix performance by logging to files that purge later
|
233
|
-
* Add support for [zadd](http://redis.io/topics/data-types-intro) so one could determine single hits versus multiple hits on a line, letting us determine the most executed code in production.
|
234
|
-
* Add stats optional support on the number of total requests recorded
|
247
|
+
* Fix network performance by logging to files that purge later (far more time lost in set_trace_func than sending files, hence not a high priority)
|
248
|
+
* Add support for [zadd](http://redis.io/topics/data-types-intro) so one could determine single call versus multiple calls on a line, letting us determine the most executed code in production.
|
235
249
|
* Possibly add ability to record code run for a given route
|
236
250
|
* Improve client code api, around manual usage of sampling (like event usage)
|
237
251
|
* Provide a better lighter example app, to show how to use Coverband.
|
238
252
|
* blank rails app
|
239
|
-
* blank Sinatra app
|
253
|
+
* blank Sinatra app
|
254
|
+
* report on Coverband files that haven't recorded any coverage (find things like events and crons that aren't recording, or dead files)
|
255
|
+
* ability to change the cover band config at runtime by changing the config pushed to the Redis hash. In memory cache around the changes to only make that call periodically.
|
240
256
|
|
241
257
|
## Resources
|
242
258
|
|
data/lib/coverband/base.rb
CHANGED
@@ -6,7 +6,8 @@ module Coverband
|
|
6
6
|
@enabled = false
|
7
7
|
@tracer_set = false
|
8
8
|
@files = {}
|
9
|
-
@file_usage =
|
9
|
+
@file_usage = Hash.new(0)
|
10
|
+
@file_line_usage = {}
|
10
11
|
@startup_delay = Coverband.configuration.startup_delay
|
11
12
|
@ignore_patterns = Coverband.configuration.ignore
|
12
13
|
@sample_percentage = Coverband.configuration.percentage
|
@@ -83,11 +84,9 @@ module Coverband
|
|
83
84
|
def add_file(file, line)
|
84
85
|
if !file.match(/(\/gems\/|internal\:prelude)/) && file.match(@project_directory) && !@ignore_patterns.any?{|pattern| file.match(/#{pattern}/) }
|
85
86
|
if @verbose
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
@file_usage[file] = 1
|
90
|
-
end
|
87
|
+
@file_usage[file] += 1
|
88
|
+
@file_line_usage[file] = Hash.new(0) unless @file_line_usage.include?(file)
|
89
|
+
@file_line_usage[file][line] += 1
|
91
90
|
end
|
92
91
|
if @files.include?(file)
|
93
92
|
@files[file] << line unless @files.include?(line)
|
@@ -96,6 +95,15 @@ module Coverband
|
|
96
95
|
end
|
97
96
|
end
|
98
97
|
end
|
98
|
+
|
99
|
+
def output_file_line_usage
|
100
|
+
@logger.info "coverband debug coverband file:line usage:"
|
101
|
+
@file_line_usage.sort_by {|_key, value| value.length}.each do |pair|
|
102
|
+
file = pair.first
|
103
|
+
lines = pair.last
|
104
|
+
@logger.info "file: #{file} => #{lines.sort_by {|_key, value| value}}"
|
105
|
+
end
|
106
|
+
end
|
99
107
|
|
100
108
|
def report_coverage
|
101
109
|
unless @enabled
|
@@ -105,7 +113,12 @@ module Coverband
|
|
105
113
|
|
106
114
|
unset_tracer
|
107
115
|
|
108
|
-
|
116
|
+
if @verbose
|
117
|
+
@logger.info "coverband file usage: #{@file_usage.sort_by {|_key, value| value}.inspect}"
|
118
|
+
if @verbose=="debug"
|
119
|
+
output_file_line_usage
|
120
|
+
end
|
121
|
+
end
|
109
122
|
|
110
123
|
if @reporter
|
111
124
|
if @reporter.class.name.match(/redis/i)
|
@@ -115,7 +128,8 @@ module Coverband
|
|
115
128
|
time_spent = Time.now - before_time
|
116
129
|
@stats.timing "coverband.files.recorded_time", time_spent if @stats
|
117
130
|
@files = {}
|
118
|
-
|
131
|
+
@file_usage = Hash.new(0)
|
132
|
+
@file_line_usage = {}
|
119
133
|
end
|
120
134
|
elsif @verbose
|
121
135
|
@logger.info "coverage report: "
|
data/lib/coverband/tasks.rb
CHANGED
@@ -24,8 +24,23 @@ namespace :coverband do
|
|
24
24
|
}
|
25
25
|
end
|
26
26
|
|
27
|
+
###
|
28
|
+
# note: If have set a ton of simplecov filters you might want to override them and clear the filters or run the task below.
|
29
|
+
###
|
27
30
|
desc "report runtime coverband code coverage"
|
28
31
|
task :coverage => :environment do
|
32
|
+
Coverband::Reporter.report
|
33
|
+
end
|
34
|
+
|
35
|
+
def clear_simplecov_filters
|
36
|
+
if defined? SimpleCov
|
37
|
+
SimpleCov.filters.clear
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "report runtime coverband code coverage"
|
42
|
+
task :coverage_no_filters => :environment do
|
43
|
+
clear_simplecov_filters
|
29
44
|
Coverband::Reporter.report
|
30
45
|
end
|
31
46
|
|
data/lib/coverband/version.rb
CHANGED
metadata
CHANGED
@@ -1,142 +1,125 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coverband
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.26
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Dan Mayer
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-06-02 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '1.3'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '1.3'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: mocha
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- - ~>
|
45
|
+
- - "~>"
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: 0.14.0
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- - ~>
|
52
|
+
- - "~>"
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: 0.14.0
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: shoulda
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: rack
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - ">="
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - ">="
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: simplecov
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
|
-
- -
|
87
|
+
- - ">="
|
100
88
|
- !ruby/object:Gem::Version
|
101
89
|
version: '0'
|
102
90
|
type: :runtime
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
|
-
- -
|
94
|
+
- - ">="
|
108
95
|
- !ruby/object:Gem::Version
|
109
96
|
version: '0'
|
110
97
|
- !ruby/object:Gem::Dependency
|
111
98
|
name: json
|
112
99
|
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
100
|
requirements:
|
115
|
-
- -
|
101
|
+
- - ">="
|
116
102
|
- !ruby/object:Gem::Version
|
117
103
|
version: '0'
|
118
104
|
type: :runtime
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
107
|
requirements:
|
123
|
-
- -
|
108
|
+
- - ">="
|
124
109
|
- !ruby/object:Gem::Version
|
125
110
|
version: '0'
|
126
111
|
- !ruby/object:Gem::Dependency
|
127
112
|
name: redis
|
128
113
|
requirement: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
114
|
requirements:
|
131
|
-
- -
|
115
|
+
- - ">="
|
132
116
|
- !ruby/object:Gem::Version
|
133
117
|
version: '0'
|
134
118
|
type: :runtime
|
135
119
|
prerelease: false
|
136
120
|
version_requirements: !ruby/object:Gem::Requirement
|
137
|
-
none: false
|
138
121
|
requirements:
|
139
|
-
- -
|
122
|
+
- - ">="
|
140
123
|
- !ruby/object:Gem::Version
|
141
124
|
version: '0'
|
142
125
|
description: Rack middleware to help measure production code coverage
|
@@ -146,7 +129,7 @@ executables: []
|
|
146
129
|
extensions: []
|
147
130
|
extra_rdoc_files: []
|
148
131
|
files:
|
149
|
-
- .gitignore
|
132
|
+
- ".gitignore"
|
150
133
|
- Gemfile
|
151
134
|
- LICENSE
|
152
135
|
- LICENSE.txt
|
@@ -172,33 +155,26 @@ files:
|
|
172
155
|
homepage: ''
|
173
156
|
licenses:
|
174
157
|
- MIT
|
158
|
+
metadata: {}
|
175
159
|
post_install_message:
|
176
160
|
rdoc_options: []
|
177
161
|
require_paths:
|
178
162
|
- lib
|
179
163
|
required_ruby_version: !ruby/object:Gem::Requirement
|
180
|
-
none: false
|
181
164
|
requirements:
|
182
|
-
- -
|
165
|
+
- - ">="
|
183
166
|
- !ruby/object:Gem::Version
|
184
167
|
version: '0'
|
185
|
-
segments:
|
186
|
-
- 0
|
187
|
-
hash: 2870225562195560051
|
188
168
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
189
|
-
none: false
|
190
169
|
requirements:
|
191
|
-
- -
|
170
|
+
- - ">="
|
192
171
|
- !ruby/object:Gem::Version
|
193
172
|
version: '0'
|
194
|
-
segments:
|
195
|
-
- 0
|
196
|
-
hash: 2870225562195560051
|
197
173
|
requirements: []
|
198
174
|
rubyforge_project:
|
199
|
-
rubygems_version:
|
175
|
+
rubygems_version: 2.2.2
|
200
176
|
signing_key:
|
201
|
-
specification_version:
|
177
|
+
specification_version: 4
|
202
178
|
summary: Rack middleware to help measure production code coverage
|
203
179
|
test_files:
|
204
180
|
- test/fake_app/basic_rack.rb
|