peek-pg-1.3.0/0000755000175000017500000000000013161456577012744 5ustar rajudevrajudevpeek-pg-1.3.0/Rakefile0000644000175000017500000000003413161456577014406 0ustar rajudevrajudevrequire 'bundler/gem_tasks' peek-pg-1.3.0/Gemfile0000644000175000017500000000013413161456577014235 0ustar rajudevrajudevsource 'https://rubygems.org' # Specify your gem's dependencies in peek-pg.gemspec gemspec peek-pg-1.3.0/CHANGELOG.md0000644000175000017500000000103013161456577014547 0ustar rajudevrajudev# 1.0.0 - Initial release. # 1.1.0 - Query count and Query time are now threadsafe. # 1.2.0 - Use concurrent-ruby gem in favor of deprecated atomic gem. - [#4](https://github.com/peek/peek-pg/pull/4) [@lucasmazza](https://github.com/lucasmazza) - Instrument prepared statements. - [#5](https://github.com/peek/peek-pg/pull/5) [@lucasmazza](https://github.com/lucasmazza) # 1.3.0 - Use prepend to instrument Postgres queries `alias_method_chain` - [#8](https://github.com/peek/peek-pg/pull/5) [@8398a7](https://github.com/8398a7) peek-pg-1.3.0/app/0000755000175000017500000000000013161456577013524 5ustar rajudevrajudevpeek-pg-1.3.0/app/views/0000755000175000017500000000000013161456577014661 5ustar rajudevrajudevpeek-pg-1.3.0/app/views/peek/0000755000175000017500000000000013161456577015605 5ustar rajudevrajudevpeek-pg-1.3.0/app/views/peek/views/0000755000175000017500000000000013161456577016742 5ustar rajudevrajudevpeek-pg-1.3.0/app/views/peek/views/_pg.html.erb0000644000175000017500000000022313161456577021141 0ustar rajudevrajudev... / ... pg peek-pg-1.3.0/lib/0000755000175000017500000000000013161456577013512 5ustar rajudevrajudevpeek-pg-1.3.0/lib/peek-pg.rb0000644000175000017500000000011413161456577015363 0ustar rajudevrajudevrequire 'peek-pg/version' require 'peek/views/pg' require 'peek-pg/railtie' peek-pg-1.3.0/lib/peek-pg/0000755000175000017500000000000013161456577015042 5ustar rajudevrajudevpeek-pg-1.3.0/lib/peek-pg/version.rb0000644000175000017500000000007013161456577017051 0ustar rajudevrajudevmodule Peek module PG VERSION = '1.3.0' end end peek-pg-1.3.0/lib/peek-pg/railtie.rb0000644000175000017500000000011613161456577017016 0ustar rajudevrajudevmodule Peek module PG class Railtie < ::Rails::Engine end end end peek-pg-1.3.0/lib/peek/0000755000175000017500000000000013161456577014436 5ustar rajudevrajudevpeek-pg-1.3.0/lib/peek/views/0000755000175000017500000000000013161456577015573 5ustar rajudevrajudevpeek-pg-1.3.0/lib/peek/views/pg.rb0000644000175000017500000000343613161456577016534 0ustar rajudevrajudevrequire 'pg' require 'concurrent/atomics' module Peek module PGInstrumented def exec(*args) start = Time.now super(*args) ensure duration = (Time.now - start) ::PG::Connection.query_time.update { |value| value + duration } ::PG::Connection.query_count.update { |value| value + 1 } end def async_exec(*args) start = Time.now super(*args) ensure duration = (Time.now - start) ::PG::Connection.query_time.update { |value| value + duration } ::PG::Connection.query_count.update { |value| value + 1 } end def exec_prepared(*args) start = Time.now super(*args) ensure duration = (Time.now - start) ::PG::Connection.query_time.update { |value| value + duration } ::PG::Connection.query_count.update { |value| value + 1 } end end end # Instrument SQL time class PG::Connection prepend ::Peek::PGInstrumented class << self attr_accessor :query_time, :query_count end self.query_count = Concurrent::AtomicReference.new(0) self.query_time = Concurrent::AtomicReference.new(0) end module Peek module Views class PG < View def duration ::PG::Connection.query_time.value end def formatted_duration ms = duration * 1000 if ms >= 1000 "%.2fms" % ms else "%.0fms" % ms end end def calls ::PG::Connection.query_count.value end def results { :duration => formatted_duration, :calls => calls } end private def setup_subscribers # Reset each counter when a new request starts before_request do ::PG::Connection.query_time.value = 0 ::PG::Connection.query_count.value = 0 end end end end end peek-pg-1.3.0/peek-pg.gemspec0000644000175000017500000000172113161456577015642 0ustar rajudevrajudev# -*- encoding: utf-8 -*- lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'peek-pg/version' Gem::Specification.new do |gem| gem.name = 'peek-pg' gem.version = Peek::PG::VERSION gem.authors = ['Garrett Bjerkhoel'] gem.email = ['me@garrettbjerkhoel.com'] gem.description = %q{Take a peek into the Postgres queries made during your application's requests.} gem.summary = %q{Take a peek into the Postgres queries made during your application's requests.} gem.homepage = 'https://github.com/peek/peek-pg' gem.files = `git ls-files`.split($/) gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.require_paths = ['lib'] gem.add_dependency 'peek' gem.add_dependency 'pg' gem.add_dependency 'concurrent-ruby' gem.add_dependency 'concurrent-ruby-ext' end peek-pg-1.3.0/README.md0000644000175000017500000000136513161456577014230 0ustar rajudevrajudev# Peek::PG Take a peek into the Postgres queries made during your application's requests. Things this peek view provides: - Total number of Postgres queries called during the request - The duration of the queries made during the request ## Installation Add this line to your application's Gemfile: gem 'peek-pg' And then execute: $ bundle Or install it yourself as: $ gem install peek-pg ## Usage Add the following to your `config/initializers/peek.rb`: ```ruby Peek.into Peek::Views::PG ``` ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request peek-pg-1.3.0/LICENSE.txt0000644000175000017500000000206113161456577014566 0ustar rajudevrajudevCopyright (c) 2013 Garrett Bjerkhoel MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.peek-pg-1.3.0/.gitignore0000644000175000017500000000023213161456577014731 0ustar rajudevrajudev*.gem *.rbc .bundle .config .yardoc Gemfile.lock InstalledFiles _yardoc coverage doc/ lib/bundler/man pkg rdoc spec/reports test/tmp test/version_tmp tmp