wtf-tools 1.0.3 → 1.0.4

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
  SHA1:
3
- metadata.gz: cd814bb3d6c501937b14cc58895910ecc022e500
4
- data.tar.gz: 8035edd40c08bf9b4c5c6ee3f99f5cb381a9c3ed
3
+ metadata.gz: f83d668d36c0ec083d81479f7a16b4e9c1419ace
4
+ data.tar.gz: 7dc918cbf1e1c67006836b7a84a04943219fac23
5
5
  SHA512:
6
- metadata.gz: ae70406ac25e7093a5953bce47b92a582270d6e74e26d27154287b7c23a2aafe8f2512a75ec350c452d1e17b500f50a6f20e9e86c90d583df3dc83c5daeefb5c
7
- data.tar.gz: e737a3e0126265eac0cd0cba6640556b0374c19a3e67b7c0adcd1ac89086a4fb3ab5f15d44e1303d0fd31fbf1fd949f1dd5635744399b883c8f4a440055fb52d
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 attributs: #<MyClass id: 1234>
45
-
46
- Output control
47
- :puts to STDOUT (default)
48
- :file to a separate file in configured location
49
- :error raise the string containing data as exception
50
- ```
51
-
52
- ---
53
-
54
- ### Code timing
55
-
56
- ```ruby
57
- class MyClass
58
- def run_something
59
- WTF.time {
60
- # your code
61
- }
62
- end
63
- end
64
- ```
65
-
66
- Output:
67
-
68
- ```
69
- WTF (my_class/run_something:3): 0.001
70
- ```
71
-
72
- ---
73
-
74
- ### Method tracking
75
-
76
- ```ruby
77
- class MyClass
78
- def run_something
79
- WTF.track(self)
80
- # lots of code
81
- WTF.track_finish
82
- end
83
- end
84
- ```
85
-
86
- Additionally, extra classes/modules can be given:
87
-
88
- ```
89
- WTF.track(self, OtherClass, Helpers)
90
- ```
91
-
92
- This will create a CSV file in configured location, containing profiling info.
93
- Profiling happens only in the methods of the calling class, and any other given class.
94
-
95
- How it works: every method in `MyClass` and `OtherClass` is overridden, adding resource measuring code.
96
- All calls to those methods from the code between `track` and `track_finish` are measured (time and memory).
97
- Sum amounts are written as CSV file, sorted by total time used.
98
-
99
- Example output:
100
-
101
- ```csv
102
- class,method,count,time,heap_mb
103
- ,top,0,0.948,0.0
104
- Overview,some_helper,16408,0.351,0.0
105
- Overview,my_records,28,0.172,0.0
106
- Overview,load_data,1,0.166,0.0
107
- ...
108
- ```
109
-
110
- *Warning:* tracking method calls adds time overhead (somewhere from 10% to 3x, depending on number of times the methods were called).
111
-
112
- ---
113
-
114
- ### SQL tracking
115
-
116
- ```ruby
117
- class MyClass
118
- def run_something
119
- WTF.sql %q{SELECT * FROM `my_records` WHERE `attribute`='value' AND `etc`}
120
- WTF.sql /^UPDATE `my_records` SET .*?`some_values`=/, size: 10
121
- # lots of code
122
- end
123
- end
124
- ```
125
-
126
- 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.
127
-
128
- ---
129
-
130
-
131
- Configuration
132
- -------------
133
-
134
- Configure WTF before using the above-mentioned facilities.
135
- Rails initializers directory is a good place to put it.
136
- Subkeys of `output` must be lambdas taking one string argument. They are merged into default output options.
137
-
138
- ```ruby
139
- WTF.options = {
140
- files: "#{Rails.root}/log/wtf",
141
- output: {
142
- default: ->(data) { Rails.logger.info(data) },
143
- redis: ->(data) { Redis.new.rpush(:wtf, data) },
144
- }
145
- }
146
-
147
- require 'yaml' # to use :yaml option, etc
148
- ```
149
-
150
- *Requirement:* Ruby 2.0, because the technique used involves module `prepend`-ing, which is not available in Ruby 1.9.
151
-
152
- ---
153
-
154
- License
155
- -------
156
-
157
- This is released under the [MIT License](http://www.opensource.org/licenses/MIT).
158
-
159
- Sponsors
160
- -------
161
-
162
- This gem is sponsored and used by [SameSystem](http://www.samesystem.com)
163
-
164
- ![SameSystem](http://www.samesystem.com/assets/logo_small.png)
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
@@ -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