Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added basic prepared statement support, started using a pre gem

  • Loading branch information...
commit cff6e78b3a0f9cf378ca91d4277d209afa2cd4ac 1 parent e84e0a8
@SamSaffron authored
View
3  Ruby/CHANGELOG
@@ -44,3 +44,6 @@
* Added option to disable profiler for the current session (pp=disable / pp=enable)
* yajl compatability contributed by Sven Riedel
+10-August-2012 - Sam
+
+ * Added basic prepared statement profiling for postgres
View
45 Ruby/lib/patches/sql_patches.rb
@@ -91,6 +91,23 @@ def each(*args, &blk)
class PG::Connection
alias_method :exec_without_profiling, :exec
alias_method :async_exec_without_profiling, :async_exec
+ alias_method :exec_prepared_without_profiling, :exec_prepared
+ alias_method :send_query_prepared_without_profiling, :send_query_prepared
+ alias_method :prepare_without_profiling, :prepare
+
+ def prepare(*args,&blk)
+ current = ::Rack::MiniProfiler.current
+ return prepare_without_profiling(*args,&blk) unless current
+
+ @prepare_map ||= {}
+ @prepare_map[args[0]] = args[1]
+
+ # dont leak more than 10k ever
+ @prepare_map = {} if @prepare_map.length > 10000
+
+ prepare_without_profiling(*args,&blk)
+
+ end
def exec(*args,&blk)
current = ::Rack::MiniProfiler.current
@@ -104,6 +121,34 @@ def exec(*args,&blk)
result
end
+ def exec_prepared(*args,&blk)
+ current = ::Rack::MiniProfiler.current
+ return exec_prepared_without_profiling(*args,&blk) unless current
+
+ start = Time.now
+ result = exec_prepared_without_profiling(*args,&blk)
+ elapsed_time = ((Time.now - start).to_f * 1000).round(1)
+ mapped = args[0]
+ mapped = @prepare_map[mapped] || args[0] if @prepare_map
+ result.instance_variable_set("@miniprofiler_sql_id", ::Rack::MiniProfiler.record_sql(mapped, elapsed_time))
+
+ result
+ end
+
+ def send_query_prepared(*args,&blk)
+ current = ::Rack::MiniProfiler.current
+ return send_query_prepared_without_profiling(*args,&blk) unless current
+
+ start = Time.now
+ result = send_query_prepared_without_profiling(*args,&blk)
+ elapsed_time = ((Time.now - start).to_f * 1000).round(1)
+ mapped = args[0]
+ mapped = @prepare_map[mapped] || args[0] if @prepare_map
+ result.instance_variable_set("@miniprofiler_sql_id", ::Rack::MiniProfiler.record_sql(mapped, elapsed_time))
+
+ result
+ end
+
def async_exec(*args,&blk)
current = ::Rack::MiniProfiler.current
return exec_without_profiling(*args,&blk) unless current
View
2  Ruby/rack-mini-profiler.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = "rack-mini-profiler"
- s.version = "0.1.10"
+ s.version = "0.1.11.pre"
s.summary = "Profiles loading speed for rack applications."
s.authors = ["Aleks Totic","Sam Saffron", "Robin Ward"]
s.description = "Page loading speed displayed on every page. Optimize while you develop, performance is a feature."
Please sign in to comment.
Something went wrong with that request. Please try again.