Class: RuntimeProfiler::InstrumentationData
- Inherits:
-
Object
- Object
- RuntimeProfiler::InstrumentationData
- Defined in:
- lib/runtime_profiler/instrumentation_data.rb
Instance Attribute Summary collapse
-
#controller_data ⇒ Object
readonly
Returns the value of attribute controller_data.
-
#sql_data ⇒ Object
readonly
Returns the value of attribute sql_data.
Instance Method Summary collapse
-
#initialize(controller_data: nil, sql_data: nil) ⇒ InstrumentationData
constructor
A new instance of InstrumentationData.
- #persist! ⇒ Object
Constructor Details
#initialize(controller_data: nil, sql_data: nil) ⇒ InstrumentationData
Returns a new instance of InstrumentationData.
5 6 7 8 |
# File 'lib/runtime_profiler/instrumentation_data.rb', line 5 def initialize(controller_data: nil, sql_data: nil) @controller_data = controller_data @sql_data = sql_data end |
Instance Attribute Details
#controller_data ⇒ Object (readonly)
Returns the value of attribute controller_data.
3 4 5 |
# File 'lib/runtime_profiler/instrumentation_data.rb', line 3 def controller_data @controller_data end |
#sql_data ⇒ Object (readonly)
Returns the value of attribute sql_data.
3 4 5 |
# File 'lib/runtime_profiler/instrumentation_data.rb', line 3 def sql_data @sql_data end |
Instance Method Details
#persist! ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/runtime_profiler/instrumentation_data.rb', line 10 def persist! instrumented_api = [controller_data[:payload][:controller], controller_data[:payload][:action]].join('#') instrumentation_data = { instrumentation: { instrumented_api: instrumented_api, summary: { db_runtime: controller_data[:db_runtime], view_runtime: controller_data[:view_runtime], total_runtime: controller_data[:total_runtime], slowest_sql: sql_calls_data[:slowest_sql], mostly_called_sql: sql_calls_data[:mostly_called_sql], total_sql_calls: sql_calls_data[:total_sql_calls], total_unique_sql_calls: sql_calls_data[:total_unique_sql_calls], slowest_method: method_calls_data[:slowest_method], mostly_called_method: method_calls_data[:mostly_called_method] }, instrumented_sql_calls: sql_calls_data[:instrumented_sql_calls], instrumented_methods: method_calls_data[:instrumented_methods], instrumented_at: Time.now } } FileUtils.mkdir_p(RuntimeProfiler.output_path) filename = ['runtime-profiling', Process.pid, Time.now.to_i].join('-') << '.json' output_file = File.join(RuntimeProfiler.output_path, filename) File.open(output_file, 'w') do |f| f.write JSON.dump(instrumentation_data) end puts '~~~~> [ Profiling RUNTIME ] Profiling now COMPLETE and JSON report written at ' + output_file.to_s puts '~~~~> [ Profiling RUNTIME ]' puts '~~~~> [ Profiling RUNTIME ] You can do the following to view the JSON report in console:' puts '~~~~> [ Profiling RUNTIME ]' puts '~~~~> [ Profiling RUNTIME ] bundle exec runtime_profiler view ' + output_file.to_s puts '~~~~> [ Profiling RUNTIME ]' puts '~~~~> [ Profiling RUNTIME ] Or' puts '~~~~> [ Profiling RUNTIME ]' puts '~~~~> [ Profiling RUNTIME ] bundle exec runtime_profiler view --help' puts '~~~~> [ Profiling RUNTIME ]' puts '~~~~> [ Profiling RUNTIME ] for more details.' end |