public
Rubygem
Description: simple database query profiling tool
Clone URL: git://github.com/quake/db_profiling.git
display detail app call stack
quake (author)
Wed Jun 11 23:42:22 -0700 2008
commit  3c9c29ffdad288d53f0c149accededa9c8d1c690
tree    7396cf4103350aef5546f85cbdfbb2b633d85af4
parent  6ff72471db45e79222440032046be9a7eb66e55e
...
1
2
3
 
4
5
6
...
1
2
 
3
4
5
6
0
@@ -1,6 +1,6 @@
0
 Gem::Specification.new do |s|
0
   s.name = 'db_profiling'
0
- s.version = '0.0.2'
0
+ s.version = '0.0.3'
0
   s.date = '2008-06-11'
0
   
0
   s.summary = "simple database query profiling tool"
...
20
21
22
23
 
24
25
 
26
27
28
...
37
38
39
 
 
 
 
40
41
42
...
20
21
22
 
23
24
 
25
26
27
28
...
37
38
39
40
41
42
43
44
45
46
0
@@ -20,9 +20,9 @@ ActiveRecord::ConnectionAdapters::QueryCache.module_eval do
0
   
0
   def cache_sql_with_stats(sql, &block)
0
     if @query_cache.has_key?(sql)
0
- @@stats_hits << sql
0
+ @@stats_hits << [sql, extract_app_caller]
0
     else
0
- @@stats_misses << sql
0
+ @@stats_misses << [sql, extract_app_caller]
0
     end
0
     bytes = 0
0
     rows = cache_sql_without_stats(sql, &block)
0
@@ -37,6 +37,10 @@ ActiveRecord::ConnectionAdapters::QueryCache.module_eval do
0
     rows
0
   end
0
   alias_method_chain :cache_sql, :stats
0
+
0
+ def extract_app_caller
0
+ caller.select {|s| s.index("#{RAILS_ROOT}/app") == 0}
0
+ end
0
 end
0
 
0
 ActionController::Base.module_eval do
...
6
7
8
9
 
10
11
12
 
13
14
15
 
 
16
17
18
...
6
7
8
 
9
10
11
 
12
13
 
 
14
15
16
17
18
0
@@ -6,13 +6,13 @@ module JavaEye
0
         <<HTML
0
   <div id="db_profiling" style="background:pink;color:black;position:absolute;top:16px;left:25%;padding:0.5em;border: 2px solid red;z-index:999;text-align:left;">
0
       <strong>
0
- Queries: <a href="#" onclick="$('cache_hits').toggle();return false;">#{stats[:hits].size}</a> / <a href="#" onclick="$('cache_misses').toggle();return false;">#{stats[:misses].size}</a> / #{number_to_percentage((stats[:hits].size.to_f / (stats[:queries])) * 100, :precision => 0)} |
0
+ Queries: <a href="#" onclick="$('cache_hits').toggle();return false;" title="Query cache hits">#{stats[:hits].size}</a> / <a href="#" onclick="$('cache_misses').toggle();return false;" title="DB queries">#{stats[:misses].size}</a> / #{number_to_percentage((stats[:hits].size.to_f / (stats[:queries])) * 100, :precision => 0)} |
0
         Rows: #{stats[:rows]} |
0
         Transfer: #{sprintf("%.1fk", stats[:bytes].to_f / 1024)} |
0
- <a href="#" onclick="$('db_profiling').remove();return false;" title="close">[X]</a>
0
+ <a href="#" onclick="$('db_profiling').remove();return false;" title="Close">[X]</a>
0
       </strong>
0
- <ul id="cache_hits" style="text-align:left;display:none;"><li>#{stats[:hits].join("</li><li>")}</li></ul>
0
- <ul id="cache_misses" style="text-align:left;display:none;"><li>#{stats[:misses].join("</li><li>")}</li></ul>
0
+ <ul id="cache_hits" style="text-align:left;display:none;">#{stats[:hits].inject("") {|output, s| output << "<li title='Click to display detail' onclick='$(this).next().toggle();return false;' style='cursor: pointer'>#{s[0]}</li><li style='display:none;list-style:none;'>#{s[1].join('<br/>')}</li>" }}</ul>
0
+ <ul id="cache_misses" style="text-align:left;display:none;">#{stats[:misses].inject("") {|output, s| output << "<li title='Click to display detail' onclick='$(this).next().toggle();return false;' style='cursor: pointer'>#{s[0]}</li><li style='display:none;list-style:none;'>#{s[1].join('<br/>')}</li>" }}</ul>
0
   </div>
0
 HTML
0
       end

Comments

    No one has commented yet.