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.
33 34 35 |
# File 'lib/parse/client/profiling.rb', line 33 def enabled @enabled end |
Class Method Details
.add_profile(profile) ⇒ Object
Add a profile entry
63 64 65 66 67 68 69 70 |
# File 'lib/parse/client/profiling.rb', line 63 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.
46 47 48 |
# File 'lib/parse/client/profiling.rb', line 46 def callbacks @callbacks ||= [] end |
.clear_callbacks! ⇒ Object
Clear all registered callbacks
57 58 59 |
# File 'lib/parse/client/profiling.rb', line 57 def clear_callbacks! @callbacks = [] end |
.clear_profiles! ⇒ Object
Clear all stored profiles
41 42 43 |
# File 'lib/parse/client/profiling.rb', line 41 def clear_profiles! @profiles = [] end |
.on_request_complete {|Hash| ... } ⇒ Object
Register a callback to be executed when a request completes
52 53 54 |
# File 'lib/parse/client/profiling.rb', line 52 def on_request_complete(&block) callbacks << block if block_given? end |
.profiles ⇒ Array<Hash>
Returns Recent profile data.
36 37 38 |
# File 'lib/parse/client/profiling.rb', line 36 def profiles @profiles ||= [] end |
.statistics ⇒ Hash
Get aggregate statistics for recent profiles
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/parse/client/profiling.rb', line 74 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 |