newrelic_rpm 2.14.1 → 3.0.0.beta1

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 (123) hide show
  1. data/CHANGELOG +8 -0
  2. data/README.rdoc +2 -0
  3. data/install.rb +2 -2
  4. data/lib/new_relic/agent.rb +34 -1
  5. data/lib/new_relic/agent/agent.rb +34 -25
  6. data/lib/new_relic/agent/browser_monitoring.rb +111 -0
  7. data/lib/new_relic/agent/error_collector.rb +4 -4
  8. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +3 -3
  9. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +5 -7
  10. data/lib/new_relic/agent/instrumentation/data_mapper.rb +8 -8
  11. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +1 -1
  12. data/lib/new_relic/agent/instrumentation/memcache.rb +1 -1
  13. data/lib/new_relic/agent/instrumentation/merb/controller.rb +1 -1
  14. data/lib/new_relic/agent/instrumentation/merb/errors.rb +1 -1
  15. data/lib/new_relic/agent/instrumentation/metric_frame.rb +1 -0
  16. data/lib/new_relic/agent/instrumentation/queue_time.rb +26 -26
  17. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +1 -1
  18. data/lib/new_relic/agent/instrumentation/rails/errors.rb +1 -1
  19. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +2 -2
  20. data/lib/new_relic/agent/instrumentation/sinatra.rb +1 -1
  21. data/lib/new_relic/agent/method_tracer.rb +15 -15
  22. data/lib/new_relic/agent/shim_agent.rb +2 -0
  23. data/lib/new_relic/agent/stats_engine/metric_stats.rb +3 -3
  24. data/lib/new_relic/agent/stats_engine/samplers.rb +2 -2
  25. data/lib/new_relic/agent/stats_engine/transactions.rb +2 -1
  26. data/lib/new_relic/agent/transaction_sample_builder.rb +101 -0
  27. data/lib/new_relic/agent/transaction_sampler.rb +299 -251
  28. data/lib/new_relic/control.rb +2 -2
  29. data/lib/new_relic/control/class_methods.rb +0 -5
  30. data/lib/new_relic/control/configuration.rb +4 -3
  31. data/lib/new_relic/control/frameworks/rails.rb +9 -12
  32. data/lib/new_relic/control/instance_methods.rb +2 -2
  33. data/lib/new_relic/control/instrumentation.rb +1 -1
  34. data/lib/new_relic/control/server_methods.rb +2 -2
  35. data/lib/new_relic/delayed_job_injection.rb +1 -1
  36. data/lib/new_relic/local_environment.rb +7 -7
  37. data/lib/new_relic/rack/browser_monitoring.rb +61 -0
  38. data/lib/new_relic/stats.rb +6 -6
  39. data/lib/new_relic/version.rb +4 -4
  40. data/newrelic.yml +19 -0
  41. data/newrelic_rpm.gemspec +9 -4
  42. data/test/active_record_fixtures.rb +5 -5
  43. data/test/config/test_control.rb +3 -3
  44. data/test/new_relic/agent/agent/connect_test.rb +27 -6
  45. data/test/new_relic/agent/agent/start_test.rb +13 -13
  46. data/test/new_relic/agent/agent/start_worker_thread_test.rb +8 -8
  47. data/test/new_relic/agent/agent_test.rb +85 -0
  48. data/test/new_relic/agent/agent_test_controller.rb +9 -9
  49. data/test/new_relic/agent/agent_test_controller_test.rb +37 -37
  50. data/test/new_relic/agent/browser_monitoring_test.rb +124 -0
  51. data/test/new_relic/agent/busy_calculator_test.rb +7 -7
  52. data/test/new_relic/agent/error_collector/notice_error_test.rb +9 -9
  53. data/test/new_relic/agent/error_collector_test.rb +54 -54
  54. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +69 -69
  55. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +36 -0
  56. data/test/new_relic/agent/instrumentation/metric_frame_test.rb +3 -3
  57. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +11 -11
  58. data/test/new_relic/agent/instrumentation/queue_time_test.rb +38 -35
  59. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +18 -18
  60. data/test/new_relic/agent/memcache_instrumentation_test.rb +12 -12
  61. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +1 -1
  62. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +16 -15
  63. data/test/new_relic/agent/method_tracer_test.rb +60 -60
  64. data/test/new_relic/agent/mock_scope_listener.rb +8 -8
  65. data/test/new_relic/agent/rpm_agent_test.rb +26 -26
  66. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +17 -17
  67. data/test/new_relic/agent/stats_engine/samplers_test.rb +4 -4
  68. data/test/new_relic/agent/stats_engine/stats_engine_test.rb +51 -51
  69. data/test/new_relic/agent/transaction_sample_builder_test.rb +36 -36
  70. data/test/new_relic/agent/transaction_sampler_test.rb +727 -178
  71. data/test/new_relic/agent/worker_loop_test.rb +4 -4
  72. data/test/new_relic/collection_helper_test.rb +15 -15
  73. data/test/new_relic/command/deployments_test.rb +5 -5
  74. data/test/new_relic/control_test.rb +25 -25
  75. data/test/new_relic/local_environment_test.rb +11 -11
  76. data/test/new_relic/metric_spec_test.rb +21 -21
  77. data/test/new_relic/rack/episodes_test.rb +35 -35
  78. data/test/new_relic/stats_test.rb +61 -43
  79. data/test/new_relic/transaction_sample_subtest_test.rb +15 -15
  80. data/test/new_relic/transaction_sample_test.rb +25 -25
  81. data/test/new_relic/version_number_test.rb +11 -11
  82. data/test/test_contexts.rb +7 -7
  83. data/test/test_helper.rb +6 -6
  84. data/ui/helpers/developer_mode_helper.rb +67 -67
  85. data/ui/helpers/google_pie_chart.rb +4 -4
  86. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +4 -4
  87. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/action_mailer.rb +3 -3
  88. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_merchant.rb +7 -7
  89. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_record.rb +1 -1
  90. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/apdex.rb +9 -9
  91. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/background_transaction.rb +1 -1
  92. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/client.rb +8 -8
  93. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller.rb +9 -9
  94. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_cpu.rb +4 -4
  95. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_ext.rb +2 -2
  96. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database.rb +8 -8
  97. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database_pool.rb +3 -3
  98. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net.rb +6 -6
  99. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net_parser.rb +3 -3
  100. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/external.rb +2 -2
  101. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/frontend.rb +6 -6
  102. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/gc.rb +2 -2
  103. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/hibernate_session.rb +1 -1
  104. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java.rb +4 -4
  105. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java_parser.rb +3 -3
  106. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp.rb +4 -4
  107. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp_tag.rb +1 -1
  108. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +1 -1
  109. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +21 -21
  110. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/orm.rb +2 -2
  111. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/other_transaction.rb +6 -6
  112. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet.rb +2 -2
  113. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_context_listener.rb +1 -1
  114. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_filter.rb +1 -1
  115. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr.rb +3 -3
  116. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr_request_handler.rb +1 -1
  117. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring.rb +8 -8
  118. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_action.rb +3 -3
  119. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_result.rb +3 -3
  120. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +5 -5
  121. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_transaction.rb +20 -20
  122. metadata +15 -9
  123. data/lib/new_relic/agent/instrumentation/sequel.rb +0 -109
@@ -1,49 +1,49 @@
1
1
  class NewRelic::TransactionSample::SubTest < Test::Unit::TestCase
2
2
  def setup
3
3
  @t = NewRelic::TransactionSample.new
4
-
4
+
5
5
  @t.params[:test] = "hi"
6
-
6
+
7
7
  s1 = @t.create_segment(1.0, "controller")
8
-
8
+
9
9
  @t.root_segment.add_called_segment(s1)
10
-
10
+
11
11
  s2 = @t.create_segment(2.0, "AR1")
12
-
12
+
13
13
  s2.params[:test] = "test"
14
-
14
+
15
15
  s1.add_called_segment(s2)
16
16
  s2.end_trace 3.0
17
17
  s1.end_trace 4.0
18
-
18
+
19
19
  s3 = @t.create_segment(4.0, "post_filter")
20
20
  @t.root_segment.add_called_segment(s3)
21
21
  s3.end_trace 6.0
22
-
22
+
23
23
  s4 = @t.create_segment(6.0, "post_filter")
24
24
  @t.root_segment.add_called_segment(s4)
25
25
  s4.end_trace 7.0
26
26
  end
27
-
27
+
28
28
  def test_exclusive_duration
29
29
  s1 = @t.root_segment.called_segments.first
30
30
  assert_equal 3.0, s1.duration
31
31
  assert_equal 2.0, s1.exclusive_duration
32
32
  end
33
-
33
+
34
34
  def test_count_the_segments
35
35
  assert_equal 4, @t.count_segments
36
36
  end
37
-
37
+
38
38
  def test_truncate_long_samples
39
39
  @t.truncate(2)
40
40
  assert_equal 2, @t.count_segments
41
-
41
+
42
42
  @t = NewRelic::TransactionSample.new
43
-
43
+
44
44
  s1 = @t.create_segment(1.0, "controller")
45
45
  @t.root_segment.add_called_segment(s1)
46
-
46
+
47
47
  100.times do
48
48
  s1.add_called_segment(@t.create_segment(1.0, "segment"))
49
49
  end
@@ -52,5 +52,5 @@ class NewRelic::TransactionSample::SubTest < Test::Unit::TestCase
52
52
  assert_equal 2, @t.count_segments
53
53
  assert_equal 101, @t.params[:segment_count]
54
54
  end
55
-
55
+
56
56
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper.rb', __FILE__)
1
+ require File.expand_path('../../test_helper.rb', __FILE__)
2
2
 
3
3
  class NewRelic::TransactionSampleTest < Test::Unit::TestCase
4
4
  include TransactionSampleTestHelper
@@ -7,23 +7,23 @@ class NewRelic::TransactionSampleTest < Test::Unit::TestCase
7
7
  def setup
8
8
  @connection_stub = Mocha::Mockery.instance.named_mock('connection')
9
9
  @connection_stub.stubs(:execute).returns('QUERY RESULT')
10
-
10
+
11
11
  NewRelic::TransactionSample.stubs(:get_connection).returns @connection_stub
12
12
  @t = make_sql_transaction(::SQL_STATEMENT, ::SQL_STATEMENT)
13
13
  end
14
-
14
+
15
15
  def test_be_recorded
16
16
  assert_not_nil @t
17
17
  end
18
-
18
+
19
19
  def test_not_record_sql_when_record_sql_off
20
20
  s = @t.prepare_to_send(:explain_sql => 0.00000001)
21
21
  s.each_segment do |segment|
22
22
  assert_nil segment.params[:explanation]
23
23
  assert_nil segment.params[:sql]
24
- end
24
+ end
25
25
  end
26
-
26
+
27
27
  def test_record_raw_sql
28
28
  s = @t.prepare_to_send(:explain_sql => 0.00000001, :record_sql => :raw)
29
29
  got_one = false
@@ -33,58 +33,58 @@ class NewRelic::TransactionSampleTest < Test::Unit::TestCase
33
33
  end
34
34
  assert got_one
35
35
  end
36
-
36
+
37
37
  def test_record_obfuscated_sql
38
-
38
+
39
39
  s = @t.prepare_to_send(:explain_sql => 0.00000001, :record_sql => :obfuscated)
40
40
 
41
41
  got_one = false
42
42
  s.each_segment do |segment|
43
43
  got_one = got_one || segment.params[:explanation] || segment.params[:sql]
44
- end
45
-
44
+ end
45
+
46
46
  assert got_one
47
47
  end
48
-
48
+
49
49
  def test_have_sql_rows_when_sql_is_recorded
50
50
  s = @t.prepare_to_send(:explain_sql => 0.00000001)
51
-
51
+
52
52
  assert s.sql_segments.empty?
53
53
  s.root_segment[:sql] = 'hello'
54
54
  assert !s.sql_segments.empty?
55
55
  end
56
-
56
+
57
57
  def test_have_sql_rows_when_sql_is_obfuscated
58
58
  s = @t.prepare_to_send(:explain_sql => 0.00000001)
59
-
59
+
60
60
  assert s.sql_segments.empty?
61
61
  s.root_segment[:sql_obfuscated] = 'hello'
62
62
  assert !s.sql_segments.empty?
63
63
  end
64
-
64
+
65
65
  def test_have_sql_rows_when_recording_non_sql_keys
66
66
  s = @t.prepare_to_send(:explain_sql => 0.00000001)
67
-
67
+
68
68
  assert s.sql_segments.empty?
69
69
  s.root_segment[:key] = 'hello'
70
70
  assert !s.sql_segments.empty?
71
71
  end
72
-
72
+
73
73
  def test_catch_exceptions
74
74
  @connection_stub.expects(:execute).raises
75
75
  # the sql connection will throw
76
76
  @t.prepare_to_send(:record_sql => :obfuscated, :explain_sql => 0.00000001)
77
77
  end
78
-
78
+
79
79
  def test_have_explains
80
-
80
+
81
81
  s = @t.prepare_to_send(:record_sql => :obfuscated, :explain_sql => 0.00000001)
82
-
82
+
83
83
  explain_count = 0
84
84
  s.each_segment do |segment|
85
85
  if segment.params[:explanation]
86
86
  explanations = segment.params[:explanation]
87
-
87
+
88
88
  explanations.each do |explanation|
89
89
  assert_kind_of Array, explanation
90
90
  assert_kind_of Array, explanation[0]
@@ -101,14 +101,14 @@ class NewRelic::TransactionSampleTest < Test::Unit::TestCase
101
101
  NewRelic::Agent.disable_sql_recording do
102
102
  t = make_sql_transaction(::SQL_STATEMENT, ::SQL_STATEMENT)
103
103
  end
104
-
104
+
105
105
  s = t.prepare_to_send(:explain_sql => 0.00000001)
106
-
106
+
107
107
  s.each_segment do |segment|
108
108
  assert_nil segment.params[:explanation]
109
109
  assert_nil segment.params[:sql]
110
110
  end
111
- end
111
+ end
112
112
 
113
113
  def test_not_record_transactions
114
114
  NewRelic::Agent.disable_transaction_tracing do
@@ -116,5 +116,5 @@ class NewRelic::TransactionSampleTest < Test::Unit::TestCase
116
116
  assert t.nil?
117
117
  end
118
118
  end
119
-
119
+
120
120
  end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
2
2
  class NewRelic::VersionNumberTest < Test::Unit::TestCase
3
-
3
+
4
4
  def test_comparison__first
5
5
  versions = %w[1.0.0 0.1.0 0.0.1 10.0.1 1.10.0].map {|s| NewRelic::VersionNumber.new s }
6
6
  assert_equal %w[0.0.1 0.1.0 1.0.0 1.10.0 10.0.1], versions.sort.map(&:to_s)
@@ -35,14 +35,14 @@ class NewRelic::VersionNumberTest < Test::Unit::TestCase
35
35
  assert v3 > v0
36
36
  end
37
37
  def test_sort
38
- values = %w[1.1.1
39
- 1.1.99
40
- 1.1.999
41
- 2.0.6
42
- 2.6.5
43
- 2.7
44
- 2.7.1
45
- 2.7.2
38
+ values = %w[1.1.1
39
+ 1.1.99
40
+ 1.1.999
41
+ 2.0.6
42
+ 2.6.5
43
+ 2.7
44
+ 2.7.1
45
+ 2.7.2
46
46
  2.7.2.0
47
47
  3
48
48
  999]
@@ -59,7 +59,7 @@ class NewRelic::VersionNumberTest < Test::Unit::TestCase
59
59
  assert v0 < '1.2.0'
60
60
  assert v0 < '1.2.0.c'
61
61
  assert v0 < '1.2.0.0'
62
-
62
+
63
63
  end
64
64
  def test_compare_string
65
65
  v0 = NewRelic::VersionNumber.new '1.2.0'
@@ -86,4 +86,4 @@ class NewRelic::VersionNumberTest < Test::Unit::TestCase
86
86
  assert_equal '1.2.0', NewRelic::VersionNumber.new('1.2.0').to_s
87
87
  assert_equal '1.2', NewRelic::VersionNumber.new('1.2').to_s
88
88
  end
89
- end
89
+ end
@@ -1,21 +1,21 @@
1
1
 
2
2
  module TestContexts
3
3
  def with_running_agent
4
-
4
+
5
5
  context 'with running agent' do # this is needed for the nested setups
6
-
6
+
7
7
  setup do
8
8
  @log_data = StringIO.new
9
9
  @log = Logger.new(@log_data)
10
- NewRelic::Agent.manual_start :log => @log
10
+ NewRelic::Agent.manual_start :log => @log
11
11
  @agent = NewRelic::Agent.instance
12
12
  @agent.transaction_sampler.send :clear_builder
13
13
  @agent.transaction_sampler.reset!
14
14
  @agent.stats_engine.clear_stats
15
15
  end
16
-
16
+
17
17
  yield
18
-
18
+
19
19
  def teardown
20
20
  super
21
21
  NewRelic::Agent.shutdown
@@ -23,7 +23,7 @@ module TestContexts
23
23
  NewRelic::Control.instance['dispatcher']=nil
24
24
  NewRelic::Control.instance['dispatcher_instance_id']=nil
25
25
  end
26
-
26
+
27
27
  end
28
28
  end
29
- end
29
+ end
@@ -9,7 +9,7 @@ $LOAD_PATH.uniq!
9
9
 
10
10
  require 'rubygems'
11
11
  # We can speed things up in tests that don't need to load rails.
12
- # You can also run the tests in a mode without rails. Many tests
12
+ # You can also run the tests in a mode without rails. Many tests
13
13
  # will be skipped.
14
14
 
15
15
  begin
@@ -19,7 +19,7 @@ begin
19
19
  rescue LoadError
20
20
  # ignore load problems on test help - it doesn't exist in rails 3
21
21
  end
22
-
22
+
23
23
  rescue LoadError
24
24
  puts "Unable to load Rails for New Relic tests"
25
25
  raise
@@ -121,16 +121,16 @@ module TransactionSampleTestHelper
121
121
  sampler.notice_first_scope_push Time.now.to_f
122
122
  sampler.notice_transaction '/path', nil, :jim => "cool"
123
123
  sampler.notice_push_scope "a"
124
-
124
+
125
125
  sampler.notice_transaction '/path/2', nil, :jim => "cool"
126
-
126
+
127
127
  sql.each {|sql_statement| sampler.notice_sql(sql_statement, {:adapter => "test"}, 0 ) }
128
-
128
+
129
129
  sleep 1.0
130
130
  yield if block_given?
131
131
  sampler.notice_pop_scope "a"
132
132
  sampler.notice_scope_empty
133
-
133
+
134
134
  sampler.samples[0]
135
135
  end
136
136
  end
@@ -6,23 +6,23 @@ module NewRelic::DeveloperModeHelper
6
6
  include NewRelic::CollectionHelper
7
7
 
8
8
  private
9
-
9
+
10
10
  # limit of how many detail/SQL rows we display - very large data sets (~10000+) crash browsers
11
11
  def trace_row_display_limit
12
12
  2000
13
13
  end
14
-
14
+
15
15
  def trace_row_display_limit_reached
16
16
  (!@detail_segment_count.nil? && @detail_segment_count > trace_row_display_limit) || @sample.sql_segments.length > trace_row_display_limit
17
17
  end
18
-
18
+
19
19
  # return the sample but post processed to strip out segments that normally don't show
20
20
  # up in production (after the first execution, at least) such as application code loading
21
21
  def stripped_sample(sample = @sample)
22
22
  sample.omit_segments_with('(Rails/Application Code Loading)|(Database/.*/.+ Columns)')
23
23
  end
24
-
25
- # return the highest level in the call stack for the trace that is not rails or
24
+
25
+ # return the highest level in the call stack for the trace that is not rails or
26
26
  # newrelic agent code
27
27
  def application_caller(trace)
28
28
  trace = strip_nr_from_backtrace(trace) unless params[:show_nr]
@@ -34,7 +34,7 @@ module NewRelic::DeveloperModeHelper
34
34
  end
35
35
  trace.last
36
36
  end
37
-
37
+
38
38
  def application_stack_trace(trace, include_rails = false)
39
39
  trace = strip_nr_from_backtrace(trace) unless params[:show_nr]
40
40
  trace.reject do |trace_line|
@@ -42,10 +42,10 @@ module NewRelic::DeveloperModeHelper
42
42
  exclude_file_from_stack_trace?(file, include_rails)
43
43
  end
44
44
  end
45
-
45
+
46
46
  def render_backtrace
47
47
  if @segment[:backtrace]
48
- content_tag('h3', 'Application Stack Trace') +
48
+ content_tag('h3', 'Application Stack Trace') +
49
49
  render(:partial => 'stack_trace')
50
50
  end
51
51
  end
@@ -53,35 +53,35 @@ module NewRelic::DeveloperModeHelper
53
53
  def h(text)
54
54
  text
55
55
  end
56
-
56
+
57
57
  def agent_views_path(path)
58
58
  path
59
59
  end
60
-
60
+
61
61
  def url_for_source(trace_line)
62
62
  file, line = file_and_line(trace_line)
63
-
63
+
64
64
  begin
65
65
  file = Pathname.new(file).realpath
66
66
  rescue Errno::ENOENT
67
67
  # we hit this exception when Pathame.realpath fails for some reason; attempt a link to
68
68
  # the file without a real path. It may also fail, only when the user clicks on this specific
69
69
  # entry in the stack trace
70
- rescue
70
+ rescue
71
71
  # catch all other exceptions. We're going to create an invalid link below, but that's okay.
72
72
  end
73
-
73
+
74
74
  if using_textmate?
75
75
  "txmt://open?url=file://#{file}&line=#{line}"
76
76
  else
77
77
  "show_source?file=#{file}&amp;line=#{line}&amp;anchor=selected_line"
78
78
  end
79
79
  end
80
-
80
+
81
81
  def dev_name(metric_name)
82
82
  NewRelic::MetricParser::MetricParser.parse(metric_name).developer_name
83
83
  end
84
-
84
+
85
85
  # write the metric label for a segment metric in the detail view
86
86
  def write_segment_label(segment)
87
87
  if source_available && segment[:backtrace] && (source_url = url_for_source(application_caller(segment[:backtrace])))
@@ -90,36 +90,36 @@ module NewRelic::DeveloperModeHelper
90
90
  dev_name(segment.metric_name)
91
91
  end
92
92
  end
93
-
93
+
94
94
  def source_available
95
95
  true
96
96
  end
97
-
97
+
98
98
  # write the metric label for a segment metric in the summary table of metrics
99
99
  def write_summary_segment_label(segment)
100
100
  dev_name(segment.metric_name)
101
101
  end
102
-
102
+
103
103
  def write_stack_trace_line(trace_line)
104
104
  link_to trace_line, url_for_source(trace_line)
105
105
  end
106
-
106
+
107
107
  # write a link to the source for a trace
108
108
  def link_to_source(trace)
109
109
  image_url = 'file/images/' + (using_textmate? ? "textmate.png" : "file_icon.png")
110
-
110
+
111
111
  link_to "<img src=#{image_url} alt=\"View Source\" title=\"View Source\"/>", url_for_source(application_caller(trace))
112
112
  end
113
-
113
+
114
114
  # print the formatted timestamp for a segment
115
115
  def timestamp(segment)
116
116
  sprintf("%1.3f", segment.entry_timestamp)
117
117
  end
118
-
118
+
119
119
  def format_timestamp(time)
120
- time.strftime("%H:%M:%S")
120
+ time.strftime("%H:%M:%S")
121
121
  end
122
-
122
+
123
123
  def colorize(value, yellow_threshold = 0.05, red_threshold = 0.15, s=to_ms(value))
124
124
  if value > yellow_threshold
125
125
  color = (value > red_threshold ? 'red' : 'orange')
@@ -128,42 +128,42 @@ module NewRelic::DeveloperModeHelper
128
128
  "#{s}"
129
129
  end
130
130
  end
131
-
131
+
132
132
  def expanded_image_path()
133
133
  '/newrelic/file/images/arrow-open.png'
134
134
  end
135
-
135
+
136
136
  def collapsed_image_path()
137
137
  '/newrelic/file/images/arrow-close.png'
138
138
  end
139
-
139
+
140
140
  def explain_sql_url(segment)
141
141
  "explain_sql?id=#{@sample.sample_id}&amp;segment=#{segment.segment_id}"
142
142
  end
143
-
143
+
144
144
  def segment_duration_value(segment)
145
145
  link_to colorize(segment.duration, 0.05, 0.15, "#{with_delimiter(to_ms(segment.duration))} ms"), explain_sql_url(segment)
146
146
  end
147
-
147
+
148
148
  def line_wrap_sql(sql)
149
149
  sql.gsub(/\,/,', ').squeeze(' ') if sql
150
150
  end
151
-
151
+
152
152
  def render_sample_details(sample)
153
153
  @indentation_depth=0
154
154
  # skip past the root segments to the first child, which is always the controller
155
155
  first_segment = sample.root_segment.called_segments.first
156
-
156
+
157
157
  # render the segments, then the css classes to indent them
158
158
  render_segment_details(first_segment).to_s + render_indentation_classes(@indentation_depth).to_s
159
159
  end
160
-
160
+
161
161
  # the rows logger plugin disables the sql tracing functionality of the NewRelic agent -
162
162
  # notify the user about this
163
163
  def rows_logger_present?
164
164
  File.exist?(File.join(File.dirname(__FILE__), "../../../rows_logger/init.rb"))
165
165
  end
166
-
166
+
167
167
  def expand_segment_image(segment, depth)
168
168
  if depth > 0
169
169
  if !segment.called_segments.empty?
@@ -172,49 +172,49 @@ module NewRelic::DeveloperModeHelper
172
172
  end
173
173
  end
174
174
  end
175
-
175
+
176
176
  def segment_child_row_class(segment)
177
177
  "segment#{segment.segment_id}"
178
178
  end
179
-
179
+
180
180
  def summary_pie_chart(sample, width, height)
181
181
  pie_chart = GooglePieChart.new
182
182
  pie_chart.color, pie_chart.width, pie_chart.height = '6688AA', width, height
183
-
183
+
184
184
  chart_data = sample.breakdown_data(6)
185
185
  chart_data.each { |s| pie_chart.add_data_point dev_name(s.metric_name), to_ms(s.exclusive_time) }
186
-
186
+
187
187
  pie_chart.render
188
188
  end
189
-
189
+
190
190
  def segment_row_classes(segment, depth)
191
191
  classes = []
192
-
193
- classes << "segment#{segment.parent_segment.segment_id}" if depth > 1
194
-
192
+
193
+ classes << "segment#{segment.parent_segment.segment_id}" if depth > 1
194
+
195
195
  classes << "view_segment" if segment.metric_name.index('View') == 0
196
196
  classes << "summary_segment" if segment.is_a?(NewRelic::TransactionSample::CompositeSegment)
197
-
197
+
198
198
  classes.join(' ')
199
199
  end
200
-
200
+
201
201
  # render_segment_details should be called before calling this method
202
202
  def render_indentation_classes(depth)
203
- styles = []
203
+ styles = []
204
204
  (1..depth).each do |d|
205
205
  styles << ".segment_indent_level#{d} { display: inline-block; margin-left: #{(d-1)*20}px }"
206
206
  end
207
- content_tag("style", styles.join(' '))
207
+ content_tag("style", styles.join(' '))
208
208
  end
209
-
209
+
210
210
  def sql_link_mouseover_options(segment)
211
211
  { :onmouseover => "sql_mouse_over(#{segment.segment_id})", :onmouseout => "sql_mouse_out(#{segment.segment_id})"}
212
212
  end
213
-
213
+
214
214
  def explain_sql_link(segment, child_sql = false)
215
215
  link_to 'SQL', explain_sql_url(segment)+ '"' + sql_link_mouseover_options(segment).map {|k,v| "#{k}=\"#{v}\""}.join(' ')+ 'fake=\"'
216
216
  end
217
-
217
+
218
218
  def explain_sql_links(segment)
219
219
  if segment[:sql]
220
220
  explain_sql_link segment
@@ -228,23 +228,23 @@ module NewRelic::DeveloperModeHelper
228
228
  links[0..1].join(', ') + (links.length > 2?', ...':'')
229
229
  end
230
230
  end
231
-
231
+
232
232
  private
233
233
  def file_and_line(stack_trace_line)
234
234
  stack_trace_line.match(/(.*):(\d+)/)[1..2]
235
235
  end
236
-
236
+
237
237
  def using_textmate?
238
238
  NewRelic::Control.instance.use_textmate?
239
239
  end
240
-
241
-
240
+
241
+
242
242
  def render_segment_details(segment, depth=0)
243
243
  @detail_segment_count ||= 0
244
244
  @detail_segment_count += 1
245
-
245
+
246
246
  return '' if @detail_segment_count > trace_row_display_limit
247
-
247
+
248
248
  @indentation_depth = depth if depth > @indentation_depth
249
249
  repeat = nil
250
250
  if segment.is_a?(NewRelic::TransactionSample::CompositeSegment)
@@ -254,34 +254,34 @@ module NewRelic::DeveloperModeHelper
254
254
  html = render(:partial => 'segment', :object => [segment, depth, repeat])
255
255
  depth += 1
256
256
  end
257
-
257
+
258
258
  segment.called_segments.each do |child|
259
259
  html << render_segment_details(child, depth)
260
260
  end
261
-
261
+
262
262
  html
263
263
  end
264
-
264
+
265
265
  def exclude_file_from_stack_trace?(file, include_rails)
266
266
  return false if include_rails
267
267
  return true if file !~ /\.(rb|java)/
268
- %w[/actionmailer/
269
- /activerecord
270
- /activeresource
271
- /activesupport
272
- /lib/mongrel
273
- /actionpack
268
+ %w[/actionmailer/
269
+ /activerecord
270
+ /activeresource
271
+ /activesupport
272
+ /lib/mongrel
273
+ /actionpack
274
274
  /passenger/
275
275
  /railties
276
276
  benchmark.rb].each { |s| return true if file.include? s }
277
277
  false
278
278
  end
279
-
279
+
280
280
  def show_view_link(title, page_name)
281
281
  link_to_function("[#{title}]", "show_view('#{page_name}')");
282
282
  end
283
283
 
284
-
284
+
285
285
  def link_to(name, location)
286
286
  location = "/newrelic/#{location}" unless /:\/\// =~ location
287
287
  "<a href=\"#{location}\">#{name}</a>"
@@ -302,7 +302,7 @@ module NewRelic::DeveloperModeHelper
302
302
  text
303
303
  end
304
304
  end
305
-
305
+
306
306
  def cycle(even, odd)
307
307
  @cycle ||= 'a'
308
308
  if @cycle == 'a'
@@ -341,7 +341,7 @@ module NewRelic::DeveloperModeHelper
341
341
  parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")
342
342
  parts.join '.'
343
343
  end
344
-
344
+
345
345
  def profile_table(profile)
346
346
  out = StringIO.new
347
347
  printer = RubyProf::GraphHtmlPrinter.new(profile)