Class: QueryTraceSummary::EventSummary
- Inherits:
-
Object
- Object
- QueryTraceSummary::EventSummary
- Defined in:
- lib/event_summary.rb
Constant Summary collapse
- ASCII_COLOR_RX =
/\e\[\d+m/- EVENT_RX =
/([A-Z][A-Za-z0-9_:]+) (Create|Load|Update|Destroy) \((\d+(?:\.\d+)?)ms\)/- LOCATION_PREFIX_RX =
/Query Trace:$/- LOCATION_RX =
Assumes conservative file naming
/([a-zA-Z0-9_.\-\/]+:\d+:in `.+')$/
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#calls ⇒ Object
Returns the value of attribute calls.
-
#location ⇒ Object
Returns the value of attribute location.
-
#model ⇒ Object
Returns the value of attribute model.
-
#total_time ⇒ Object
Returns the value of attribute total_time.
Class Method Summary collapse
-
.parse_files(*file_names) ⇒ Object
Gathers all of the events in provided files and returns array of event summaries sorted in descending order by their total time.
Instance Method Summary collapse
-
#initialize(model, action, location) ⇒ EventSummary
constructor
A new instance of EventSummary.
Constructor Details
#initialize(model, action, location) ⇒ EventSummary
Returns a new instance of EventSummary.
15 16 17 18 19 20 |
# File 'lib/event_summary.rb', line 15 def initialize(model, action, location) @model = model @action = action @location = location @total_time = @calls = 0 end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
5 6 7 |
# File 'lib/event_summary.rb', line 5 def action @action end |
#calls ⇒ Object
Returns the value of attribute calls.
5 6 7 |
# File 'lib/event_summary.rb', line 5 def calls @calls end |
#location ⇒ Object
Returns the value of attribute location.
5 6 7 |
# File 'lib/event_summary.rb', line 5 def location @location end |
#model ⇒ Object
Returns the value of attribute model.
5 6 7 |
# File 'lib/event_summary.rb', line 5 def model @model end |
#total_time ⇒ Object
Returns the value of attribute total_time.
5 6 7 |
# File 'lib/event_summary.rb', line 5 def total_time @total_time end |
Class Method Details
.parse_files(*file_names) ⇒ Object
Gathers all of the events in provided files and returns array of event summaries sorted in descending order by their total time
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 53 54 55 56 |
# File 'lib/event_summary.rb', line 25 def self.parse_files(*file_names) events = {} event_match = nil each_line(*file_names) do |line| # Previous line was an event if event_match location_match = LOCATION_RX.match(line) if location_match model, action, time = event_match.captures location = location_match.captures.first key = "#{model}/#{action}/#{location}" event = events[key] ||= new(model, action, location) event.calls += 1 event.total_time += time.to_d event_match = nil next elsif LOCATION_PREFIX_RX.match(line) next end end event_match = EVENT_RX.match(line) end events.values.sort_by { |summary| -summary.total_time } end |