newrelic_rpm 3.6.7.159 → 3.6.8.164

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. data/CHANGELOG +14 -0
  2. data/lib/new_relic/agent/agent.rb +38 -35
  3. data/lib/new_relic/agent/agent_logger.rb +6 -47
  4. data/lib/new_relic/agent/beacon_configuration.rb +10 -4
  5. data/lib/new_relic/agent/browser_monitoring.rb +39 -33
  6. data/lib/new_relic/agent/commands/agent_command.rb +4 -4
  7. data/lib/new_relic/agent/commands/agent_command_router.rb +72 -10
  8. data/lib/new_relic/agent/commands/thread_profiler_session.rb +110 -0
  9. data/lib/new_relic/agent/commands/xray_session.rb +55 -0
  10. data/lib/new_relic/agent/commands/xray_session_collection.rb +158 -0
  11. data/lib/new_relic/agent/configuration/default_source.rb +61 -24
  12. data/lib/new_relic/agent/configuration/mask_defaults.rb +2 -2
  13. data/lib/new_relic/agent/configuration/server_source.rb +1 -1
  14. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +2 -0
  15. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +4 -10
  16. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +10 -11
  17. data/lib/new_relic/agent/memory_logger.rb +52 -0
  18. data/lib/new_relic/agent/new_relic_service.rb +4 -0
  19. data/lib/new_relic/agent/request_sampler.rb +32 -13
  20. data/lib/new_relic/agent/samplers/cpu_sampler.rb +6 -3
  21. data/lib/new_relic/agent/threading/agent_thread.rb +2 -1
  22. data/lib/new_relic/agent/threading/backtrace_node.rb +80 -27
  23. data/lib/new_relic/agent/threading/backtrace_service.rb +264 -0
  24. data/lib/new_relic/agent/threading/thread_profile.rb +79 -118
  25. data/lib/new_relic/agent/transaction/developer_mode_sample_buffer.rb +56 -0
  26. data/lib/new_relic/agent/transaction/force_persist_sample_buffer.rb +25 -0
  27. data/lib/new_relic/agent/transaction/slowest_sample_buffer.rb +25 -0
  28. data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +86 -0
  29. data/lib/new_relic/agent/transaction/xray_sample_buffer.rb +64 -0
  30. data/lib/new_relic/agent/transaction.rb +25 -4
  31. data/lib/new_relic/agent/transaction_sample_builder.rb +6 -10
  32. data/lib/new_relic/agent/transaction_sampler.rb +47 -202
  33. data/lib/new_relic/agent/worker_loop.rb +47 -39
  34. data/lib/new_relic/agent.rb +1 -1
  35. data/lib/new_relic/build.rb +2 -2
  36. data/lib/new_relic/coerce.rb +8 -0
  37. data/lib/new_relic/control/instance_methods.rb +1 -0
  38. data/lib/new_relic/rack/browser_monitoring.rb +15 -1
  39. data/lib/new_relic/rack/developer_mode.rb +1 -1
  40. data/lib/new_relic/transaction_sample.rb +20 -5
  41. data/lib/new_relic/version.rb +1 -1
  42. data/newrelic.yml +4 -6
  43. data/newrelic_rpm.gemspec +1 -1
  44. data/test/agent_helper.rb +11 -0
  45. data/test/environments/lib/environments/runner.rb +5 -1
  46. data/test/environments/rails21/Gemfile +2 -2
  47. data/test/environments/rails22/Gemfile +2 -2
  48. data/test/environments/rails23/Gemfile +2 -2
  49. data/test/environments/rails31/Gemfile +2 -2
  50. data/test/environments/rails32/Gemfile +2 -2
  51. data/test/multiverse/suites/agent_only/marshaling_test.rb +1 -1
  52. data/test/multiverse/suites/agent_only/testing_app.rb +6 -0
  53. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +5 -5
  54. data/test/multiverse/suites/agent_only/xray_sessions_test.rb +163 -0
  55. data/test/multiverse/suites/rails/request_statistics_test.rb +2 -2
  56. data/test/multiverse/suites/rails/view_instrumentation_test.rb +20 -21
  57. data/test/new_relic/agent/agent/connect_test.rb +0 -10
  58. data/test/new_relic/agent/agent_test.rb +27 -44
  59. data/test/new_relic/agent/browser_monitoring_test.rb +0 -52
  60. data/test/new_relic/agent/commands/agent_command_router_test.rb +150 -12
  61. data/test/new_relic/agent/commands/{thread_profiler_test.rb → thread_profiler_session_test.rb} +58 -19
  62. data/test/new_relic/agent/commands/xray_session_collection_test.rb +332 -0
  63. data/test/new_relic/agent/commands/xray_session_test.rb +42 -0
  64. data/test/new_relic/agent/configuration/manager_test.rb +2 -1
  65. data/test/new_relic/agent/configuration/server_source_test.rb +10 -10
  66. data/test/new_relic/agent/cpu_sampler_test.rb +50 -0
  67. data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +31 -0
  68. data/test/new_relic/agent/instrumentation/queue_time_test.rb +0 -1
  69. data/test/new_relic/agent/instrumentation/sequel_test.rb +1 -1
  70. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +0 -1
  71. data/test/new_relic/agent/memory_logger_test.rb +53 -0
  72. data/test/new_relic/agent/new_relic_service_test.rb +1 -1
  73. data/test/new_relic/agent/pipe_channel_manager_test.rb +4 -5
  74. data/test/new_relic/agent/request_sampler_test.rb +70 -20
  75. data/test/new_relic/agent/rules_engine_test.rb +6 -0
  76. data/test/new_relic/agent/threading/agent_thread_test.rb +2 -2
  77. data/test/new_relic/agent/threading/backtrace_node_test.rb +110 -17
  78. data/test/new_relic/agent/threading/backtrace_service_test.rb +567 -0
  79. data/test/new_relic/agent/threading/fake_thread.rb +4 -0
  80. data/test/new_relic/agent/threading/thread_profile_test.rb +141 -217
  81. data/test/new_relic/agent/threading/threaded_test_case.rb +3 -8
  82. data/test/new_relic/agent/transaction/developer_mode_sample_buffer_test.rb +69 -0
  83. data/test/new_relic/agent/transaction/force_persist_sample_buffer_test.rb +52 -0
  84. data/test/new_relic/agent/transaction/slowest_sample_buffer_test.rb +67 -0
  85. data/test/new_relic/agent/transaction/xray_sample_buffer_test.rb +71 -0
  86. data/test/new_relic/agent/transaction_sampler_test.rb +171 -307
  87. data/test/new_relic/agent/transaction_test.rb +33 -5
  88. data/test/new_relic/agent/worker_loop_test.rb +33 -11
  89. data/test/new_relic/coerce_test.rb +13 -0
  90. data/test/new_relic/fake_collector.rb +26 -3
  91. data/test/new_relic/multiverse_helpers.rb +2 -0
  92. data/test/new_relic/rack/browser_monitoring_test.rb +12 -0
  93. data/test/new_relic/rack/developer_mode_test.rb +2 -2
  94. data/test/new_relic/transaction_sample_test.rb +19 -2
  95. data/test/performance/lib/performance/console_reporter.rb +1 -1
  96. data/test/performance/lib/performance/test_case.rb +7 -3
  97. data/test/performance/script/runner +3 -0
  98. data/test/performance/suites/thread_profiling.rb +83 -0
  99. data/test/test_helper.rb +2 -2
  100. data.tar.gz.sig +0 -0
  101. metadata +32 -32
  102. metadata.gz.sig +1 -1
  103. data/lib/new_relic/agent/commands/thread_profiler.rb +0 -80
@@ -26,6 +26,10 @@ class FakeThread
26
26
  thread[:scrubbed_backtrace] || thread.backtrace
27
27
  end
28
28
 
29
+ def alive?
30
+ true
31
+ end
32
+
29
33
  def key?(key)
30
34
  @locals.key?(key)
31
35
  end
@@ -4,16 +4,18 @@
4
4
 
5
5
  require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
6
6
 
7
+ require 'new_relic/agent/threading/backtrace_service'
7
8
  require 'new_relic/agent/threading/thread_profile'
8
9
  require 'new_relic/agent/threading/threaded_test_case'
9
10
 
10
- if NewRelic::Agent::Commands::ThreadProfiler.is_supported?
11
+ if NewRelic::Agent::Threading::BacktraceService.is_supported?
11
12
 
12
13
  module NewRelic::Agent::Threading
13
- class ThreadProfileTest < ThreadedTestCase
14
+ class ThreadProfileTest < Test::Unit::TestCase
15
+ include ThreadedTestCase
14
16
 
15
17
  def setup
16
- super
18
+ setup_fake_threads
17
19
 
18
20
  @single_trace = [
19
21
  "irb.rb:69:in `catch'",
@@ -21,286 +23,208 @@ if NewRelic::Agent::Commands::ThreadProfiler.is_supported?
21
23
  "irb:12:in `<main>'"
22
24
  ]
23
25
 
24
- @profile = ThreadProfile.new(create_agent_command)
26
+ @profile = ThreadProfile.new
25
27
 
26
28
  # Run the worker_loop for the thread profile based on two iterations
27
29
  # This takes time fussiness out of the equation and keeps the tests stable
28
30
  @profile.instance_variable_set(:@worker_loop, NewRelic::Agent::WorkerLoop.new(:limit => 2))
29
31
  end
30
32
 
31
- # Running Tests
32
- def test_profiler_collects_backtrace_from_every_thread
33
- FakeThread.list << FakeThread.new
34
- FakeThread.list << FakeThread.new
35
-
36
- @profile.run
37
-
38
- assert_equal 2, @profile.poll_count
39
- assert_equal 4, @profile.sample_count
33
+ def teardown
34
+ teardown_fake_threads
40
35
  end
41
36
 
42
- def test_profiler_collects_into_request_bucket
43
- FakeThread.list << FakeThread.new(
44
- :bucket => :request,
45
- :backtrace => @single_trace)
46
-
47
- @profile.run
48
-
49
- assert_equal 1, @profile.traces[:request].size
37
+ def target_for_shared_client_tests
38
+ @profile
50
39
  end
51
40
 
52
- def test_profiler_collects_into_background_bucket
53
- FakeThread.list << FakeThread.new(
54
- :bucket => :background,
55
- :backtrace => @single_trace)
41
+ def test_prune_tree
42
+ @profile.aggregate(@single_trace, :request, Thread.current)
56
43
 
57
- @profile.run
44
+ @profile.truncate_to_node_count!(1)
58
45
 
59
- assert_equal 1, @profile.traces[:background].size
46
+ assert_equal 0, @profile.traces[:request].children.first.children.size
60
47
  end
61
48
 
62
- def test_profiler_collects_into_other_bucket
63
- FakeThread.list << FakeThread.new(
64
- :bucket => :other,
65
- :backtrace => @single_trace)
49
+ def test_prune_keeps_highest_counts
50
+ @profile.aggregate(@single_trace, :request, Thread.current)
51
+ @profile.aggregate(@single_trace, :other, Thread.current)
52
+ @profile.aggregate(@single_trace, :other, Thread.current)
66
53
 
67
- @profile.run
54
+ @profile.truncate_to_node_count!(1)
68
55
 
69
- assert_equal 1, @profile.traces[:other].size
56
+ assert_empty @profile.traces[:request]
57
+ assert_equal 1, @profile.traces[:other].children.size
58
+ assert_equal [], @profile.traces[:other].children.first.children
70
59
  end
71
60
 
72
- def test_profiler_collects_into_agent_bucket
73
- FakeThread.list << FakeThread.new(
74
- :bucket => :agent,
75
- :backtrace => @single_trace)
61
+ def test_prune_keeps_highest_count_then_depths
62
+ @profile.aggregate(@single_trace, :request, Thread.current)
63
+ @profile.aggregate(@single_trace, :other, Thread.current)
76
64
 
77
- @profile.run
65
+ @profile.truncate_to_node_count!(2)
78
66
 
79
- assert_equal 1, @profile.traces[:agent].size
67
+ assert_equal 1, @profile.traces[:request].children.size
68
+ assert_equal 1, @profile.traces[:other].children.size
69
+ assert_equal [], @profile.traces[:request].children.first.children
70
+ assert_equal [], @profile.traces[:other].children.first.children
80
71
  end
81
72
 
82
- def test_profiler_ignores_agent_threads_when_told_to
83
- FakeThread.list << FakeThread.new(
84
- :bucket => :ignore,
85
- :backtrace => @single_trace)
86
-
87
- @profile.run
88
-
89
- @profile.traces.each do |key, trace|
90
- assert trace.empty?, "Trace :#{key} should have been empty"
91
- end
92
- end
73
+ def build_well_known_trace(args={})
74
+ @profile = ThreadProfile.new(args)
93
75
 
94
- def test_profiler_tries_to_scrub_backtraces
95
- FakeThread.list << FakeThread.new(
96
- :bucket => :agent,
97
- :backtrace => @single_trace,
98
- :scrubbed_backtrace => @single_trace[0..0])
76
+ thread = stub
77
+ trace = ["thread_profiler.py:1:in `<module>'"]
78
+ 10.times { @profile.aggregate(trace, :other, thread) }
99
79
 
100
- @profile.run
80
+ thread = stub
81
+ trace = [
82
+ "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py:489:in `__bootstrap'",
83
+ "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py:512:in `__bootstrap_inner'",
84
+ "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py:480:in `run'",
85
+ "thread_profiler.py:76:in `_profiler_loop'",
86
+ "thread_profiler.py:103:in `_run_profiler'",
87
+ "thread_profiler.py:165:in `collect_thread_stacks'"
88
+ ]
89
+ 10.times { @profile.aggregate(trace, :agent, thread) }
101
90
 
102
- assert_equal [], @profile.traces[:agent].first.children
91
+ @profile.increment_poll_count
103
92
  end
104
93
 
105
- def test_profile_can_be_stopped
106
- # Can't easily stop in middle of processing since FakeThread's synchronous
107
- # Mark to bail immediately, then see we didn't record anything
108
- @profile.stop
109
-
110
- @profile.run
111
-
112
- assert_not_nil @profile.stop_time
113
- assert_equal true, @profile.finished?
94
+ WELL_KNOWN_TRACE_ENCODED = "eJy9klFPwjAUhf/LfW7WDQTUGBPUiYkGdAxelqXZRpGGrm1uS8xi/O924JQX\n9Un7dm77ndN7c19hlt7FCZxnWQZug7xYMYN6LSTHwDRA4KLWq53kl0CinEQh\nCUmW5zmBJH5axPPUk16MJ/E0/cGk0lLyyrGPS+uKamu943DQeX5HMtypz5In\nwv6vRCeZ1NoAGQ2PCDpvrOM1fRAlFtjQWyxq/qJxa+lj4zZaBeuuQpccrdDK\n0l4wolKU1OxftOoQLNTzIdL/EcjJafjnQYyVWjvrsDBMKNVOZBD1/jO27fPs\naBG+DoGr8fX9JJktpjftVry9A9unzGo=\n"
114
95
 
115
- assert_equal 0, @profile.poll_count
116
- @profile.traces.each do |key, trace|
117
- assert_equal [], trace, "Trace for :#{key} should have been empty"
118
- end
119
- end
96
+ def test_to_collector_array
97
+ build_well_known_trace('profile_id' => 333)
98
+ @profile.stubs(:created_at).returns(1350403938892.524)
99
+ @profile.finished_at = 1350403939904.375
120
100
 
121
- def test_profiler_tracks_time
122
- @profile.run
101
+ expected = [
102
+ 333,
103
+ 1350403938892.524,
104
+ 1350403939904.375,
105
+ 1,
106
+ WELL_KNOWN_TRACE_ENCODED,
107
+ 2,
108
+ 0
109
+ ]
123
110
 
124
- assert_not_nil @profile.start_time
125
- assert_not_nil @profile.stop_time
111
+ assert_equal expected, @profile.to_collector_array(encoder)
126
112
  end
127
113
 
128
- def test_finished
129
- assert !@profile.finished?
130
-
131
- @profile.run.join
114
+ def test_to_collector_array_with_xray_session_id
115
+ build_well_known_trace('profile_id' => -1, 'x_ray_id' => 4242)
116
+ @profile.stubs(:created_at).returns(1350403938892.524)
117
+ @profile.finished_at = 1350403939904.375
132
118
 
133
- assert @profile.finished?
134
- end
135
-
136
- # Parsing and Aggregation Tests
137
- def test_parse_backtrace
138
- trace = [
139
- "/Users/jclark/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/irb.rb:69:in `catch'",
140
- "/Users/jclark/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/irb.rb:69:in `start'",
141
- "/Users/jclark/.rbenv/versions/1.9.3/bin/irb:12:in `<main>'"
119
+ expected = [
120
+ -1,
121
+ 1350403938892.524,
122
+ 1350403939904.375,
123
+ 20,
124
+ WELL_KNOWN_TRACE_ENCODED,
125
+ 2,
126
+ 0,
127
+ 4242
142
128
  ]
143
129
 
144
- result = ThreadProfile.parse_backtrace(trace)
145
- assert_equal({ :method => 'catch',
146
- :file => '/Users/jclark/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/irb.rb',
147
- :line_no => 69 }, result[0])
148
- assert_equal({ :method => 'start',
149
- :file => '/Users/jclark/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/irb.rb',
150
- :line_no => 69 }, result[1])
151
- assert_equal({ :method => '<main>',
152
- :file => '/Users/jclark/.rbenv/versions/1.9.3/bin/irb',
153
- :line_no => 12 }, result[2])
154
- end
155
-
156
- def test_aggregate_empty_trace
157
- result = @profile.aggregate([])
158
- assert_nil result
159
- end
160
-
161
- def test_aggregate_nil_trace
162
- result = @profile.aggregate(nil)
163
- assert_nil result
130
+ assert_equal expected, @profile.to_collector_array(encoder)
164
131
  end
165
132
 
166
- def test_aggregate_builds_tree_from_first_trace
167
- result = @profile.aggregate(@single_trace)
133
+ def test_to_collector_array_with_bad_values
134
+ build_well_known_trace(:profile_id => -1)
135
+ @profile.stubs(:created_at).returns('')
136
+ @profile.finished_at = nil
137
+ @profile.instance_variable_set(:@poll_count, Rational(10, 1))
138
+ @profile.instance_variable_set(:@backtrace_count, nil)
139
+ @profile.instance_variable_set(:@unique_threads, nil)
168
140
 
169
- tree = BacktraceNode.new(@single_trace[-1])
170
- child = BacktraceNode.new(@single_trace[-2], tree)
171
- BacktraceNode.new(@single_trace[-3], child)
141
+ expected = [
142
+ -1,
143
+ 0.0,
144
+ 0.0,
145
+ 10,
146
+ WELL_KNOWN_TRACE_ENCODED,
147
+ 0,
148
+ 0
149
+ ]
172
150
 
173
- assert_equal tree, result
151
+ assert_equal expected, @profile.to_collector_array(encoder)
174
152
  end
175
153
 
176
- def test_aggregate_builds_tree_from_overlapping_traces
177
- result = @profile.aggregate(@single_trace)
178
- result = @profile.aggregate(@single_trace, [result])
179
-
180
- tree = BacktraceNode.new(@single_trace[-1])
181
- tree.runnable_count += 1
182
- child = BacktraceNode.new(@single_trace[-2], tree)
183
- child.runnable_count += 1
184
- grand = BacktraceNode.new(@single_trace[-3], child)
185
- grand.runnable_count += 1
154
+ def test_aggregate_should_increment_only_backtrace_count
155
+ backtrace_count = @profile.backtrace_count
156
+ failure_count = @profile.failure_count
157
+ @profile.aggregate(@single_trace, :request, Thread.current)
186
158
 
187
- assert_equal tree, result
159
+ assert_equal backtrace_count + 1, @profile.backtrace_count
160
+ assert_equal failure_count, @profile.failure_count
188
161
  end
189
162
 
190
- def test_aggregate_builds_tree_from_diverging_traces
191
- other_trace = [
192
- "irb.rb:69:in `catch'",
193
- "chunky_bacon.rb:42:in `start'",
194
- "irb:12:in `<main>'"
195
- ]
163
+ def test_aggregate_increments_only_the_failure_count_with_nil_backtrace
164
+ backtrace_count = @profile.backtrace_count
165
+ failure_count = @profile.failure_count
166
+ @profile.aggregate(nil, :request, Thread.current)
196
167
 
197
- result = @profile.aggregate(@single_trace)
198
- result = @profile.aggregate(@single_trace, [result])
168
+ assert_equal backtrace_count, @profile.backtrace_count
169
+ assert_equal failure_count + 1, @profile.failure_count
170
+ end
199
171
 
200
- tree = BacktraceNode.new(@single_trace[-1])
201
- tree.runnable_count += 1
172
+ def test_aggregate_updates_created_at_timestamp
173
+ expected = freeze_time
174
+ @profile = ThreadProfile.new
202
175
 
203
- child = BacktraceNode.new(@single_trace[-2], tree)
204
- grand = BacktraceNode.new(@single_trace[-3], child)
176
+ @profile.aggregate(@single_trace, :request, Thread.current)
177
+ t0 = @profile.created_at
205
178
 
206
- other_child = BacktraceNode.new(other_trace[-2], tree)
207
- other_grand = BacktraceNode.new(other_trace[-3], other_child)
179
+ advance_time(5.0)
180
+ @profile.aggregate(@single_trace, :request, Thread.current)
208
181
 
209
- assert_equal tree, result
182
+ assert_equal expected, t0
183
+ assert_equal expected, @profile.created_at
210
184
  end
211
185
 
212
- def test_prune_tree
213
- @profile.aggregate(@single_trace)
186
+ def test_aggregate_keeps_unique_thread_count
187
+ thread0 = stub
188
+ thread1 = stub
214
189
 
215
- t = @profile.prune!(1)
190
+ @profile.aggregate(@single_trace, :request, thread0)
191
+ @profile.aggregate(@single_trace, :request, thread0)
192
+ @profile.aggregate(@single_trace, :request, thread1)
216
193
 
217
- assert_equal 0, @profile.traces[:request].first.children.size
194
+ assert_equal 2, @profile.unique_thread_count
218
195
  end
219
196
 
220
- def test_prune_keeps_highest_counts
221
- @profile.aggregate(@single_trace, @profile.traces[:request])
222
- @profile.aggregate(@single_trace, @profile.traces[:other])
223
- @profile.aggregate(@single_trace, @profile.traces[:other])
197
+ SAMPLE_COUNT_POSITION = 3
224
198
 
225
- @profile.prune!(1)
199
+ def test_sample_count_for_thread_profiling
200
+ profile = ThreadProfile.new('x_ray_id' => nil)
201
+ profile.increment_poll_count
226
202
 
227
- assert_equal [], @profile.traces[:request]
228
- assert_equal 1, @profile.traces[:other].size
229
- assert_equal [], @profile.traces[:other][0].children
203
+ result = profile.to_collector_array(encoder)
204
+ assert_equal 1, result[SAMPLE_COUNT_POSITION]
230
205
  end
231
206
 
232
- def test_prune_keeps_highest_count_then_depths
233
- @profile.aggregate(@single_trace, @profile.traces[:request])
234
- @profile.aggregate(@single_trace, @profile.traces[:other])
235
-
236
- @profile.prune!(2)
207
+ def test_sample_count_for_xrays
208
+ profile = ThreadProfile.new('x_ray_id' => 123)
209
+ profile.aggregate(@single_trace, :request, Thread.current)
237
210
 
238
- assert_equal 1, @profile.traces[:request].size
239
- assert_equal 1, @profile.traces[:other].size
240
- assert_equal [], @profile.traces[:request][0].children
241
- assert_equal [], @profile.traces[:other][0].children
211
+ result = profile.to_collector_array(encoder)
212
+ assert_equal 1, result[SAMPLE_COUNT_POSITION]
242
213
  end
243
214
 
244
- def build_well_known_trace
245
- trace = ["thread_profiler.py:1:in `<module>'"]
246
- 10.times { @profile.aggregate(trace, @profile.traces[:other]) }
247
-
248
- trace = [
249
- "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py:489:in `__bootstrap'",
250
- "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py:512:in `__bootstrap_inner'",
251
- "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py:480:in `run'",
252
- "thread_profiler.py:76:in `_profiler_loop'",
253
- "thread_profiler.py:103:in `_run_profiler'",
254
- "thread_profiler.py:165:in `collect_thread_stacks'"]
255
- 10.times { @profile.aggregate(trace, @profile.traces[:agent]) }
215
+ def test_empty
216
+ profile = ThreadProfile.new
217
+ assert profile.empty?
256
218
  end
257
219
 
258
- WELL_KNOWN_TRACE_ENCODED = "eJy9klFPwjAUhf/LfW7WDQTUGBPUiYkGdAxelqXZRpGGrm1uS8xi/O924JQX\n9Un7dm77ndN7c19hlt7FCZxnWQZug7xYMYN6LSTHwDRA4KLWq53kl0CinEQh\nCUmW5zmBJH5axPPUk16MJ/E0/cGk0lLyyrGPS+uKamu943DQeX5HMtypz5In\nwv6vRCeZ1NoAGQ2PCDpvrOM1fRAlFtjQWyxq/qJxa+lj4zZaBeuuQpccrdDK\n0l4wolKU1OxftOoQLNTzIdL/EcjJafjnQYyVWjvrsDBMKNVOZBD1/jO27fPs\naBG+DoGr8fX9JJktpjftVry9A9unzGo=\n"
259
-
260
- def test_to_collector_array
261
- @profile.instance_variable_set(:@profile_id, "-1")
262
- @profile.instance_variable_set(:@start_time, 1350403938892.524)
263
- @profile.instance_variable_set(:@stop_time, 1350403939904.375)
264
- @profile.instance_variable_set(:@poll_count, 10)
265
- @profile.instance_variable_set(:@sample_count, 2)
266
-
267
- build_well_known_trace
268
-
269
- expected = [[
270
- -1,
271
- 1350403938892.524,
272
- 1350403939904.375,
273
- 10,
274
- WELL_KNOWN_TRACE_ENCODED,
275
- 2,
276
- 0
277
- ]]
278
-
279
- marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
280
- assert_equal expected, @profile.to_collector_array(marshaller.default_encoder)
220
+ def test_not_empty
221
+ profile = ThreadProfile.new
222
+ profile.aggregate([], :request, Thread.current)
223
+ assert_false profile.empty?
281
224
  end
282
225
 
283
- def test_to_collector_array_with_bad_values
284
- @profile.instance_variable_set(:@profile_id, "-1")
285
- @profile.instance_variable_set(:@start_time, "")
286
- @profile.instance_variable_set(:@stop_time, nil)
287
- @profile.instance_variable_set(:@poll_count, Rational(10, 1))
288
- @profile.instance_variable_set(:@sample_count, nil)
289
-
290
- build_well_known_trace
291
-
292
- expected = [[
293
- -1,
294
- 0.0,
295
- 0.0,
296
- 10,
297
- WELL_KNOWN_TRACE_ENCODED,
298
- 0,
299
- 0
300
- ]]
301
-
302
- marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
303
- assert_equal expected, @profile.to_collector_array(marshaller.default_encoder)
226
+ def encoder
227
+ NewRelic::Agent::NewRelicService::JsonMarshaller.new.default_encoder
304
228
  end
305
229
  end
306
230