wtf-tools 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 +4 -4
- data/README.md +30 -10
- data/lib/wtf-tools.rb +2 -2
- data/lib/wtf/query_tracker.rb +22 -7
- data/wtf-tools.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b03d032d5d09b5261862248f5cc65b8e4932d16
|
4
|
+
data.tar.gz: dcfd4c3e52e98bedbd466691a2d06bd4d5b70e51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00326e4785fcbb49bb840148ea29b82f6be03fe967b910f97aea15203a499251873b2603c0b99a62aeffe3fc4c9c69014fb73db3c24fbc778804cd9d61f648fe
|
7
|
+
data.tar.gz: 9ccf0185977fc76a51582adb8c78fac32db6fa149ca4ed35a65f047b1c3dc4def4a2af0314ca7f1b802d9c370e57fa072af790f6409e7d6662c95973febaa776
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ Some tools for debugging and profiling Ruby on Rails projects. Included:
|
|
9
9
|
* SQL tracker - detect where exactly given SQL query originated from
|
10
10
|
|
11
11
|
User is responsible for requiring gems necessary for rendering output.
|
12
|
-
For example, when
|
12
|
+
For example, when `:yaml` option is used with `WTF?`, we expect that `YAML` is already loaded.
|
13
13
|
Library requirements for specific options are documented below.
|
14
14
|
|
15
15
|
Usage examples
|
@@ -65,6 +65,12 @@ class MyClass
|
|
65
65
|
end
|
66
66
|
```
|
67
67
|
|
68
|
+
Output:
|
69
|
+
|
70
|
+
```
|
71
|
+
WTF (my_class/run_something:3): 0.001
|
72
|
+
```
|
73
|
+
|
68
74
|
---
|
69
75
|
|
70
76
|
### Method tracking
|
@@ -72,19 +78,25 @@ end
|
|
72
78
|
```ruby
|
73
79
|
class MyClass
|
74
80
|
def run_something
|
75
|
-
WTF.track(self
|
81
|
+
WTF.track(self)
|
76
82
|
# lots of code
|
77
83
|
WTF.track_finish
|
78
84
|
end
|
79
85
|
end
|
80
86
|
```
|
81
87
|
|
88
|
+
Additionally, extra classes/modules can be given:
|
89
|
+
|
90
|
+
```
|
91
|
+
WTF.track(self, OtherClass, Helpers)
|
92
|
+
```
|
93
|
+
|
82
94
|
This will create a CSV file in configured location, containing profiling info.
|
83
|
-
Profiling happens only in the methods of the calling class, and other given class.
|
95
|
+
Profiling happens only in the methods of the calling class, and any other given class.
|
84
96
|
|
85
|
-
How it works: every method in `MyClass` and `OtherClass` is overridden, adding resource
|
86
|
-
All calls to those methods from the code between `track` and `track_finish` are measured (time and memory)
|
87
|
-
|
97
|
+
How it works: every method in `MyClass` and `OtherClass` is overridden, adding resource measuring code.
|
98
|
+
All calls to those methods from the code between `track` and `track_finish` are measured (time and memory).
|
99
|
+
Sum amounts are written as CSV file, sorted by total time used.
|
88
100
|
|
89
101
|
Example output:
|
90
102
|
|
@@ -97,8 +109,7 @@ Overview,load_data,1,0.166,0.0
|
|
97
109
|
...
|
98
110
|
```
|
99
111
|
|
100
|
-
|
101
|
-
Warning: tracking method calls adds time overhead (somewhere from 10% to 3x, depending on number of times the methods were called).
|
112
|
+
*Warning:* tracking method calls adds time overhead (somewhere from 10% to 3x, depending on number of times the methods were called).
|
102
113
|
|
103
114
|
---
|
104
115
|
|
@@ -108,7 +119,7 @@ Warning: tracking method calls adds time overhead (somewhere from 10% to 3x, dep
|
|
108
119
|
class MyClass
|
109
120
|
def run_something
|
110
121
|
WTF.sql %q{SELECT * FROM `my_records` WHERE `attribute`='value' AND `etc`}
|
111
|
-
WTF.sql
|
122
|
+
WTF.sql /^UPDATE `my_records` SET .*?`some_values`=/, size: 10
|
112
123
|
# lots of code
|
113
124
|
end
|
114
125
|
end
|
@@ -122,7 +133,7 @@ This will add a `WTF?`-style dump in the default location, containing stacktrace
|
|
122
133
|
Configuration
|
123
134
|
-------------
|
124
135
|
|
125
|
-
Configure WTF before using the above-mentioned facilities. Rails
|
136
|
+
Configure WTF before using the above-mentioned facilities. Rails initializers directory is a good place for it.
|
126
137
|
|
127
138
|
```ruby
|
128
139
|
WTF.options = {
|
@@ -134,9 +145,18 @@ WTF.options = {
|
|
134
145
|
require 'yaml' # to use :yaml option, etc
|
135
146
|
```
|
136
147
|
|
148
|
+
*Requirement:* Ruby 2.0, because the technique used involves module `prepend`-ing, which is not available in Ruby 1.9.
|
149
|
+
|
137
150
|
---
|
138
151
|
|
139
152
|
License
|
140
153
|
-------
|
141
154
|
|
142
155
|
This is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
156
|
+
|
157
|
+
Sponsors
|
158
|
+
-------
|
159
|
+
|
160
|
+
This gem is sponsored and used by [SameSystem](http://www.samesystem.com)
|
161
|
+
|
162
|
+

|
data/lib/wtf-tools.rb
CHANGED
data/lib/wtf/query_tracker.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
module WTF
|
2
2
|
module QueryTracker
|
3
|
+
Trackable = Struct.new(:pattern, :options)
|
4
|
+
|
3
5
|
class << self
|
4
|
-
attr_reader :
|
6
|
+
attr_reader :trackables
|
5
7
|
|
6
|
-
def start_tracking(
|
7
|
-
if @
|
8
|
+
def start_tracking(pattern, options = {})
|
9
|
+
if @trackables.nil?
|
8
10
|
prepare_hook
|
9
|
-
@
|
11
|
+
@trackables = []
|
10
12
|
end
|
11
|
-
@
|
13
|
+
@trackables << Trackable.new(pattern, options)
|
12
14
|
end
|
13
15
|
|
14
16
|
def prepare_hook
|
@@ -24,8 +26,21 @@ module WTF
|
|
24
26
|
end
|
25
27
|
|
26
28
|
def on_sql(sql)
|
27
|
-
|
28
|
-
|
29
|
+
trackables.each do |it|
|
30
|
+
if match(it.pattern, sql)
|
31
|
+
WTF::Dumper.new(:sql, sql, *caller.take(it.options[:size] || 30), :line)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def match(pattern, sql)
|
37
|
+
case pattern
|
38
|
+
when Regexp
|
39
|
+
pattern.match(sql)
|
40
|
+
when String
|
41
|
+
pattern == sql
|
42
|
+
when Proc
|
43
|
+
pattern.call(sql)
|
29
44
|
end
|
30
45
|
end
|
31
46
|
end
|
data/wtf-tools.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wtf-tools
|
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
|
- Remigijus Jodelis
|
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
66
|
version: '0'
|
67
67
|
requirements: []
|
68
68
|
rubyforge_project:
|
69
|
-
rubygems_version: 2.
|
69
|
+
rubygems_version: 2.4.5
|
70
70
|
signing_key:
|
71
71
|
specification_version: 4
|
72
72
|
summary: tools for debugging and profiling Ruby on Rails projects
|