Class: Rack::Insight::SpeedTracer::Panel

Inherits:
Panel
  • Object
show all
Defined in:
lib/rack/insight/panels/speedtracer_panel.rb

Overview

TODO Refactor this class nameā€¦ TODO: Fix indentation of this class. TODO: Update this class to Rack::Insight pattern.

Instance Attribute Summary

Attributes inherited from Panel

#request

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Panel

#after, #after_detect, #before, #bool_prop, #camelized_name, #content, current_panel_file, excluded, file_index, from_file, #handle_error_for, #has_content?, #has_custom_probes?, has_table, #has_table?, #heading_for_request, inherited, #inspect, #is_magic?, #is_probing?, #name, #panel_app, panel_exclusion, #render, set_sub_class_template_root, #underscored_name

Methods included from Database::EigenClient

included

Methods included from Instrumentation::EigenClient

included

Methods included from Logging

logger, verbose, verbosity

Methods included from Instrumentation::Client

#after_detect, #before_detect, #probe, #request_finish, #request_start

Methods included from Database::RequestDataClient

#count, #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

#initialize(app) ⇒ Panel

Returns a new instance of Panel.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rack/insight/panels/speedtracer_panel.rb', line 17

def initialize(app)
  @app = app
  @uuid = UUIDTools::UUID.random_create.to_s
  table_setup("speedtracer", "uuid")
  key_sql_template("'%s'")

  @tracer = Tracer.new(@table)
  probe(@tracer) do
    instrument("ActiveSupport::Notifications") do
      class_probe :instrument
    end

    instrument("ActionView::Rendering") do
      instance_probe :render
    end

    instrument("ActionView::Helpers::RecordTagHelper") do
      instance_probe :content_tag_for
    end

    instrument("ActionView::Partials::PartialRenderer") do
      instance_probe :render, :find_template, :render_collection, :collection_with_template, :collection_without_template, :partial_path, :collection_paths
    end

    instrument("ActionView::Template") do
      instance_probe :render, :compile
    end

    instrument("ActiveRecord::Base") do
      class_probe :find, :find_by_sql, :all, :first, :last, :count, :delete_all
      instance_probe :save, :save!, :destroy, :delete
    end

    instrument("ActionController::Base") do
      instance_probe :process, :render
    end
  end

  super
end

Class Method Details

.panel_mappingsObject



67
68
69
# File 'lib/rack/insight/panels/speedtracer_panel.rb', line 67

def self.panel_mappings
  { "speedtracer" => TraceApp.new }
end

Instance Method Details

#call(env) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/rack/insight/panels/speedtracer_panel.rb', line 58

def call(env)
  env['rack-insight.speedtracer-id'] = @uuid

  status, headers, body = @app.call(env)
  store(env, env['rack-insight.speedtracer-id'], env['rack-insight.speedtracer-record'])
  headers['X-TraceUrl'] = '__insight__/speedtracer?id=' + env['rack-insight.speedtracer-id']
  return [status, headers, body]
end

#content_for_request(request_id) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/rack/insight/panels/speedtracer_panel.rb', line 75

def content_for_request(request_id)
trace = retrieve(request_id).first
return "" if trace.nil?
advice = []
if not defined?(Yajl)
  advice << "yajl-ruby not installed - Speedtracer server events won't be available"
end
render_template "panels/speedtracer/traces", :trace => trace, :advice => advice
end

#headingObject



71
72
73
# File 'lib/rack/insight/panels/speedtracer_panel.rb', line 71

def heading
  "#{table_length} traces"
end