wd_newrelic_rpm 3.3.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +591 -0
- data/LICENSE +64 -0
- data/README.rdoc +179 -0
- data/bin/mongrel_rpm +33 -0
- data/bin/newrelic +13 -0
- data/bin/newrelic_cmd +5 -0
- data/cert/cacert.pem +118 -0
- data/cert/oldsite.pem +28 -0
- data/cert/site.pem +27 -0
- data/install.rb +9 -0
- data/lib/conditional_vendored_dependency_detection.rb +3 -0
- data/lib/conditional_vendored_metric_parser.rb +5 -0
- data/lib/new_relic/agent.rb +467 -0
- data/lib/new_relic/agent/agent.rb +1325 -0
- data/lib/new_relic/agent/beacon_configuration.rb +121 -0
- data/lib/new_relic/agent/browser_monitoring.rb +142 -0
- data/lib/new_relic/agent/busy_calculator.rb +99 -0
- data/lib/new_relic/agent/chained_call.rb +13 -0
- data/lib/new_relic/agent/database.rb +223 -0
- data/lib/new_relic/agent/error_collector.rb +251 -0
- data/lib/new_relic/agent/instrumentation.rb +9 -0
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +29 -0
- data/lib/new_relic/agent/instrumentation/active_record.rb +137 -0
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +68 -0
- data/lib/new_relic/agent/instrumentation/authlogic.rb +19 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +443 -0
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +238 -0
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +52 -0
- data/lib/new_relic/agent/instrumentation/memcache.rb +80 -0
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +41 -0
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +29 -0
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +353 -0
- data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +80 -0
- data/lib/new_relic/agent/instrumentation/net.rb +29 -0
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +37 -0
- data/lib/new_relic/agent/instrumentation/queue_time.rb +210 -0
- data/lib/new_relic/agent/instrumentation/rack.rb +98 -0
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +114 -0
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +42 -0
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +42 -0
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +180 -0
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +37 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +78 -0
- data/lib/new_relic/agent/instrumentation/sunspot.rb +29 -0
- data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +21 -0
- data/lib/new_relic/agent/method_tracer.rb +528 -0
- data/lib/new_relic/agent/sampler.rb +50 -0
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +58 -0
- data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +40 -0
- data/lib/new_relic/agent/samplers/memory_sampler.rb +143 -0
- data/lib/new_relic/agent/samplers/object_sampler.rb +26 -0
- data/lib/new_relic/agent/shim_agent.rb +29 -0
- data/lib/new_relic/agent/sql_sampler.rb +286 -0
- data/lib/new_relic/agent/stats_engine.rb +26 -0
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +123 -0
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +187 -0
- data/lib/new_relic/agent/stats_engine/samplers.rb +95 -0
- data/lib/new_relic/agent/stats_engine/transactions.rb +125 -0
- data/lib/new_relic/agent/transaction_info.rb +74 -0
- data/lib/new_relic/agent/transaction_sample_builder.rb +116 -0
- data/lib/new_relic/agent/transaction_sampler.rb +468 -0
- data/lib/new_relic/agent/worker_loop.rb +89 -0
- data/lib/new_relic/collection_helper.rb +77 -0
- data/lib/new_relic/command.rb +85 -0
- data/lib/new_relic/commands/deployments.rb +105 -0
- data/lib/new_relic/commands/install.rb +80 -0
- data/lib/new_relic/control.rb +46 -0
- data/lib/new_relic/control/class_methods.rb +53 -0
- data/lib/new_relic/control/configuration.rb +206 -0
- data/lib/new_relic/control/frameworks.rb +10 -0
- data/lib/new_relic/control/frameworks/external.rb +16 -0
- data/lib/new_relic/control/frameworks/merb.rb +31 -0
- data/lib/new_relic/control/frameworks/rails.rb +164 -0
- data/lib/new_relic/control/frameworks/rails3.rb +75 -0
- data/lib/new_relic/control/frameworks/ruby.rb +42 -0
- data/lib/new_relic/control/frameworks/sinatra.rb +20 -0
- data/lib/new_relic/control/instance_methods.rb +179 -0
- data/lib/new_relic/control/instrumentation.rb +100 -0
- data/lib/new_relic/control/logging_methods.rb +143 -0
- data/lib/new_relic/control/profiling.rb +25 -0
- data/lib/new_relic/control/server_methods.rb +114 -0
- data/lib/new_relic/data_serialization.rb +151 -0
- data/lib/new_relic/delayed_job_injection.rb +51 -0
- data/lib/new_relic/language_support.rb +73 -0
- data/lib/new_relic/local_environment.rb +428 -0
- data/lib/new_relic/merbtasks.rb +6 -0
- data/lib/new_relic/metric_data.rb +51 -0
- data/lib/new_relic/metric_spec.rb +76 -0
- data/lib/new_relic/metrics.rb +9 -0
- data/lib/new_relic/noticed_error.rb +29 -0
- data/lib/new_relic/rack/browser_monitoring.rb +76 -0
- data/lib/new_relic/rack/developer_mode.rb +268 -0
- data/lib/new_relic/recipes.rb +77 -0
- data/lib/new_relic/stats.rb +335 -0
- data/lib/new_relic/timer_lib.rb +27 -0
- data/lib/new_relic/transaction_analysis.rb +77 -0
- data/lib/new_relic/transaction_analysis/segment_summary.rb +49 -0
- data/lib/new_relic/transaction_sample.rb +261 -0
- data/lib/new_relic/transaction_sample/composite_segment.rb +27 -0
- data/lib/new_relic/transaction_sample/fake_segment.rb +9 -0
- data/lib/new_relic/transaction_sample/segment.rb +203 -0
- data/lib/new_relic/transaction_sample/summary_segment.rb +21 -0
- data/lib/new_relic/url_rule.rb +14 -0
- data/lib/new_relic/version.rb +55 -0
- data/lib/newrelic_rpm.rb +49 -0
- data/lib/tasks/all.rb +4 -0
- data/lib/tasks/install.rake +7 -0
- data/lib/tasks/tests.rake +19 -0
- data/newrelic.yml +265 -0
- data/newrelic_rpm.gemspec +312 -0
- data/recipes/newrelic.rb +6 -0
- data/test/active_record_fixtures.rb +77 -0
- data/test/config/newrelic.yml +48 -0
- data/test/config/test_control.rb +48 -0
- data/test/fixtures/proc_cpuinfo.txt +575 -0
- data/test/new_relic/agent/agent/connect_test.rb +403 -0
- data/test/new_relic/agent/agent/start_test.rb +255 -0
- data/test/new_relic/agent/agent/start_worker_thread_test.rb +153 -0
- data/test/new_relic/agent/agent_test.rb +140 -0
- data/test/new_relic/agent/agent_test_controller.rb +77 -0
- data/test/new_relic/agent/agent_test_controller_test.rb +382 -0
- data/test/new_relic/agent/apdex_from_server_test.rb +9 -0
- data/test/new_relic/agent/beacon_configuration_test.rb +111 -0
- data/test/new_relic/agent/browser_monitoring_test.rb +323 -0
- data/test/new_relic/agent/busy_calculator_test.rb +81 -0
- data/test/new_relic/agent/database_test.rb +149 -0
- data/test/new_relic/agent/error_collector/notice_error_test.rb +257 -0
- data/test/new_relic/agent/error_collector_test.rb +192 -0
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +576 -0
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +34 -0
- data/test/new_relic/agent/instrumentation/instrumentation_test.rb +11 -0
- data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +171 -0
- data/test/new_relic/agent/instrumentation/metric_frame_test.rb +50 -0
- data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +84 -0
- data/test/new_relic/agent/instrumentation/queue_time_test.rb +382 -0
- data/test/new_relic/agent/instrumentation/rack_test.rb +35 -0
- data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +184 -0
- data/test/new_relic/agent/memcache_instrumentation_test.rb +143 -0
- data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +164 -0
- data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +234 -0
- data/test/new_relic/agent/method_tracer_test.rb +386 -0
- data/test/new_relic/agent/mock_scope_listener.rb +23 -0
- data/test/new_relic/agent/rpm_agent_test.rb +149 -0
- data/test/new_relic/agent/sampler_test.rb +19 -0
- data/test/new_relic/agent/shim_agent_test.rb +20 -0
- data/test/new_relic/agent/sql_sampler_test.rb +192 -0
- data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +150 -0
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +82 -0
- data/test/new_relic/agent/stats_engine/samplers_test.rb +99 -0
- data/test/new_relic/agent/stats_engine_test.rb +220 -0
- data/test/new_relic/agent/transaction_info_test.rb +13 -0
- data/test/new_relic/agent/transaction_sample_builder_test.rb +219 -0
- data/test/new_relic/agent/transaction_sampler_test.rb +967 -0
- data/test/new_relic/agent/worker_loop_test.rb +66 -0
- data/test/new_relic/agent_test.rb +187 -0
- data/test/new_relic/collection_helper_test.rb +149 -0
- data/test/new_relic/command/deployments_test.rb +68 -0
- data/test/new_relic/control/class_methods_test.rb +62 -0
- data/test/new_relic/control/configuration_test.rb +84 -0
- data/test/new_relic/control/logging_methods_test.rb +185 -0
- data/test/new_relic/control_test.rb +256 -0
- data/test/new_relic/data_serialization_test.rb +208 -0
- data/test/new_relic/delayed_job_injection_test.rb +16 -0
- data/test/new_relic/local_environment_test.rb +85 -0
- data/test/new_relic/metric_data_test.rb +125 -0
- data/test/new_relic/metric_parser/metric_parser_test.rb +11 -0
- data/test/new_relic/metric_spec_test.rb +95 -0
- data/test/new_relic/rack/all_test.rb +11 -0
- data/test/new_relic/rack/browser_monitoring_test.rb +142 -0
- data/test/new_relic/rack/developer_mode_helper_test.rb +141 -0
- data/test/new_relic/rack/developer_mode_test.rb +74 -0
- data/test/new_relic/stats_test.rb +411 -0
- data/test/new_relic/transaction_analysis/segment_summary_test.rb +91 -0
- data/test/new_relic/transaction_analysis_test.rb +121 -0
- data/test/new_relic/transaction_sample/composite_segment_test.rb +35 -0
- data/test/new_relic/transaction_sample/fake_segment_test.rb +17 -0
- data/test/new_relic/transaction_sample/segment_test.rb +389 -0
- data/test/new_relic/transaction_sample/summary_segment_test.rb +31 -0
- data/test/new_relic/transaction_sample_subtest_test.rb +56 -0
- data/test/new_relic/transaction_sample_test.rb +177 -0
- data/test/new_relic/version_number_test.rb +89 -0
- data/test/script/build_test_gem.sh +51 -0
- data/test/script/ci.sh +94 -0
- data/test/script/ci_bench.sh +52 -0
- data/test/test_contexts.rb +29 -0
- data/test/test_helper.rb +155 -0
- data/ui/helpers/developer_mode_helper.rb +357 -0
- data/ui/helpers/google_pie_chart.rb +48 -0
- data/ui/views/layouts/newrelic_default.rhtml +47 -0
- data/ui/views/newrelic/_explain_plans.rhtml +27 -0
- data/ui/views/newrelic/_sample.rhtml +20 -0
- data/ui/views/newrelic/_segment.rhtml +28 -0
- data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
- data/ui/views/newrelic/_segment_row.rhtml +12 -0
- data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
- data/ui/views/newrelic/_show_sample_sql.rhtml +24 -0
- data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
- data/ui/views/newrelic/_sql_row.rhtml +16 -0
- data/ui/views/newrelic/_stack_trace.rhtml +15 -0
- data/ui/views/newrelic/_table.rhtml +12 -0
- data/ui/views/newrelic/explain_sql.rhtml +43 -0
- data/ui/views/newrelic/file/images/arrow-close.png +0 -0
- data/ui/views/newrelic/file/images/arrow-open.png +0 -0
- data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
- data/ui/views/newrelic/file/images/file_icon.png +0 -0
- data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
- data/ui/views/newrelic/file/images/new-relic-rpm-desktop.gif +0 -0
- data/ui/views/newrelic/file/images/new_relic_rpm_desktop.gif +0 -0
- data/ui/views/newrelic/file/images/textmate.png +0 -0
- data/ui/views/newrelic/file/javascript/jquery-1.4.2.js +6240 -0
- data/ui/views/newrelic/file/javascript/transaction_sample.js +120 -0
- data/ui/views/newrelic/file/stylesheets/style.css +490 -0
- data/ui/views/newrelic/index.rhtml +71 -0
- data/ui/views/newrelic/sample_not_found.rhtml +2 -0
- data/ui/views/newrelic/show_sample.rhtml +80 -0
- data/ui/views/newrelic/show_source.rhtml +3 -0
- data/ui/views/newrelic/threads.rhtml +53 -0
- data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +5 -0
- data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +67 -0
- data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection/version.rb +3 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/metric_parser.rb +1 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser.rb +64 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/action_mailer.rb +14 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_merchant.rb +31 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_record.rb +33 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/apdex.rb +89 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/background_transaction.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/client.rb +46 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller.rb +67 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_cpu.rb +43 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_ext.rb +17 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database.rb +48 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database_pool.rb +24 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net.rb +28 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net_parser.rb +17 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/errors.rb +11 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/external.rb +55 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/frontend.rb +40 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/gc.rb +20 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/hibernate_session.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java.rb +31 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java_parser.rb +17 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp.rb +34 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp_tag.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +55 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +135 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/orm.rb +27 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/other_transaction.rb +40 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_context_listener.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_filter.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr.rb +27 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr_request_handler.rb +15 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring.rb +54 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_controller.rb +6 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_view.rb +6 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_action.rb +20 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_result.rb +20 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/version.rb +5 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +70 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_frontend.rb +18 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_service.rb +14 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_transaction.rb +133 -0
- metadata +376 -0
@@ -0,0 +1,49 @@
|
|
1
|
+
module NewRelic
|
2
|
+
module TransactionAnalysis
|
3
|
+
# summarizes performance data for all calls to segments
|
4
|
+
# with the same metric_name
|
5
|
+
class SegmentSummary
|
6
|
+
attr_accessor :metric_name, :total_time, :exclusive_time, :call_count, :current_nest_count
|
7
|
+
def initialize(metric_name, sample)
|
8
|
+
@metric_name = metric_name
|
9
|
+
@total_time, @exclusive_time, @call_count = 0,0,0
|
10
|
+
@sample = sample
|
11
|
+
@current_nest_count = 0
|
12
|
+
end
|
13
|
+
|
14
|
+
def <<(segment)
|
15
|
+
if metric_name != segment.metric_name
|
16
|
+
raise ArgumentError, "Metric Name Mismatch: #{segment.metric_name} != #{metric_name}"
|
17
|
+
end
|
18
|
+
|
19
|
+
# a nested segment should use the sum of the top level totals
|
20
|
+
@total_time += segment.duration if current_nest_count == 0
|
21
|
+
@exclusive_time += segment.exclusive_duration
|
22
|
+
@call_count += 1
|
23
|
+
end
|
24
|
+
|
25
|
+
def average_time
|
26
|
+
@total_time / @call_count
|
27
|
+
end
|
28
|
+
|
29
|
+
def average_exclusive_time
|
30
|
+
@exclusive_time / @call_count
|
31
|
+
end
|
32
|
+
|
33
|
+
def exclusive_time_percentage
|
34
|
+
return 0 unless @exclusive_time && @sample.duration && @sample.duration > 0
|
35
|
+
@exclusive_time / @sample.duration
|
36
|
+
end
|
37
|
+
|
38
|
+
def total_time_percentage
|
39
|
+
return 0 unless @total_time && @sample.duration && @sample.duration > 0
|
40
|
+
@total_time / @sample.duration
|
41
|
+
end
|
42
|
+
|
43
|
+
def ui_name
|
44
|
+
return @metric_name if @metric_name == 'Remainder'
|
45
|
+
NewRelic::MetricParser::MetricParser.parse(@metric_name).developer_name
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,261 @@
|
|
1
|
+
require 'new_relic/transaction_sample/segment'
|
2
|
+
require 'new_relic/transaction_sample/summary_segment'
|
3
|
+
require 'new_relic/transaction_sample/fake_segment'
|
4
|
+
require 'new_relic/transaction_sample/composite_segment'
|
5
|
+
module NewRelic
|
6
|
+
# the number of segments that need to exist before we roll them up
|
7
|
+
# into one segment with multiple executions
|
8
|
+
COLLAPSE_SEGMENTS_THRESHOLD = 2
|
9
|
+
|
10
|
+
class TransactionSample
|
11
|
+
|
12
|
+
attr_accessor :params, :root_segment, :profile, :force_persist, :guid
|
13
|
+
attr_reader :root_segment, :params, :sample_id
|
14
|
+
|
15
|
+
@@start_time = Time.now
|
16
|
+
|
17
|
+
include TransactionAnalysis
|
18
|
+
|
19
|
+
def initialize(time = Time.now.to_f, sample_id = nil)
|
20
|
+
@sample_id = sample_id || object_id
|
21
|
+
@start_time = time
|
22
|
+
@params = { :segment_count => -1, :request_params => {} }
|
23
|
+
@segment_count = -1
|
24
|
+
@root_segment = create_segment 0.0, "ROOT"
|
25
|
+
|
26
|
+
@guid = generate_guid
|
27
|
+
NewRelic::Agent::TransactionInfo.get.guid = @guid
|
28
|
+
end
|
29
|
+
|
30
|
+
def count_segments
|
31
|
+
@segment_count
|
32
|
+
end
|
33
|
+
|
34
|
+
# Truncates the transaction sample to a maximum length determined
|
35
|
+
# by the passed-in parameter. Operates recursively on the entire
|
36
|
+
# tree of transaction segments in a depth-first manner
|
37
|
+
def truncate(max)
|
38
|
+
return if @segment_count < max
|
39
|
+
@root_segment.truncate(max + 1)
|
40
|
+
@segment_count = max
|
41
|
+
end
|
42
|
+
|
43
|
+
# makes sure that the parameter cache for segment count is set to
|
44
|
+
# the correct value
|
45
|
+
def ensure_segment_count_set(count)
|
46
|
+
params[:segment_count] ||= count
|
47
|
+
end
|
48
|
+
|
49
|
+
# offset from start of app
|
50
|
+
def timestamp
|
51
|
+
@start_time - @@start_time.to_f
|
52
|
+
end
|
53
|
+
|
54
|
+
# Used in the server only
|
55
|
+
def to_json(options = {}) #:nodoc:
|
56
|
+
map = {:sample_id => @sample_id,
|
57
|
+
:start_time => @start_time,
|
58
|
+
:root_segment => @root_segment}
|
59
|
+
if @params && !@params.empty?
|
60
|
+
map[:params] = @params
|
61
|
+
end
|
62
|
+
map.to_json
|
63
|
+
end
|
64
|
+
|
65
|
+
def start_time
|
66
|
+
Time.at(@start_time)
|
67
|
+
end
|
68
|
+
|
69
|
+
def path_string
|
70
|
+
@root_segment.path_string
|
71
|
+
end
|
72
|
+
|
73
|
+
def create_segment(relative_timestamp, metric_name, segment_id = nil)
|
74
|
+
raise TypeError.new("Frozen Transaction Sample") if frozen?
|
75
|
+
@params[:segment_count] += 1
|
76
|
+
@segment_count += 1
|
77
|
+
NewRelic::TransactionSample::Segment.new(relative_timestamp, metric_name, segment_id)
|
78
|
+
end
|
79
|
+
|
80
|
+
def duration
|
81
|
+
root_segment.duration
|
82
|
+
end
|
83
|
+
|
84
|
+
# Iterates recursively over each segment in the entire transaction
|
85
|
+
# sample tree
|
86
|
+
def each_segment(&block)
|
87
|
+
@root_segment.each_segment(&block)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Iterates recursively over each segment in the entire transaction
|
91
|
+
# sample tree while keeping track of nested segments
|
92
|
+
def each_segment_with_nest_tracking(&block)
|
93
|
+
@root_segment.each_segment_with_nest_tracking(&block)
|
94
|
+
end
|
95
|
+
|
96
|
+
def to_s_compact
|
97
|
+
@root_segment.to_s_compact
|
98
|
+
end
|
99
|
+
|
100
|
+
# Searches the tree recursively for the segment with the given
|
101
|
+
# id. note that this is an internal id, not an ActiveRecord id
|
102
|
+
def find_segment(id)
|
103
|
+
@root_segment.find_segment(id)
|
104
|
+
end
|
105
|
+
|
106
|
+
def to_s
|
107
|
+
s = "Transaction Sample collected at #{start_time}\n"
|
108
|
+
s << " {\n"
|
109
|
+
s << " Path: #{params[:path]} \n"
|
110
|
+
|
111
|
+
params.each do |k,v|
|
112
|
+
next if k == :path
|
113
|
+
s << " #{k}: " <<
|
114
|
+
case v
|
115
|
+
when Enumerable then v.map(&:to_s).sort.join("; ")
|
116
|
+
when String then v
|
117
|
+
when Float then '%6.3s' % v
|
118
|
+
when Fixnum then v.to_s
|
119
|
+
when nil then ''
|
120
|
+
else
|
121
|
+
raise "unexpected value type for #{k}: '#{v}' (#{v.class})"
|
122
|
+
end << "\n"
|
123
|
+
end
|
124
|
+
s << " }\n\n"
|
125
|
+
s << @root_segment.to_debug_str(0)
|
126
|
+
end
|
127
|
+
|
128
|
+
# return a new transaction sample that treats segments
|
129
|
+
# with the given regular expression in their name as if they
|
130
|
+
# were never called at all. This allows us to strip out segments
|
131
|
+
# from traces captured in development environment that would not
|
132
|
+
# normally show up in production (like Rails/Application Code Loading)
|
133
|
+
def omit_segments_with(regex)
|
134
|
+
regex = Regexp.new(regex)
|
135
|
+
|
136
|
+
sample = TransactionSample.new(@start_time, sample_id)
|
137
|
+
|
138
|
+
sample.params = params.dup
|
139
|
+
sample.params[:segment_count] = 0
|
140
|
+
|
141
|
+
delta = build_segment_with_omissions(sample, 0.0, @root_segment, sample.root_segment, regex)
|
142
|
+
sample.root_segment.end_trace(@root_segment.exit_timestamp - delta)
|
143
|
+
sample.profile = self.profile
|
144
|
+
sample
|
145
|
+
end
|
146
|
+
|
147
|
+
# Return a new transaction sample that can be sent to the New
|
148
|
+
# Relic service. This involves potentially one or more of the
|
149
|
+
# following options
|
150
|
+
#
|
151
|
+
# :explain_sql : run EXPLAIN on all queries whose response times equal the value for this key
|
152
|
+
# (for example :explain_sql => 2.0 would explain everything over 2 seconds. 0.0 would explain everything.)
|
153
|
+
# :keep_backtraces : keep backtraces, significantly increasing size of trace (off by default)
|
154
|
+
# :record_sql => [ :raw | :obfuscated] : copy over the sql, obfuscating if necessary
|
155
|
+
def prepare_to_send(options={})
|
156
|
+
sample = TransactionSample.new(@start_time, sample_id)
|
157
|
+
|
158
|
+
sample.params.merge! self.params
|
159
|
+
sample.guid = self.guid
|
160
|
+
sample.force_persist = self.force_persist if self.force_persist
|
161
|
+
|
162
|
+
begin
|
163
|
+
build_segment_for_transfer(sample, @root_segment, sample.root_segment, options)
|
164
|
+
ensure
|
165
|
+
NewRelic::Agent::Database.close_connections
|
166
|
+
end
|
167
|
+
|
168
|
+
sample.root_segment.end_trace(@root_segment.exit_timestamp)
|
169
|
+
sample
|
170
|
+
end
|
171
|
+
|
172
|
+
def params=(params)
|
173
|
+
@params = params
|
174
|
+
end
|
175
|
+
|
176
|
+
private
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
HEX_DIGITS = (0..15).map{|i| i.to_s(16)}
|
181
|
+
# generate a random 64 bit uuid
|
182
|
+
def generate_guid
|
183
|
+
guid = ''
|
184
|
+
HEX_DIGITS.each do |a|
|
185
|
+
guid << HEX_DIGITS[rand(16)]
|
186
|
+
end
|
187
|
+
guid
|
188
|
+
end
|
189
|
+
|
190
|
+
# This is badly in need of refactoring
|
191
|
+
def build_segment_with_omissions(new_sample, time_delta, source_segment, target_segment, regex)
|
192
|
+
source_segment.called_segments.each do |source_called_segment|
|
193
|
+
# if this segment's metric name matches the given regular expression, bail
|
194
|
+
# here and increase the amount of time that we reduce the target sample with
|
195
|
+
# by this omitted segment's duration.
|
196
|
+
do_omit = regex =~ source_called_segment.metric_name
|
197
|
+
|
198
|
+
if do_omit
|
199
|
+
time_delta += source_called_segment.duration
|
200
|
+
else
|
201
|
+
target_called_segment = new_sample.create_segment(
|
202
|
+
source_called_segment.entry_timestamp - time_delta,
|
203
|
+
source_called_segment.metric_name,
|
204
|
+
source_called_segment.segment_id)
|
205
|
+
|
206
|
+
target_segment.add_called_segment target_called_segment
|
207
|
+
source_called_segment.params.each do |k,v|
|
208
|
+
target_called_segment[k]=v
|
209
|
+
end
|
210
|
+
|
211
|
+
time_delta = build_segment_with_omissions(
|
212
|
+
new_sample, time_delta, source_called_segment, target_called_segment, regex)
|
213
|
+
target_called_segment.end_trace(source_called_segment.exit_timestamp - time_delta)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
return time_delta
|
218
|
+
end
|
219
|
+
|
220
|
+
# see prepare_to_send for what we do with options
|
221
|
+
#
|
222
|
+
# This is badly in need of refactoring
|
223
|
+
def build_segment_for_transfer(new_sample, source_segment, target_segment, options)
|
224
|
+
source_segment.called_segments.each do |source_called_segment|
|
225
|
+
target_called_segment = new_sample.create_segment(
|
226
|
+
source_called_segment.entry_timestamp,
|
227
|
+
source_called_segment.metric_name,
|
228
|
+
source_called_segment.segment_id)
|
229
|
+
|
230
|
+
target_segment.add_called_segment target_called_segment
|
231
|
+
source_called_segment.params.each do |k,v|
|
232
|
+
case k
|
233
|
+
when :backtrace
|
234
|
+
target_called_segment[k]=v if options[:keep_backtraces]
|
235
|
+
when :sql
|
236
|
+
# run an EXPLAIN on this sql if specified.
|
237
|
+
if options[:record_sql] && options[:record_sql] &&
|
238
|
+
options[:explain_sql] &&
|
239
|
+
source_called_segment.duration > options[:explain_sql].to_f
|
240
|
+
target_called_segment[:explain_plan] = source_called_segment.explain_sql
|
241
|
+
end
|
242
|
+
|
243
|
+
target_called_segment[:sql] = case options[:record_sql]
|
244
|
+
when :raw then v
|
245
|
+
when :obfuscated then NewRelic::Agent::Database.obfuscate_sql(v)
|
246
|
+
else raise "Invalid value for record_sql: #{options[:record_sql]}"
|
247
|
+
end.to_s if options[:record_sql]
|
248
|
+
when :connection_config
|
249
|
+
# don't copy it
|
250
|
+
else
|
251
|
+
target_called_segment[k]=v
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
build_segment_for_transfer(new_sample, source_called_segment, target_called_segment, options)
|
256
|
+
target_called_segment.end_trace(source_called_segment.exit_timestamp)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
end
|
261
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'new_relic/transaction_sample'
|
2
|
+
require 'new_relic/transaction_sample/segment'
|
3
|
+
require 'new_relic/transaction_sample/summary_segment'
|
4
|
+
module NewRelic
|
5
|
+
class TransactionSample
|
6
|
+
class CompositeSegment < Segment
|
7
|
+
attr_reader :detail_segments
|
8
|
+
|
9
|
+
def initialize(segments)
|
10
|
+
summary = SummarySegment.new(segments.first)
|
11
|
+
super summary.entry_timestamp, "Repeating pattern (#{segments.length} repeats)", nil
|
12
|
+
|
13
|
+
summary.end_trace(segments.last.exit_timestamp)
|
14
|
+
|
15
|
+
@detail_segments = segments.clone
|
16
|
+
|
17
|
+
add_called_segment(summary)
|
18
|
+
end_trace summary.exit_timestamp
|
19
|
+
end
|
20
|
+
|
21
|
+
def detail_segments=(segments)
|
22
|
+
@detail_segments = segments
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,203 @@
|
|
1
|
+
require 'new_relic/transaction_sample'
|
2
|
+
module NewRelic
|
3
|
+
class TransactionSample
|
4
|
+
class Segment
|
5
|
+
attr_reader :entry_timestamp
|
6
|
+
# The exit timestamp will be relative except for the outermost sample which will
|
7
|
+
# have a timestamp.
|
8
|
+
attr_reader :exit_timestamp
|
9
|
+
attr_reader :parent_segment
|
10
|
+
attr_reader :metric_name
|
11
|
+
attr_reader :segment_id
|
12
|
+
|
13
|
+
def initialize(timestamp, metric_name, segment_id)
|
14
|
+
@entry_timestamp = timestamp
|
15
|
+
@metric_name = metric_name || '<unknown>'
|
16
|
+
@segment_id = segment_id || object_id
|
17
|
+
end
|
18
|
+
|
19
|
+
# sets the final timestamp on a segment to indicate the exit
|
20
|
+
# point of the segment
|
21
|
+
def end_trace(timestamp)
|
22
|
+
@exit_timestamp = timestamp
|
23
|
+
end
|
24
|
+
|
25
|
+
def add_called_segment(s)
|
26
|
+
@called_segments ||= []
|
27
|
+
@called_segments << s
|
28
|
+
s.parent_segment = self
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_s
|
32
|
+
to_debug_str(0)
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_json(options={})
|
36
|
+
hash = {
|
37
|
+
:entry_timestamp => @entry_timestamp,
|
38
|
+
:exit_timestamp => @exit_timestamp,
|
39
|
+
:metric_name => @metric_name,
|
40
|
+
:segment_id => @segment_id,
|
41
|
+
}
|
42
|
+
|
43
|
+
hash[:called_segments] = called_segments if !called_segments.empty?
|
44
|
+
hash[:params] = @params if @params && !@params.empty?
|
45
|
+
|
46
|
+
hash.to_json
|
47
|
+
end
|
48
|
+
|
49
|
+
def path_string
|
50
|
+
"#{metric_name}[#{called_segments.collect {|segment| segment.path_string }.join('')}]"
|
51
|
+
end
|
52
|
+
def to_s_compact
|
53
|
+
str = ""
|
54
|
+
str << metric_name
|
55
|
+
if called_segments.any?
|
56
|
+
str << "{#{called_segments.map { | cs | cs.to_s_compact }.join(",")}}"
|
57
|
+
end
|
58
|
+
str
|
59
|
+
end
|
60
|
+
def to_debug_str(depth)
|
61
|
+
tab = " " * depth
|
62
|
+
s = tab.clone
|
63
|
+
s << ">> #{'%3i ms' % (@entry_timestamp*1000)} [#{self.class.name.split("::").last}] #{metric_name} \n"
|
64
|
+
unless params.empty?
|
65
|
+
params.each do |k,v|
|
66
|
+
s << "#{tab} -#{'%-16s' % k}: #{v.to_s[0..80]}\n"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
called_segments.each do |cs|
|
70
|
+
s << cs.to_debug_str(depth + 1)
|
71
|
+
end
|
72
|
+
s << tab + "<< "
|
73
|
+
s << case @exit_timestamp
|
74
|
+
when nil then ' n/a'
|
75
|
+
when Numeric then '%3i ms' % (@exit_timestamp*1000)
|
76
|
+
else @exit_timestamp.to_s
|
77
|
+
end
|
78
|
+
s << " #{metric_name}\n"
|
79
|
+
end
|
80
|
+
|
81
|
+
def called_segments
|
82
|
+
@called_segments || []
|
83
|
+
end
|
84
|
+
|
85
|
+
# return the total duration of this segment
|
86
|
+
def duration
|
87
|
+
(@exit_timestamp - @entry_timestamp).to_f
|
88
|
+
end
|
89
|
+
|
90
|
+
# return the duration of this segment without
|
91
|
+
# including the time in the called segments
|
92
|
+
def exclusive_duration
|
93
|
+
d = duration
|
94
|
+
|
95
|
+
called_segments.each do |segment|
|
96
|
+
d -= segment.duration
|
97
|
+
end
|
98
|
+
d
|
99
|
+
end
|
100
|
+
|
101
|
+
def count_segments
|
102
|
+
count = 1
|
103
|
+
called_segments.each { | seg | count += seg.count_segments }
|
104
|
+
count
|
105
|
+
end
|
106
|
+
|
107
|
+
# Walk through the tree and truncate the segments in a
|
108
|
+
# depth-first manner
|
109
|
+
def truncate(max)
|
110
|
+
return 1 unless @called_segments
|
111
|
+
total, self.called_segments = truncate_each_child(max - 1)
|
112
|
+
total+1
|
113
|
+
end
|
114
|
+
|
115
|
+
def truncate_each_child(max)
|
116
|
+
total = 0
|
117
|
+
accumulator = []
|
118
|
+
called_segments.each { | s |
|
119
|
+
if total == max
|
120
|
+
true
|
121
|
+
else
|
122
|
+
total += s.truncate(max - total)
|
123
|
+
accumulator << s
|
124
|
+
end
|
125
|
+
}
|
126
|
+
total
|
127
|
+
[total, accumulator]
|
128
|
+
end
|
129
|
+
|
130
|
+
def []=(key, value)
|
131
|
+
# only create a parameters field if a parameter is set; this will save
|
132
|
+
# bandwidth etc as most segments have no parameters
|
133
|
+
params[key] = value
|
134
|
+
end
|
135
|
+
|
136
|
+
def [](key)
|
137
|
+
params[key]
|
138
|
+
end
|
139
|
+
|
140
|
+
def params
|
141
|
+
@params ||= {}
|
142
|
+
end
|
143
|
+
|
144
|
+
# call the provided block for this segment and each
|
145
|
+
# of the called segments
|
146
|
+
def each_segment(&block)
|
147
|
+
block.call self
|
148
|
+
|
149
|
+
if @called_segments
|
150
|
+
@called_segments.each do |segment|
|
151
|
+
segment.each_segment(&block)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
# call the provided block for this segment and each
|
157
|
+
# of the called segments while keeping track of nested segments
|
158
|
+
def each_segment_with_nest_tracking(&block)
|
159
|
+
summary = block.call self
|
160
|
+
summary.current_nest_count += 1 if summary
|
161
|
+
|
162
|
+
if @called_segments
|
163
|
+
@called_segments.each do |segment|
|
164
|
+
segment.each_segment_with_nest_tracking(&block)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
summary.current_nest_count -= 1 if summary
|
169
|
+
end
|
170
|
+
|
171
|
+
def find_segment(id)
|
172
|
+
return self if @segment_id == id
|
173
|
+
called_segments.each do |segment|
|
174
|
+
found = segment.find_segment(id)
|
175
|
+
return found if found
|
176
|
+
end
|
177
|
+
nil
|
178
|
+
end
|
179
|
+
|
180
|
+
def explain_sql
|
181
|
+
NewRelic::Agent::Database.explain_sql(params[:sql],
|
182
|
+
params[:connection_config])
|
183
|
+
end
|
184
|
+
|
185
|
+
def obfuscated_sql
|
186
|
+
NewRelic::Agent::Database.obfuscate_sql(params[:sql])
|
187
|
+
end
|
188
|
+
|
189
|
+
def params=(p)
|
190
|
+
@params = p
|
191
|
+
end
|
192
|
+
|
193
|
+
def called_segments=(segments)
|
194
|
+
@called_segments = segments
|
195
|
+
end
|
196
|
+
|
197
|
+
protected
|
198
|
+
def parent_segment=(s)
|
199
|
+
@parent_segment = s
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|