From 0b19321ec3a4bfb9941d5e192564f3f2c719501d Mon Sep 17 00:00:00 2001 From: Hafiz Badrie Lubis Date: Sat, 10 Jan 2015 19:00:21 +0700 Subject: [PATCH 1/2] list all of queries executed --- app/assets/javascripts/peek-mysql2.coffee | 18 ++++++++++++++++++ app/assets/stylesheets/peek-mysql2.scss | 15 +++++++++++++++ app/views/peek/views/_mysql2.html.erb | 4 +++- lib/peek/views/mysql2.rb | 14 ++++++++++++-- 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 app/assets/javascripts/peek-mysql2.coffee create mode 100644 app/assets/stylesheets/peek-mysql2.scss diff --git a/app/assets/javascripts/peek-mysql2.coffee b/app/assets/javascripts/peek-mysql2.coffee new file mode 100644 index 0000000..264e01f --- /dev/null +++ b/app/assets/javascripts/peek-mysql2.coffee @@ -0,0 +1,18 @@ +firstTime = true + +$(document).on "click", "#peek-mysql2-queries", (e) -> + e.preventDefault() + $this = $(this) + if $this.text() == 'Show List' + $this.text('Hide List') + else + $this.text('Show List') + + $queryList = $("div[data-defer-to=mysql2-queries]") + contentText = $queryList.text() + + if contentText.indexOf('
') >= 0 + $queryList.html($queryList.text()) + + $queryList.toggle() + return diff --git a/app/assets/stylesheets/peek-mysql2.scss b/app/assets/stylesheets/peek-mysql2.scss new file mode 100644 index 0000000..0b1f17c --- /dev/null +++ b/app/assets/stylesheets/peek-mysql2.scss @@ -0,0 +1,15 @@ +#peek-view-mysql2 { + position: relative; +} + +div[data-defer-to="mysql2-queries"] { + background-color: rgb(255, 255, 255); + color: rgb(0, 0, 0); + padding: 5px; + position: absolute; + top: 40px; + width: 700px; + z-index: 99999; + border: 2px solid rgba(0, 0, 0, 0.2); + border-radius: 5px; +} diff --git a/app/views/peek/views/_mysql2.html.erb b/app/views/peek/views/_mysql2.html.erb index be94502..0f4b748 100644 --- a/app/views/peek/views/_mysql2.html.erb +++ b/app/views/peek/views/_mysql2.html.erb @@ -1 +1,3 @@ -... / ... sql +... +/ ... sql +(Show List)
diff --git a/lib/peek/views/mysql2.rb b/lib/peek/views/mysql2.rb index 26ab955..fac1bf2 100644 --- a/lib/peek/views/mysql2.rb +++ b/lib/peek/views/mysql2.rb @@ -4,10 +4,11 @@ # Instrument SQL time class Mysql2::Client class << self - attr_accessor :query_time, :query_count + attr_accessor :query_time, :query_count, :query_list end self.query_count = Atomic.new(0) self.query_time = Atomic.new(0) + self.query_list = Atomic.new('') def query_with_timing(*args) start = Time.now @@ -16,6 +17,10 @@ def query_with_timing(*args) duration = (Time.now - start) Mysql2::Client.query_time.update { |value| value + duration } Mysql2::Client.query_count.update { |value| value + 1 } + Mysql2::Client.query_list.update { |value| + ms = duration * 1000 + value + args.first + '(' + ms.to_s + ' ms)
' + } end alias_method_chain :query, :timing end @@ -40,8 +45,12 @@ def calls ::Mysql2::Client.query_count.value end + def queries + ::Mysql2::Client.query_list.value + end + def results - { :duration => formatted_duration, :calls => calls } + { :duration => formatted_duration, :calls => calls, :queries => queries } end private @@ -51,6 +60,7 @@ def setup_subscribers before_request do ::Mysql2::Client.query_time.value = 0 ::Mysql2::Client.query_count.value = 0 + ::Mysql2::Client.query_list.value = '' end end end From deea7adbeef6ab3915dfba58ecea63331c20c732 Mon Sep 17 00:00:00 2001 From: Hafiz Badrie Lubis Date: Mon, 12 Jan 2015 18:48:09 +0700 Subject: [PATCH 2/2] remove unnecessary variable --- app/assets/javascripts/peek-mysql2.coffee | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/assets/javascripts/peek-mysql2.coffee b/app/assets/javascripts/peek-mysql2.coffee index 264e01f..3ed2d72 100644 --- a/app/assets/javascripts/peek-mysql2.coffee +++ b/app/assets/javascripts/peek-mysql2.coffee @@ -1,5 +1,3 @@ -firstTime = true - $(document).on "click", "#peek-mysql2-queries", (e) -> e.preventDefault() $this = $(this)