Class: RspecProfiling::Example

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_profiling/example.rb

Constant Summary collapse

IGNORED_QUERIES_PATTERN =
%r{(
  pg_table|
  pg_attribute|
  pg_namespace|
  show\stables|
  pragma|
  sqlite_master/rollback|
  ^TRUNCATE TABLE|
  ^ALTER TABLE|
  ^BEGIN|
  ^COMMIT|
  ^ROLLBACK|
  ^RELEASE|
  ^SAVEPOINT
)}xi

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(example) ⇒ Example

Returns a new instance of Example.



26
27
28
29
30
31
32
# File 'lib/rspec_profiling/example.rb', line 26

def initialize(example)
  @example = example
  @counts  = Hash.new(0)
  @event_counts = Hash.new(0)
  @event_times = Hash.new(0)
  @event_events = Hash.new()
end

Instance Attribute Details

#event_countsObject (readonly)

Returns the value of attribute event_counts.



78
79
80
# File 'lib/rspec_profiling/example.rb', line 78

def event_counts
  @event_counts
end

#event_eventsObject (readonly)

Returns the value of attribute event_events.



78
79
80
# File 'lib/rspec_profiling/example.rb', line 78

def event_events
  @event_events
end

#event_timesObject (readonly)

Returns the value of attribute event_times.



78
79
80
# File 'lib/rspec_profiling/example.rb', line 78

def event_times
  @event_times
end

Instance Method Details

#descriptionObject



42
43
44
# File 'lib/rspec_profiling/example.rb', line 42

def description
  [:full_description]
end

#exceptionObject



50
51
52
# File 'lib/rspec_profiling/example.rb', line 50

def exception
  execution_result.exception
end

#fileObject



34
35
36
# File 'lib/rspec_profiling/example.rb', line 34

def file
  [:file_path]
end

#line_numberObject



38
39
40
# File 'lib/rspec_profiling/example.rb', line 38

def line_number
  [:line_number]
end

#log_event(event_name, event, start, finish) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/rspec_profiling/example.rb', line 92

def log_event(event_name, event, start, finish)
  event_counts[event_name] += 1
  event_times[event_name] += (finish - start)
  event_events[event_name] ||= []
  if verbose_record_event?(event_name)
    begin
      event_events[event_name] << event.as_json
    rescue => e
      # no op
    end
  end
end

#log_query(query, start, finish) ⇒ Object



80
81
82
83
84
85
# File 'lib/rspec_profiling/example.rb', line 80

def log_query(query, start, finish)
  unless query[:sql] =~ IGNORED_QUERIES_PATTERN
    counts[:query_count] += 1
    counts[:query_time] += (finish - start)
  end
end

#log_request(request, start, finish) ⇒ Object



87
88
89
90
# File 'lib/rspec_profiling/example.rb', line 87

def log_request(request, start, finish)
  counts[:request_count] += 1
  counts[:request_time] += request[:view_runtime].to_f
end

#owner_tagObject



58
59
60
# File 'lib/rspec_profiling/example.rb', line 58

def owner_tag
  ownership_for_file([:file_path])
end

#query_countObject



62
63
64
# File 'lib/rspec_profiling/example.rb', line 62

def query_count
  counts[:query_count]
end

#query_timeObject



66
67
68
# File 'lib/rspec_profiling/example.rb', line 66

def query_time
  counts[:query_time]
end

#request_countObject



70
71
72
# File 'lib/rspec_profiling/example.rb', line 70

def request_count
  counts[:request_count]
end

#request_timeObject



74
75
76
# File 'lib/rspec_profiling/example.rb', line 74

def request_time
  counts[:request_time]
end

#statusObject



46
47
48
# File 'lib/rspec_profiling/example.rb', line 46

def status
  execution_result.status
end

#timeObject



54
55
56
# File 'lib/rspec_profiling/example.rb', line 54

def time
  execution_result.run_time
end