newrelic_rpm 2.8.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of newrelic_rpm might be problematic. Click here for more details.

Files changed (107) hide show
  1. data/LICENSE +37 -0
  2. data/README +93 -0
  3. data/Rakefile +38 -0
  4. data/install.rb +37 -0
  5. data/lib/new_relic/agent.rb +26 -0
  6. data/lib/new_relic/agent/agent.rb +762 -0
  7. data/lib/new_relic/agent/chained_call.rb +13 -0
  8. data/lib/new_relic/agent/collection_helper.rb +81 -0
  9. data/lib/new_relic/agent/error_collector.rb +105 -0
  10. data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +95 -0
  11. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +151 -0
  12. data/lib/new_relic/agent/instrumentation/data_mapper.rb +90 -0
  13. data/lib/new_relic/agent/instrumentation/dispatcher_instrumentation.rb +105 -0
  14. data/lib/new_relic/agent/instrumentation/memcache.rb +18 -0
  15. data/lib/new_relic/agent/instrumentation/merb/controller.rb +17 -0
  16. data/lib/new_relic/agent/instrumentation/merb/dispatcher.rb +15 -0
  17. data/lib/new_relic/agent/instrumentation/merb/errors.rb +6 -0
  18. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +35 -0
  19. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +27 -0
  20. data/lib/new_relic/agent/instrumentation/rails/dispatcher.rb +30 -0
  21. data/lib/new_relic/agent/instrumentation/rails/errors.rb +23 -0
  22. data/lib/new_relic/agent/instrumentation/rails/rails.rb +6 -0
  23. data/lib/new_relic/agent/method_tracer.rb +171 -0
  24. data/lib/new_relic/agent/patch_const_missing.rb +31 -0
  25. data/lib/new_relic/agent/samplers/cpu.rb +29 -0
  26. data/lib/new_relic/agent/samplers/memory.rb +55 -0
  27. data/lib/new_relic/agent/samplers/mongrel.rb +26 -0
  28. data/lib/new_relic/agent/stats_engine.rb +241 -0
  29. data/lib/new_relic/agent/synchronize.rb +40 -0
  30. data/lib/new_relic/agent/transaction_sampler.rb +281 -0
  31. data/lib/new_relic/agent/worker_loop.rb +128 -0
  32. data/lib/new_relic/api/deployments.rb +92 -0
  33. data/lib/new_relic/config.rb +194 -0
  34. data/lib/new_relic/config/merb.rb +35 -0
  35. data/lib/new_relic/config/rails.rb +113 -0
  36. data/lib/new_relic/config/ruby.rb +9 -0
  37. data/lib/new_relic/local_environment.rb +108 -0
  38. data/lib/new_relic/merbtasks.rb +6 -0
  39. data/lib/new_relic/metric_data.rb +26 -0
  40. data/lib/new_relic/metric_spec.rb +39 -0
  41. data/lib/new_relic/metrics.rb +7 -0
  42. data/lib/new_relic/noticed_error.rb +21 -0
  43. data/lib/new_relic/shim_agent.rb +95 -0
  44. data/lib/new_relic/stats.rb +359 -0
  45. data/lib/new_relic/transaction_analysis.rb +122 -0
  46. data/lib/new_relic/transaction_sample.rb +499 -0
  47. data/lib/new_relic/version.rb +111 -0
  48. data/lib/new_relic_api.rb +275 -0
  49. data/lib/newrelic_rpm.rb +27 -0
  50. data/lib/tasks/agent_tests.rake +14 -0
  51. data/lib/tasks/all.rb +4 -0
  52. data/lib/tasks/install.rake +7 -0
  53. data/newrelic.yml +137 -0
  54. data/recipes/newrelic.rb +46 -0
  55. data/test/config/newrelic.yml +26 -0
  56. data/test/config/test_config.rb +9 -0
  57. data/test/new_relic/agent/mock_ar_connection.rb +40 -0
  58. data/test/new_relic/agent/mock_scope_listener.rb +23 -0
  59. data/test/new_relic/agent/model_fixture.rb +17 -0
  60. data/test/new_relic/agent/tc_active_record.rb +91 -0
  61. data/test/new_relic/agent/tc_agent.rb +112 -0
  62. data/test/new_relic/agent/tc_collection_helper.rb +104 -0
  63. data/test/new_relic/agent/tc_controller.rb +98 -0
  64. data/test/new_relic/agent/tc_dispatcher_instrumentation.rb +52 -0
  65. data/test/new_relic/agent/tc_error_collector.rb +127 -0
  66. data/test/new_relic/agent/tc_method_tracer.rb +306 -0
  67. data/test/new_relic/agent/tc_stats_engine.rb +218 -0
  68. data/test/new_relic/agent/tc_synchronize.rb +37 -0
  69. data/test/new_relic/agent/tc_transaction_sample.rb +175 -0
  70. data/test/new_relic/agent/tc_transaction_sample_builder.rb +200 -0
  71. data/test/new_relic/agent/tc_transaction_sampler.rb +305 -0
  72. data/test/new_relic/agent/tc_worker_loop.rb +101 -0
  73. data/test/new_relic/agent/testable_agent.rb +13 -0
  74. data/test/new_relic/tc_config.rb +36 -0
  75. data/test/new_relic/tc_deployments_api.rb +37 -0
  76. data/test/new_relic/tc_environment.rb +94 -0
  77. data/test/new_relic/tc_metric_spec.rb +150 -0
  78. data/test/new_relic/tc_shim_agent.rb +9 -0
  79. data/test/new_relic/tc_stats.rb +141 -0
  80. data/test/test_helper.rb +39 -0
  81. data/test/ui/tc_newrelic_helper.rb +44 -0
  82. data/ui/controllers/newrelic_controller.rb +200 -0
  83. data/ui/helpers/google_pie_chart.rb +55 -0
  84. data/ui/helpers/newrelic_helper.rb +286 -0
  85. data/ui/views/layouts/newrelic_default.rhtml +49 -0
  86. data/ui/views/newrelic/_explain_plans.rhtml +27 -0
  87. data/ui/views/newrelic/_sample.rhtml +12 -0
  88. data/ui/views/newrelic/_segment.rhtml +28 -0
  89. data/ui/views/newrelic/_segment_row.rhtml +14 -0
  90. data/ui/views/newrelic/_show_sample_detail.rhtml +22 -0
  91. data/ui/views/newrelic/_show_sample_sql.rhtml +19 -0
  92. data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
  93. data/ui/views/newrelic/_sql_row.rhtml +11 -0
  94. data/ui/views/newrelic/_stack_trace.rhtml +30 -0
  95. data/ui/views/newrelic/_table.rhtml +12 -0
  96. data/ui/views/newrelic/explain_sql.rhtml +45 -0
  97. data/ui/views/newrelic/images/arrow-close.png +0 -0
  98. data/ui/views/newrelic/images/arrow-open.png +0 -0
  99. data/ui/views/newrelic/images/blue_bar.gif +0 -0
  100. data/ui/views/newrelic/images/gray_bar.gif +0 -0
  101. data/ui/views/newrelic/index.rhtml +37 -0
  102. data/ui/views/newrelic/javascript/transaction_sample.js +107 -0
  103. data/ui/views/newrelic/sample_not_found.rhtml +2 -0
  104. data/ui/views/newrelic/show_sample.rhtml +62 -0
  105. data/ui/views/newrelic/show_source.rhtml +3 -0
  106. data/ui/views/newrelic/stylesheets/style.css +394 -0
  107. metadata +180 -0
@@ -0,0 +1,44 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','test_helper'))
2
+ require 'newrelic_helper'
3
+ require 'new_relic/agent/model_fixture'
4
+
5
+ class NewRelic::Agent::NewrelicHelperTests < Test::Unit::TestCase
6
+ include NewrelicHelper
7
+ def setup
8
+ super
9
+ NewRelic::Agent::ModelFixture.setup
10
+ begin
11
+ # setup instrumentation
12
+ NewRelic::Agent.instance.start :test, :test
13
+ NewRelic::Agent::ModelFixture.find 0
14
+ rescue => e
15
+ @exception = e
16
+ return
17
+ end
18
+ flunk "should throw"
19
+ end
20
+ def teardown
21
+ NewRelic::Agent::ModelFixture.teardown
22
+ NewRelic::Agent.instance.shutdown
23
+ super
24
+ end
25
+ def test_application_caller
26
+ assert_match /setup/, application_caller(@exception.backtrace)
27
+ end
28
+
29
+ def test_application_stack_trace__rails
30
+ assert_clean(application_stack_trace(@exception.backtrace, true), true)
31
+ end
32
+ def test_application_stack_trace__no_rails
33
+ assert_clean(application_stack_trace(@exception.backtrace, false), false)
34
+ end
35
+
36
+ private
37
+ def assert_clean(backtrace, rails=false)
38
+ if !rails
39
+ assert_equal 0, backtrace.grep('/rails/').size, backtrace.grep(/newrelic_rpm/)
40
+ end
41
+ assert_equal 0, backtrace.grep(/trace/).size, backtrace.grep(/trace/)
42
+ assert_equal 0, backtrace.grep(/newrelic_rpm\/lib/).size, backtrace.grep(/newrelic_rpm\/lib/)
43
+ end
44
+ end
@@ -0,0 +1,200 @@
1
+ ##require 'new_relic/agent'
2
+ require 'google_pie_chart'
3
+
4
+ class NewrelicController < ActionController::Base
5
+ include NewrelicHelper
6
+
7
+ # See http://wiki.rubyonrails.org/rails/pages/Safe+ERB:
8
+ # We don't need to worry about checking taintedness
9
+ def initialize(*args)
10
+ @skip_checking_tainted = true
11
+ super *args
12
+ end
13
+
14
+ # do not include any filters inside the application since there might be a conflict
15
+ if respond_to? :filter_chain
16
+ filters = filter_chain.collect do |f|
17
+ if f.respond_to? :filter
18
+ # rails 2.0
19
+ f.filter
20
+ elsif f.respond_to? :method
21
+ # rails 2.1
22
+ f.method
23
+ else
24
+ fail "Unknown filter class. Please send this exception to support@newrelic.com"
25
+ end
26
+ end
27
+ skip_filter filters
28
+ end
29
+
30
+ # for this controller, the views are located in a different directory from
31
+ # the application's views.
32
+ view_path = File.join(File.dirname(__FILE__), '..', 'views')
33
+ if public_methods.include? 'append_view_path' # rails 2.1+
34
+ self.append_view_path view_path
35
+ elsif public_methods.include? "view_paths" # rails 2.0+
36
+ self.view_paths << view_path
37
+ else # rails <2.0
38
+ self.template_root = view_path
39
+ end
40
+
41
+ layout "newrelic_default"
42
+
43
+ write_inheritable_attribute('do_not_trace', true)
44
+
45
+ def css
46
+ forward_to_file '/newrelic/stylesheets/', 'text/css'
47
+ end
48
+
49
+ def image
50
+ forward_to_file '/newrelic/images/', params[:content_type]
51
+ end
52
+
53
+ def javascript
54
+ forward_to_file '/newrelic/javascript/', 'text/javascript'
55
+ end
56
+
57
+
58
+
59
+ def index
60
+ get_samples
61
+ end
62
+
63
+ def show_sample_detail
64
+ show_sample_data
65
+ end
66
+
67
+ def show_sample_summary
68
+ show_sample_data
69
+ end
70
+
71
+ def show_sample_sql
72
+ show_sample_data
73
+ end
74
+
75
+
76
+ def explain_sql
77
+ get_segment
78
+
79
+ render :action => "sample_not_found" and return unless @sample
80
+
81
+ @sql = @segment[:sql]
82
+ @trace = @segment[:backtrace]
83
+
84
+ if NewRelic::Agent.agent.record_sql == :obfuscated
85
+ @obfuscated_sql = @segment.obfuscated_sql
86
+ end
87
+
88
+ explanations = @segment.explain_sql
89
+ if explanations
90
+ @explanation = explanations.first
91
+ if !@explanation.blank?
92
+ first_row = @explanation.first
93
+ # Show the standard headers if it looks like a mysql explain plan
94
+ # Otherwise show blank headers
95
+ if first_row.length < NewRelic::MYSQL_EXPLAIN_COLUMNS.length
96
+ @row_headers = nil
97
+ else
98
+ @row_headers = NewRelic::MYSQL_EXPLAIN_COLUMNS
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ # show the selected source file with the highlighted selected line
105
+ def show_source
106
+ @filename = params[:file]
107
+ line_number = params[:line].to_i
108
+
109
+ if !File.readable?(@filename)
110
+ @source="<p>Unable to read #{@filename}.</p>"
111
+ return
112
+ end
113
+ begin
114
+ file = File.new(@filename, 'r')
115
+ rescue => e
116
+ @source="<p>Unable to access the source file #{@filename} (#{e.message}).</p>"
117
+ return
118
+ end
119
+ @source = ""
120
+
121
+ @source << "<pre>"
122
+ file.each_line do |line|
123
+ # place an anchor 6 lines above the selected line (if the line # < 6)
124
+ if file.lineno == line_number - 6
125
+ @source << "</pre><pre id = 'selected_line'>"
126
+ @source << line.rstrip
127
+ @source << "</pre><pre>"
128
+
129
+ # highlight the selected line
130
+ elsif file.lineno == line_number
131
+ @source << "</pre><pre class = 'selected_source_line'>"
132
+ @source << line.rstrip
133
+ @source << "</pre><pre>"
134
+ else
135
+ @source << line
136
+ end
137
+ end
138
+ end
139
+
140
+ private
141
+
142
+ # root path is relative to plugin newrelic_rpm/ui/views directory.
143
+ def forward_to_file(root_path, content_type='ignored anyway')
144
+ file = File.expand_path(File.join(__FILE__,"../../views", root_path, params[:file]))
145
+ last_modified = File.mtime(file)
146
+ date_check = request.respond_to?(:headers) ? request.headers['if-modified-since'] : request.env['HTTP_IF_MODIFIED_SINCE']
147
+ if date_check && Time.parse(date_check) >= last_modified
148
+ expires_in 24.hours
149
+ head :not_modified,
150
+ :last_modified => last_modified,
151
+ :type => 'text/plain'
152
+ else
153
+ response.headers['Last-Modified'] = last_modified
154
+ expires_in 24.hours
155
+ send_file file, :content_type => mime_type_from_extension(file), :disposition => 'inline' #, :filename => File.basename(file)
156
+ end
157
+ end
158
+
159
+ def show_sample_data
160
+ get_sample
161
+
162
+ render :action => "sample_not_found" and return unless @sample
163
+
164
+ @request_params = @sample.params[:request_params] || {}
165
+ controller_metric = @sample.root_segment.called_segments.first.metric_name
166
+
167
+ controller_segments = controller_metric.split('/')
168
+ @sample_controller_name = controller_segments[1..-2].join('/').camelize+"Controller"
169
+ @sample_action_name = controller_segments[-1].underscore
170
+
171
+ render :action => :show_sample
172
+ end
173
+
174
+ def get_samples
175
+ @samples = NewRelic::Agent.instance.transaction_sampler.get_samples.select do |sample|
176
+ sample.params[:path] != nil
177
+ end
178
+
179
+ @samples = @samples.reverse
180
+ end
181
+
182
+ def get_sample
183
+ get_samples
184
+ sample_id = params[:id].to_i
185
+ @samples.each do |s|
186
+ if s.sample_id == sample_id
187
+ @sample = stripped_sample(s)
188
+ return
189
+ end
190
+ end
191
+ end
192
+
193
+ def get_segment
194
+ get_sample
195
+ return unless @sample
196
+
197
+ segment_id = params[:segment].to_i
198
+ @segment = @sample.find_segment(segment_id)
199
+ end
200
+ end
@@ -0,0 +1,55 @@
1
+
2
+ # A wrapper around the google charts service.
3
+ # TODO consider making generic and open sourcing
4
+ class GooglePieChart
5
+ attr_accessor :width, :height, :color
6
+
7
+ def initialize
8
+ # an array of [label, value]
9
+ @data = []
10
+
11
+ self.width = 300
12
+ self.height = 200
13
+ end
14
+
15
+ def add_data_point(label, value)
16
+ @data << [label, value]
17
+ @max = (@max.nil? || @max < value ? value : @max)
18
+ end
19
+
20
+ # render the chart to html by creating an image object and
21
+ # placing the correct URL to the google charts api
22
+ def render
23
+ labels = ''
24
+ values = ''
25
+ @data.each do |label, value|
26
+ labels << CGI::escape(label) + '|'
27
+ values << (value * 100 / @max).round.to_s + ","
28
+ end
29
+
30
+ # strip of the last separator char for labels and values
31
+ labels = labels[0..-2]
32
+ values = values[0..-2]
33
+
34
+ params = {:cht => 'p', :chs => "#{width}x#{height}", :chd => "t:#{values}", :chl => labels }
35
+ params['chco'] = color if color
36
+
37
+ url = "http://chart.apis.google.com/chart?#{to_query(params)}"
38
+
39
+ alt_msg = "This pie chart is generated by Google Charts. You must be connected to the Internet to view this chart."
40
+ html = "<img id=\"pie_chart_image\" src=\"#{url}\" alt=\"#{alt_msg}\"/>"
41
+ return html
42
+ end
43
+
44
+ private
45
+ # Hash#to_query is not present in all supported rails platforms, so implement
46
+ # its equivalent here.
47
+ def to_query(params)
48
+ p = []
49
+ params.each do |k,v|
50
+ p << "#{k}=#{v}"
51
+ end
52
+
53
+ p.join "&"
54
+ end
55
+ end
@@ -0,0 +1,286 @@
1
+ require 'pathname'
2
+ require 'new_relic/agent/collection_helper'
3
+ module NewrelicHelper
4
+ include NewRelic::Agent::CollectionHelper
5
+ # return the host that serves static content (css, metric documentation, images, etc)
6
+ # that supports the desktop edition.
7
+ def server
8
+ NewRelic::Agent.instance.config['desktop_server'] || "http://rpm.newrelic.com"
9
+ end
10
+
11
+ # return the sample but post processed to strip out segments that normally don't show
12
+ # up in production (after the first execution, at least) such as application code loading
13
+ def stripped_sample(sample = @sample)
14
+ if session[:newrelic_strip_code_loading] || true
15
+ sample.omit_segments_with('(Rails/Application Code Loading)|(Database/.*/.+ Columns)')
16
+ else
17
+ sample
18
+ end
19
+ end
20
+
21
+ # return the highest level in the call stack for the trace that is not rails or
22
+ # newrelic agent code
23
+ def application_caller(trace)
24
+ trace = strip_nr_from_backtrace(trace)
25
+ trace.each do |trace_line|
26
+ file = file_and_line(trace_line).first
27
+ unless exclude_file_from_stack_trace?(file, false)
28
+ return trace_line
29
+ end
30
+ end
31
+ trace.last
32
+ end
33
+
34
+ def application_stack_trace(trace, include_rails = false)
35
+ trace = strip_nr_from_backtrace(trace)
36
+ trace.reject do |trace_line|
37
+ file = file_and_line(trace_line).first
38
+ exclude_file_from_stack_trace?(file, include_rails)
39
+ end
40
+ end
41
+
42
+ def agent_views_path(path)
43
+ path
44
+ end
45
+
46
+ def url_for_metric_doc(metric_name)
47
+ "#{server}/metric_doc?metric=#{CGI::escape(metric_name)}"
48
+ end
49
+
50
+ def url_for_source(trace_line)
51
+ file, line = file_and_line(trace_line)
52
+
53
+ begin
54
+ file = Pathname.new(file).realpath
55
+ rescue Errno::ENOENT
56
+ # we hit this exception when Pathame.realpath fails for some reason; attempt a link to
57
+ # the file without a real path. It may also fail, only when the user clicks on this specific
58
+ # entry in the stack trace
59
+ rescue
60
+ # catch all other exceptions. We're going to create an invalid link below, but that's okay.
61
+ end
62
+
63
+ if using_textmate?
64
+ "txmt://open?url=file://#{file}&line=#{line}"
65
+ else
66
+ url_for :action => 'show_source', :file => file, :line => line, :anchor => 'selected_line'
67
+ end
68
+ end
69
+
70
+
71
+ def dev_name(metric_name)
72
+ @@metric_parser_available ||= defined? MetricParser
73
+
74
+ (@@metric_parser_available) ? MetricParser.parse(metric_name).developer_name : metric_name
75
+ end
76
+
77
+ # write the metric label for a segment metric in the detail view
78
+ def write_segment_label(segment)
79
+ if source_available && segment[:backtrace] && (source_url = url_for_source(application_caller(segment[:backtrace])))
80
+ link_to dev_name(segment.metric_name), source_url
81
+ else
82
+ dev_name(segment.metric_name)
83
+ end
84
+ end
85
+
86
+ def source_available
87
+ true
88
+ end
89
+
90
+ # write the metric label for a segment metric in the summary table of metrics
91
+ def write_summary_segment_label(segment)
92
+ dev_name(segment.metric_name)
93
+ end
94
+
95
+ def write_stack_trace_line(trace_line)
96
+ link_to h(trace_line), url_for_source(trace_line)
97
+ end
98
+
99
+ # write a link to the source for a trace
100
+ def link_to_source(trace)
101
+ image_url = "#{server}/images/"
102
+ image_url << (using_textmate? ? "textmate.png" : "file_icon.png")
103
+
104
+ link_to image_tag(image_url, :alt => (title = 'View Source'), :title => title), url_for_source(application_caller(trace))
105
+ end
106
+
107
+ # print the formatted timestamp for a segment
108
+ def timestamp(segment)
109
+ sprintf("%1.3f", segment.entry_timestamp)
110
+ end
111
+
112
+ def format_timestamp(time)
113
+ time.strftime("%H:%M:%S")
114
+ end
115
+
116
+ def colorize(value, yellow_threshold = 0.05, red_threshold = 0.15)
117
+ if value > yellow_threshold
118
+ color = (value > red_threshold ? 'red' : 'orange')
119
+ "<font color=#{color}>#{value.to_ms}</font>"
120
+ else
121
+ "#{value.to_ms}"
122
+ end
123
+ end
124
+
125
+ def expanded_image_path()
126
+ url_for(:controller => :newrelic, :action => :image, :file => 'arrow-open.png')
127
+ end
128
+
129
+ def collapsed_image_path()
130
+ url_for(:controller => :newrelic, :action => :image, :file => 'arrow-close.png')
131
+ end
132
+
133
+ def explain_sql_url(segment)
134
+ url_for(:action => :explain_sql,
135
+ :id => @sample.sample_id,
136
+ :segment => segment.segment_id)
137
+ end
138
+
139
+ def segment_duration_value(segment)
140
+ link_to "#{segment.duration.to_ms.with_delimiter} ms", explain_sql_url(segment)
141
+ end
142
+
143
+ def line_wrap_sql(sql)
144
+ sql.gsub(/\,/,', ').squeeze(' ') if sql
145
+ end
146
+
147
+ def render_sample_details(sample)
148
+ @indentation_depth=0
149
+ # skip past the root segments to the first child, which is always the controller
150
+ first_segment = sample.root_segment.called_segments.first
151
+
152
+ # render the segments, then the css classes to indent them
153
+ render_segment_details(first_segment) + render_indentation_classes(@indentation_depth)
154
+ end
155
+
156
+ # the rows logger plugin disables the sql tracing functionality of the NewRelic agent -
157
+ # notify the user about this
158
+ def rows_logger_present?
159
+ File.exist?(File.join(File.dirname(__FILE__), "../../../rows_logger/init.rb"))
160
+ end
161
+
162
+ def expand_segment_image(segment, depth)
163
+ if depth > 0
164
+ if !segment.called_segments.empty?
165
+ row_class =segment_child_row_class(segment)
166
+ link_to_function(tag('img', :src => collapsed_image_path, :id => "image_#{row_class}",
167
+ :class_for_children => row_class,
168
+ :class => (!segment.called_segments.empty?) ? 'parent_segment_image' : 'child_segment_image'),
169
+ "toggle_row_class(this)")
170
+ end
171
+ end
172
+ end
173
+
174
+ def segment_child_row_class(segment)
175
+ "segment#{segment.segment_id}"
176
+ end
177
+
178
+ def summary_pie_chart(sample, width, height)
179
+ pie_chart = GooglePieChart.new
180
+ pie_chart.color, pie_chart.width, pie_chart.height = '6688AA', width, height
181
+
182
+ chart_data = sample.breakdown_data(6)
183
+ chart_data.each { |s| pie_chart.add_data_point dev_name(s.metric_name), s.exclusive_time.to_ms }
184
+
185
+ pie_chart.render
186
+ end
187
+
188
+ def segment_row_classes(segment, depth)
189
+ classes = []
190
+
191
+ classes << "segment#{segment.parent_segment.segment_id}" if depth > 1
192
+
193
+ classes << "view_segment" if segment.metric_name.starts_with?('View')
194
+ classes << "summary_segment" if segment.is_a?(NewRelic::TransactionSample::CompositeSegment)
195
+
196
+ classes.join(' ')
197
+ end
198
+
199
+ # render_segment_details should be called before calling this method
200
+ def render_indentation_classes(depth)
201
+ styles = []
202
+ (1..depth).each do |d|
203
+ styles << ".segment_indent_level#{d} { display: inline-block; margin-left: #{(d-1)*20}px }"
204
+ end
205
+ content_tag("style", styles.join(' '))
206
+ end
207
+
208
+ def sql_link_mouseover_options(segment)
209
+ { :onmouseover => "sql_mouse_over(#{segment.segment_id})", :onmouseout => "sql_mouse_out(#{segment.segment_id})"}
210
+ end
211
+
212
+ def explain_sql_link(segment, child_sql = false)
213
+ link_to 'SQL', explain_sql_url(segment), sql_link_mouseover_options(segment)
214
+ end
215
+
216
+ def explain_sql_links(segment)
217
+ if segment[:sql_obfuscated] || segment[:sql]
218
+ explain_sql_link segment
219
+ else
220
+ links = []
221
+ segment.called_segments.each do |child|
222
+ if child[:sql_obfuscated] || child[:sql]
223
+ links << explain_sql_link(child, true)
224
+ end
225
+ end
226
+ links[0..1].join(', ') + (links.length > 2?', ...':'')
227
+ end
228
+ end
229
+
230
+ private
231
+ def file_and_line(stack_trace_line)
232
+ stack_trace_line.match(/(.*):(\d+)/)[1..2]
233
+ end
234
+
235
+ def using_textmate?
236
+ # For now, disable textmate integration
237
+ false
238
+ end
239
+
240
+
241
+ def render_segment_details(segment, depth=0)
242
+
243
+ @indentation_depth = depth if depth > @indentation_depth
244
+ repeat = nil
245
+ if segment.is_a?(NewRelic::TransactionSample::CompositeSegment)
246
+ html = ''
247
+ else
248
+ repeat = segment.parent_segment.detail_segments.length if segment.parent_segment.is_a?(NewRelic::TransactionSample::CompositeSegment)
249
+ html = render(:partial => agent_views_path('segment'), :object => segment, :locals => {:indent => depth, :repeat => repeat})
250
+ depth += 1
251
+ end
252
+
253
+ segment.called_segments.each do |child|
254
+ html << render_segment_details(child, depth)
255
+ end
256
+
257
+ html
258
+ end
259
+
260
+ def exclude_file_from_stack_trace?(file, include_rails)
261
+ !include_rails && (
262
+ file =~ /\/active(_)*record\// ||
263
+ file =~ /\/action(_)*controller\// ||
264
+ file =~ /\/activesupport\// ||
265
+ file =~ /\/lib\/mongrel/ ||
266
+ file =~ /\/actionpack\// ||
267
+ file =~ /\/passenger\// ||
268
+ file =~ /\/benchmark.rb/ ||
269
+ file !~ /\.rb/) # must be a .rb file, otherwise it's a script of something else...we could have gotten trickier and tried to see if this file exists...
270
+ end
271
+
272
+ def show_view_link(title, page_name)
273
+ link_to_function("[#{title}]", "show_view('#{page_name}')");
274
+ end
275
+ def mime_type_from_extension(extension)
276
+ extension = extension[/[^.]*$/].downcase
277
+ case extension
278
+ when 'png': 'image/png'
279
+ when 'gif': 'image/gif'
280
+ when 'jpg': 'image/jpg'
281
+ when 'css': 'text/css'
282
+ when 'js': 'text/javascript'
283
+ else 'text/plain'
284
+ end
285
+ end
286
+ end