Module: Profiler
- Defined in:
- lib/profiler.rb,
lib/profiler/engine.rb,
lib/profiler/railtie.rb,
lib/profiler/version.rb,
lib/profiler/mcp/server.rb,
lib/profiler/job_profiler.rb,
lib/profiler/configuration.rb,
lib/profiler/explain_runner.rb,
lib/profiler/mcp/file_cache.rb,
lib/profiler/models/profile.rb,
lib/profiler/current_context.rb,
lib/profiler/models/sql_query.rb,
lib/profiler/mcp/body_formatter.rb,
lib/profiler/mcp/path_extractor.rb,
lib/profiler/storage/base_store.rb,
lib/profiler/storage/blob_store.rb,
lib/profiler/storage/file_store.rb,
lib/profiler/storage/redis_store.rb,
lib/profiler/mcp/tools/query_jobs.rb,
lib/profiler/storage/memory_store.rb,
lib/profiler/storage/sqlite_store.rb,
lib/profiler/models/timeline_event.rb,
lib/profiler/mcp/tools/explain_query.rb,
lib/profiler/collectors/env_collector.rb,
lib/profiler/collectors/job_collector.rb,
lib/profiler/collectors/log_collector.rb,
lib/profiler/mcp/tools/clear_profiles.rb,
lib/profiler/mcp/tools/query_profiles.rb,
lib/profiler/collectors/ajax_collector.rb,
lib/profiler/collectors/base_collector.rb,
lib/profiler/collectors/dump_collector.rb,
lib/profiler/collectors/http_collector.rb,
lib/profiler/collectors/i18n_collector.rb,
lib/profiler/collectors/view_collector.rb,
lib/profiler/mcp/resources/n1_patterns.rb,
lib/profiler/mcp/resources/recent_jobs.rb,
lib/profiler/mcp/tools/analyze_queries.rb,
lib/profiler/collectors/cache_collector.rb,
lib/profiler/mcp/resources/slow_queries.rb,
lib/profiler/mcp/tools/get_profile_ajax.rb,
lib/profiler/mcp/tools/get_profile_http.rb,
lib/profiler/middleware/cors_middleware.rb,
lib/profiler/collectors/routes_collector.rb,
lib/profiler/mcp/tools/get_profile_dumps.rb,
lib/profiler/middleware/toolbar_injector.rb,
lib/profiler/collectors/request_collector.rb,
lib/profiler/mcp/tools/get_profile_detail.rb,
app/controllers/profiler/assets_controller.rb,
lib/profiler/collectors/database_collector.rb,
lib/profiler/mcp/resources/recent_requests.rb,
lib/profiler/collectors/exception_collector.rb,
lib/profiler/middleware/profiler_middleware.rb,
app/controllers/profiler/api/ajax_controller.rb,
app/controllers/profiler/api/jobs_controller.rb,
app/controllers/profiler/profiles_controller.rb,
lib/profiler/collectors/flamegraph_collector.rb,
app/controllers/profiler/api/explain_controller.rb,
app/controllers/profiler/api/toolbar_controller.rb,
app/controllers/profiler/application_controller.rb,
lib/profiler/instrumentation/sidekiq_middleware.rb,
app/controllers/profiler/api/env_vars_controller.rb,
app/controllers/profiler/api/profiles_controller.rb,
lib/profiler/collectors/function_profiler_collector.rb,
app/controllers/profiler/api/outbound_http_controller.rb,
lib/profiler/instrumentation/net_http_instrumentation.rb,
lib/profiler/instrumentation/active_job_instrumentation.rb,
app/controllers/profiler/api/function_profiling_controller.rb
Defined Under Namespace
Modules: Api, Collectors, CurrentContext, ExplainRunner, I18nLookupTracker, Instrumentation, MCP, Middleware, Models, Storage Classes: ApplicationController, AssetsController, Configuration, Engine, Error, JobProfiler, ProfilesController, Railtie
Constant Summary collapse
- VERSION =
"0.18.0"
Class Attribute Summary collapse
- .configuration ⇒ Object
-
.function_profiling_clock ⇒ Object
Returns the value of attribute function_profiling_clock.
-
.function_profiling_enabled ⇒ Object
Returns the value of attribute function_profiling_enabled.
-
.function_profiling_max_frames ⇒ Object
Returns the value of attribute function_profiling_max_frames.
-
.function_profiling_mode ⇒ Object
Returns the value of attribute function_profiling_mode.
Class Method Summary collapse
- .configure {|configuration| ... } ⇒ Object
-
.dump(value, label = nil) ⇒ Object
Dump a variable to the profiler Usage: Profiler.dump(variable, “optional label”).
- .enabled? ⇒ Boolean
-
.measure(label, metadata: {}, &block) ⇒ Object
Instrument an arbitrary code block and record it in the FlameGraph.
- .storage ⇒ Object
Class Attribute Details
.configuration ⇒ Object
16 17 18 |
# File 'lib/profiler.rb', line 16 def configuration @configuration ||= Configuration.new end |
.function_profiling_clock ⇒ Object
Returns the value of attribute function_profiling_clock.
14 15 16 |
# File 'lib/profiler.rb', line 14 def function_profiling_clock @function_profiling_clock end |
.function_profiling_enabled ⇒ Object
Returns the value of attribute function_profiling_enabled.
11 12 13 |
# File 'lib/profiler.rb', line 11 def function_profiling_enabled @function_profiling_enabled end |
.function_profiling_max_frames ⇒ Object
Returns the value of attribute function_profiling_max_frames.
12 13 14 |
# File 'lib/profiler.rb', line 12 def function_profiling_max_frames @function_profiling_max_frames end |
.function_profiling_mode ⇒ Object
Returns the value of attribute function_profiling_mode.
13 14 15 |
# File 'lib/profiler.rb', line 13 def function_profiling_mode @function_profiling_mode end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
20 21 22 |
# File 'lib/profiler.rb', line 20 def configure yield(configuration) end |
.dump(value, label = nil) ⇒ Object
Dump a variable to the profiler Usage: Profiler.dump(variable, “optional label”)
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/profiler.rb', line 56 def dump(value, label = nil) return unless enabled? # Get caller location caller_location = caller_locations(1, 1).first file = caller_location.path line = caller_location.lineno # Initialize dumps array if needed Thread.current[:profiler_dumps] ||= [] # Store the dump Thread.current[:profiler_dumps] << { value: value, label: label, file: file, line: line, timestamp: Time.now } value end |
.enabled? ⇒ Boolean
28 29 30 |
# File 'lib/profiler.rb', line 28 def enabled? configuration.enabled end |
.measure(label, metadata: {}, &block) ⇒ Object
Instrument an arbitrary code block and record it in the FlameGraph. Usage: Profiler.measure(“payment.stripe_charge”, metadata: { amount: 1000 }) { Stripe::Charge.create(…) }
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/profiler.rb', line 34 def measure(label, metadata: {}, &block) return yield unless enabled? collector = Thread.current[:profiler_flamegraph_collector] return yield unless collector started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC) result = yield finished_at = Process.clock_gettime(Process::CLOCK_MONOTONIC) collector.record_custom_event( label: label, started_at: started_at, finished_at: finished_at, metadata: ) result end |
.storage ⇒ Object
24 25 26 |
# File 'lib/profiler.rb', line 24 def storage @storage ||= configuration.storage_backend end |