Class: Insight::SQLPanel

Inherits:
Panel
  • Object
show all
Defined in:
lib/insight/panels/sql_panel.rb,
lib/insight/panels/sql_panel/query.rb,
lib/insight/panels/sql_panel/panel_app.rb

Defined Under Namespace

Classes: ExplainResult, PanelApp, ProfileResult, QueryResult

Instance Attribute Summary

Attributes inherited from Panel

#request

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Panel

#after, #before, #call, current_panel_file, excluded, file_index, from_file, #has_content?, inherited, #panel_app, panel_exclusion, #render

Methods included from Instrumentation::Client

#before_detect, #probe, #request_finish, #request_start

Methods included from Logging

logger

Methods included from Database::RequestDataClient

#key_sql_template, #retrieve, #store, #table_length, #table_setup

Methods included from Render

#compile, #compile!, #compiled_source, #method_name, #method_name_without_locals, #render_template, #signed_params

Constructor Details

- (SQLPanel) initialize(app)

A new instance of SQLPanel



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/insight/panels/sql_panel.rb', line 10

def initialize(app)
  super
  probe(self) do
    %w{ PostgreSQLAdapter MysqlAdapter SQLiteAdapter
        Mysql2Adapter OracleEnhancedAdapter }.each do |adapter|
      instrument "ActiveRecord::ConnectionAdapters::#{adapter}" do
        instance_probe :execute
      end
        end
  end
  table_setup("sql_queries")
end

Class Method Details

+ (Object) panel_mappings



23
24
25
# File 'lib/insight/panels/sql_panel.rb', line 23

def self.panel_mappings
  { "sql" => PanelApp.new }
end

Instance Method Details

- (Object) after_detect(method_call, timing, arguments, results)



27
28
29
# File 'lib/insight/panels/sql_panel.rb', line 27

def after_detect(method_call, timing, arguments, results)
  store(@env, QueryResult.new(arguments.first, timing.duration, method_call.backtrace, results))
end

- (Object) content_for_request(number)



46
47
48
49
# File 'lib/insight/panels/sql_panel.rb', line 46

def content_for_request(number)
  queries = retrieve(number)
  render_template "panels/sql", :queries => queries
end

- (Object) heading_for_request(number)



41
42
43
44
# File 'lib/insight/panels/sql_panel.rb', line 41

def heading_for_request(number)
  queries = retrieve(number)
  "#{queries.size} Queries (%.2fms)" % total_time(queries)
end

- (Object) name



37
38
39
# File 'lib/insight/panels/sql_panel.rb', line 37

def name
  "sql"
end

- (Object) total_time(queries)



31
32
33
34
35
# File 'lib/insight/panels/sql_panel.rb', line 31

def total_time(queries)
  (queries.inject(0) do |memo, query|
    memo + query.time
  end)
end