Class: Parse::Middleware::Profiling
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Parse::Middleware::Profiling
- Defined in:
- lib/parse/client/profiling.rb
Overview
Faraday middleware that profiles Parse API requests.
This middleware provides detailed timing information for HTTP requests including network time and overall request duration.
Constant Summary collapse
- MAX_PROFILES =
Maximum number of profiles to keep in memory
100
Class Attribute Summary collapse
-
.enabled ⇒ Boolean
Whether profiling is enabled.
Class Method Summary collapse
-
.add_profile(profile) ⇒ Object
Add a profile entry.
-
.callbacks ⇒ Array<Proc>
Callbacks to execute on request completion.
-
.clear_callbacks! ⇒ Object
Clear all registered callbacks.
-
.clear_profiles! ⇒ Object
Clear all stored profiles.
-
.on_request_complete {|Hash| ... } ⇒ Object
Register a callback to be executed when a request completes.
-
.profiles ⇒ Array<Hash>
Recent profile data.
-
.statistics ⇒ Hash
Get aggregate statistics for recent profiles.
Class Attribute Details
.enabled ⇒ Boolean
Returns Whether profiling is enabled.
32 33 34 |
# File 'lib/parse/client/profiling.rb', line 32 def enabled @enabled end |
Class Method Details
.add_profile(profile) ⇒ Object
Add a profile entry
62 63 64 65 66 67 68 69 |
# File 'lib/parse/client/profiling.rb', line 62 def add_profile(profile) profiles << profile # Keep only the most recent profiles profiles.shift while profiles.size > MAX_PROFILES # Execute callbacks callbacks.each { |cb| cb.call(profile) } end |
.callbacks ⇒ Array<Proc>
Returns Callbacks to execute on request completion.
45 46 47 |
# File 'lib/parse/client/profiling.rb', line 45 def callbacks @callbacks ||= [] end |
.clear_callbacks! ⇒ Object
Clear all registered callbacks
56 57 58 |
# File 'lib/parse/client/profiling.rb', line 56 def clear_callbacks! @callbacks = [] end |
.clear_profiles! ⇒ Object
Clear all stored profiles
40 41 42 |
# File 'lib/parse/client/profiling.rb', line 40 def clear_profiles! @profiles = [] end |
.on_request_complete {|Hash| ... } ⇒ Object
Register a callback to be executed when a request completes
51 52 53 |
# File 'lib/parse/client/profiling.rb', line 51 def on_request_complete(&block) callbacks << block if block_given? end |
.profiles ⇒ Array<Hash>
Returns Recent profile data.
35 36 37 |
# File 'lib/parse/client/profiling.rb', line 35 def profiles @profiles ||= [] end |
.statistics ⇒ Hash
Get aggregate statistics for recent profiles
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/parse/client/profiling.rb', line 73 def statistics return {} if profiles.empty? durations = profiles.map { |p| p[:duration_ms] } { count: profiles.size, total_ms: durations.sum, avg_ms: (durations.sum.to_f / durations.size).round(2), min_ms: durations.min, max_ms: durations.max, by_method: profiles.group_by { |p| p[:method] }.transform_values(&:size), by_status: profiles.group_by { |p| p[:status] }.transform_values(&:size), } end |