wtf-tools 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39cd4bdb18179b654c8c89627596eba83ef1bb93
4
- data.tar.gz: b55d4b4ddb008660477c7c54a3124299b50f8380
3
+ metadata.gz: 8b03d032d5d09b5261862248f5cc65b8e4932d16
4
+ data.tar.gz: dcfd4c3e52e98bedbd466691a2d06bd4d5b70e51
5
5
  SHA512:
6
- metadata.gz: 3fe5a3c452e36a089d9f54f94f2e082e3453bf9f2164ea91d28a58c3b725d24b7c18c8935e914890ab830374305cca3cb6d73add38cdbad12bc86191b6485b13
7
- data.tar.gz: b3301c939c79f6dcf23ad3060908e0555255bd517e3f71a129bc26f57a26ec4c3cdde88643f2828bf607ff49c18038420667dcc8782937cfb61af39bbe5bdce2
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 :yaml option is used with `WTF?`, we expect that `YAML` is already loaded.
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, OtherClass)
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 timing code.
86
- All calls to those methods from the code between `track` and `track_finish` are measured (time and memory),
87
- and sum amounts are output at the end, sorted by total time used.
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
- Requirements: Ruby 2.0, because the technique used involves module `prepend`-ing, which is not available in Ruby 1.9.
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 %q{UPDATE `my_records` SET `some_values`=NULL}
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 initializer dir is a good place for it.
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
+ ![SameSystem](http://www.samesystem.com/assets/logo_small.png)
@@ -30,8 +30,8 @@ module WTF
30
30
  WTF::MethodTracker.finish
31
31
  end
32
32
 
33
- def sql(sql)
34
- WTF::QueryTracker.start_tracking(sql)
33
+ def sql(*args)
34
+ WTF::QueryTracker.start_tracking(*args)
35
35
  end
36
36
 
37
37
  def time(*args)
@@ -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 :trackable
6
+ attr_reader :trackables
5
7
 
6
- def start_tracking(sql)
7
- if @trackable.nil?
8
+ def start_tracking(pattern, options = {})
9
+ if @trackables.nil?
8
10
  prepare_hook
9
- @trackable = {}
11
+ @trackables = []
10
12
  end
11
- @trackable[sql] = true
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
- if trackable[sql]
28
- WTF::Dumper.new(:sql, sql, *caller.take(30), :line)
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'wtf-tools'
3
- s.version = '1.0.0'
3
+ s.version = '1.0.1'
4
4
  s.date = '2014-10-14'
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.required_ruby_version = Gem::Requirement.new(">= 2.0.0")
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.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.2.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