wtf-tools 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +22 -22
- data/README.md +165 -164
- data/Rakefile +8 -8
- data/example/dump.rb +30 -30
- data/example/timing.rb +20 -20
- data/example/tracking.rb +32 -32
- data/lib/wtf-tools.rb +69 -69
- data/lib/wtf/dumper.rb +144 -113
- data/lib/wtf/method_tracker.rb +90 -90
- data/lib/wtf/query_tracker.rb +48 -48
- data/wtf-tools.gemspec +24 -24
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f83d668d36c0ec083d81479f7a16b4e9c1419ace
|
4
|
+
data.tar.gz: 7dc918cbf1e1c67006836b7a84a04943219fac23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78c9d15e95e10128fbfa4e9509dcc0333989499b007bfb0ad8e89247c3a0727bdbd1ffe0a638b23ec8f7be3583c6b10f5f86b32f20b101a2863e44919f9e225d
|
7
|
+
data.tar.gz: a1f03bdc671b5bdd7290b37cec42bfbba05cc79de7c70686bb7f133c7e93cf77b87362931a9c8215bf19f3d5787ee2b5b1f8c4589da277e99dd2fe1b25b124ab
|
data/LICENSE
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2014 Remigijus Jodelis
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
22
|
-
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Remigijus Jodelis
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
CHANGED
@@ -1,164 +1,165 @@
|
|
1
|
-
wtf-tools
|
2
|
-
=========
|
3
|
-
|
4
|
-
Some tools for debugging and profiling Ruby on Rails projects. Included:
|
5
|
-
|
6
|
-
* data dumper
|
7
|
-
* code timing tool
|
8
|
-
* method tracker - a kind of middle ground between simple timing and full profiling
|
9
|
-
* SQL tracker - detect where exactly given SQL query originated from
|
10
|
-
|
11
|
-
User is responsible for requiring gems necessary for rendering output.
|
12
|
-
For example, when `:yaml` option is used with `WTF?`, we expect that `YAML` is already loaded.
|
13
|
-
Library requirements for specific options are documented below.
|
14
|
-
|
15
|
-
Usage examples
|
16
|
-
--------------
|
17
|
-
|
18
|
-
### Data dumping
|
19
|
-
|
20
|
-
```ruby
|
21
|
-
WTF? my_var # basic
|
22
|
-
WTF? my_var, other_var, { some: data }, :pp # more data, option: pretty-print
|
23
|
-
WTF? :label, records, :bare, :time # multiple options given
|
24
|
-
data.wtf(:time).some_method # inline call
|
25
|
-
```
|
26
|
-
|
27
|
-
Supported options
|
28
|
-
|
29
|
-
```
|
30
|
-
Prefix
|
31
|
-
(default) WTF (my_file_name/method_name:227):
|
32
|
-
:np no default prefix
|
33
|
-
:nl new line before the record
|
34
|
-
:time with timestamp: [2014-10-28 12:33:11 +0200]
|
35
|
-
|
36
|
-
Formatting
|
37
|
-
(default) simple Ruby inspect
|
38
|
-
:pp pretty-print, require 'pp'
|
39
|
-
:yaml YAML format, require 'yaml'
|
40
|
-
:json JSON format, require 'json'
|
41
|
-
:csv CSV format, require 'csv'
|
42
|
-
:text simple Ruby to_s
|
43
|
-
:line modifier, each object in separate line
|
44
|
-
:bare modifier, ActiveRecord with just id
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
:
|
49
|
-
:
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
end
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
,
|
104
|
-
|
105
|
-
Overview,
|
106
|
-
Overview,
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
WTF.sql
|
121
|
-
|
122
|
-
|
123
|
-
end
|
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
|
-
|
1
|
+
wtf-tools
|
2
|
+
=========
|
3
|
+
|
4
|
+
Some tools for debugging and profiling Ruby on Rails projects. Included:
|
5
|
+
|
6
|
+
* data dumper
|
7
|
+
* code timing tool
|
8
|
+
* method tracker - a kind of middle ground between simple timing and full profiling
|
9
|
+
* SQL tracker - detect where exactly given SQL query originated from
|
10
|
+
|
11
|
+
User is responsible for requiring gems necessary for rendering output.
|
12
|
+
For example, when `:yaml` option is used with `WTF?`, we expect that `YAML` is already loaded.
|
13
|
+
Library requirements for specific options are documented below.
|
14
|
+
|
15
|
+
Usage examples
|
16
|
+
--------------
|
17
|
+
|
18
|
+
### Data dumping
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
WTF? my_var # basic
|
22
|
+
WTF? my_var, other_var, { some: data }, :pp # more data, option: pretty-print
|
23
|
+
WTF? :label, records, :bare, :time # multiple options given
|
24
|
+
data.wtf(:time).some_method # inline call
|
25
|
+
```
|
26
|
+
|
27
|
+
Supported options
|
28
|
+
|
29
|
+
```
|
30
|
+
Prefix
|
31
|
+
(default) WTF (my_file_name/method_name:227):
|
32
|
+
:np no default prefix
|
33
|
+
:nl new line before the record
|
34
|
+
:time with timestamp: [2014-10-28 12:33:11 +0200]
|
35
|
+
|
36
|
+
Formatting
|
37
|
+
(default) simple Ruby inspect
|
38
|
+
:pp pretty-print, require 'pp'
|
39
|
+
:yaml YAML format, require 'yaml'
|
40
|
+
:json JSON format, require 'json'
|
41
|
+
:csv CSV format, require 'csv'
|
42
|
+
:text simple Ruby to_s
|
43
|
+
:line modifier, each object in separate line
|
44
|
+
:bare modifier, ActiveRecord with just id attributes: #<MyClass id: 1234>
|
45
|
+
:name like :line, but with names taken from source file
|
46
|
+
|
47
|
+
Output control
|
48
|
+
:puts to STDOUT (default)
|
49
|
+
:file to a separate file in configured location
|
50
|
+
:error raise the string containing data as exception
|
51
|
+
```
|
52
|
+
|
53
|
+
---
|
54
|
+
|
55
|
+
### Code timing
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
class MyClass
|
59
|
+
def run_something
|
60
|
+
WTF.time {
|
61
|
+
# your code
|
62
|
+
}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
Output:
|
68
|
+
|
69
|
+
```
|
70
|
+
WTF (my_class/run_something:3): 0.001
|
71
|
+
```
|
72
|
+
|
73
|
+
---
|
74
|
+
|
75
|
+
### Method tracking
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
class MyClass
|
79
|
+
def run_something
|
80
|
+
WTF.track(self)
|
81
|
+
# lots of code
|
82
|
+
WTF.track_finish
|
83
|
+
end
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
Additionally, extra classes/modules can be given:
|
88
|
+
|
89
|
+
```
|
90
|
+
WTF.track(self, OtherClass, Helpers)
|
91
|
+
```
|
92
|
+
|
93
|
+
This will create a CSV file in configured location, containing profiling info.
|
94
|
+
Profiling happens only in the methods of the calling class, and any other given class.
|
95
|
+
|
96
|
+
How it works: every method in `MyClass` and `OtherClass` is overridden, adding resource measuring code.
|
97
|
+
All calls to those methods from the code between `track` and `track_finish` are measured (time and memory).
|
98
|
+
Sum amounts are written as CSV file, sorted by total time used.
|
99
|
+
|
100
|
+
Example output:
|
101
|
+
|
102
|
+
```csv
|
103
|
+
class,method,count,time,heap_mb
|
104
|
+
,top,0,0.948,0.0
|
105
|
+
Overview,some_helper,16408,0.351,0.0
|
106
|
+
Overview,my_records,28,0.172,0.0
|
107
|
+
Overview,load_data,1,0.166,0.0
|
108
|
+
...
|
109
|
+
```
|
110
|
+
|
111
|
+
*Warning:* tracking method calls adds time overhead (somewhere from 10% to 3x, depending on number of times the methods were called).
|
112
|
+
|
113
|
+
---
|
114
|
+
|
115
|
+
### SQL tracking
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
class MyClass
|
119
|
+
def run_something
|
120
|
+
WTF.sql %q{SELECT * FROM `my_records` WHERE `attribute`='value' AND `etc`}
|
121
|
+
WTF.sql /^UPDATE `my_records` SET .*?`some_values`=/, size: 10
|
122
|
+
# lots of code
|
123
|
+
end
|
124
|
+
end
|
125
|
+
```
|
126
|
+
|
127
|
+
This will add a `WTF?`-style dump in the default location, containing stacktrace where given SQL statement was generated. SQL must match exactly as strings.
|
128
|
+
|
129
|
+
---
|
130
|
+
|
131
|
+
|
132
|
+
Configuration
|
133
|
+
-------------
|
134
|
+
|
135
|
+
Configure WTF before using the above-mentioned facilities.
|
136
|
+
Rails initializers directory is a good place to put it.
|
137
|
+
Subkeys of `output` must be lambdas taking one string argument. They are merged into default output options.
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
WTF.options = {
|
141
|
+
files: "#{Rails.root}/log/wtf",
|
142
|
+
output: {
|
143
|
+
default: ->(data) { Rails.logger.info(data) },
|
144
|
+
redis: ->(data) { Redis.new.rpush(:wtf, data) },
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
148
|
+
require 'yaml' # to use :yaml option, etc
|
149
|
+
```
|
150
|
+
|
151
|
+
*Requirement:* Ruby 2.0, because the technique used involves module `prepend`-ing, which is not available in Ruby 1.9.
|
152
|
+
|
153
|
+
---
|
154
|
+
|
155
|
+
License
|
156
|
+
-------
|
157
|
+
|
158
|
+
This is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
159
|
+
|
160
|
+
Sponsors
|
161
|
+
-------
|
162
|
+
|
163
|
+
This gem is sponsored and used by [SameSystem](http://www.samesystem.com)
|
164
|
+
|
165
|
+
![SameSystem](http://www.samesystem.com/assets/logo_small.png)
|
data/Rakefile
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require 'rake/testtask'
|
2
|
-
|
3
|
-
Rake::TestTask.new do |t|
|
4
|
-
t.libs << 'test'
|
5
|
-
end
|
6
|
-
|
7
|
-
desc "Run tests"
|
8
|
-
task :default => :test
|
1
|
+
require 'rake/testtask'
|
2
|
+
|
3
|
+
Rake::TestTask.new do |t|
|
4
|
+
t.libs << 'test'
|
5
|
+
end
|
6
|
+
|
7
|
+
desc "Run tests"
|
8
|
+
task :default => :test
|
data/example/dump.rb
CHANGED
@@ -1,30 +1,30 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'wtf-tools'
|
3
|
-
require 'pp'
|
4
|
-
require 'json'
|
5
|
-
require 'yaml'
|
6
|
-
require 'active_support/logger'
|
7
|
-
require 'fileutils'
|
8
|
-
|
9
|
-
WTF.options = {
|
10
|
-
files: './wtf',
|
11
|
-
output: {
|
12
|
-
default: ActiveSupport::Logger.new('./example.log'),
|
13
|
-
}
|
14
|
-
}
|
15
|
-
|
16
|
-
data = { 'some' => { 'nested' => { 'data' => 17 } }, :question => %w(life universe and everything), :answer => 42 }
|
17
|
-
|
18
|
-
WTF? Time.now
|
19
|
-
|
20
|
-
WTF? :label, "string", 17, 2.0001, :time, :nl
|
21
|
-
|
22
|
-
WTF? 'label', "string", 17, 2.0001, :time, :line, :nl
|
23
|
-
|
24
|
-
WTF? data, :pp, :nl
|
25
|
-
|
26
|
-
WTF? data, :json, :nl
|
27
|
-
|
28
|
-
WTF? data, :yaml, :np, :file
|
29
|
-
|
30
|
-
data.wtf(:file).size
|
1
|
+
require 'rubygems'
|
2
|
+
require 'wtf-tools'
|
3
|
+
require 'pp'
|
4
|
+
require 'json'
|
5
|
+
require 'yaml'
|
6
|
+
require 'active_support/logger'
|
7
|
+
require 'fileutils'
|
8
|
+
|
9
|
+
WTF.options = {
|
10
|
+
files: './wtf',
|
11
|
+
output: {
|
12
|
+
default: ActiveSupport::Logger.new('./example.log'),
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
data = { 'some' => { 'nested' => { 'data' => 17 } }, :question => %w(life universe and everything), :answer => 42 }
|
17
|
+
|
18
|
+
WTF? Time.now
|
19
|
+
|
20
|
+
WTF? :label, "string", 17, 2.0001, :time, :nl
|
21
|
+
|
22
|
+
WTF? 'label', "string", 17, 2.0001, :time, :line, :nl
|
23
|
+
|
24
|
+
WTF? data, :pp, :nl
|
25
|
+
|
26
|
+
WTF? data, :json, :nl
|
27
|
+
|
28
|
+
WTF? data, :yaml, :np, :file
|
29
|
+
|
30
|
+
data.wtf(:file).size
|