Class: RuntimeProfiler::SqlEvent
- Inherits:
-
Object
- Object
- RuntimeProfiler::SqlEvent
- Defined in:
- lib/runtime_profiler/events/sql_event.rb
Instance Attribute Summary collapse
-
#finished_at ⇒ Object
readonly
Returns the value of attribute finished_at.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
-
#trace ⇒ Object
readonly
Returns the value of attribute trace.
Instance Method Summary collapse
-
#initialize(args:, trace:) ⇒ SqlEvent
constructor
A new instance of SqlEvent.
- #key ⇒ Object
- #recordable? ⇒ Boolean
- #sanitized_sql ⇒ Object
- #total_runtime ⇒ Object
Constructor Details
#initialize(args:, trace:) ⇒ SqlEvent
Returns a new instance of SqlEvent.
7 8 9 10 |
# File 'lib/runtime_profiler/events/sql_event.rb', line 7 def initialize(args: , trace: ) _name, @started_at, @finished_at, _unique_id, @payload = args @trace = sanitize_trace!(trace) end |
Instance Attribute Details
#finished_at ⇒ Object (readonly)
Returns the value of attribute finished_at.
5 6 7 |
# File 'lib/runtime_profiler/events/sql_event.rb', line 5 def finished_at @finished_at end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
5 6 7 |
# File 'lib/runtime_profiler/events/sql_event.rb', line 5 def payload @payload end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
5 6 7 |
# File 'lib/runtime_profiler/events/sql_event.rb', line 5 def started_at @started_at end |
#trace ⇒ Object (readonly)
Returns the value of attribute trace.
5 6 7 |
# File 'lib/runtime_profiler/events/sql_event.rb', line 5 def trace @trace end |
Instance Method Details
#key ⇒ Object
34 35 36 |
# File 'lib/runtime_profiler/events/sql_event.rb', line 34 def key @key ||= Digest::MD5.hexdigest(sql.downcase) end |
#recordable? ⇒ Boolean
12 13 14 15 |
# File 'lib/runtime_profiler/events/sql_event.rb', line 12 def recordable? return true unless RuntimeProfiler.instrumented_sql_commands.respond_to?(:join) instrumented_sql_matcher =~ sql end |
#sanitized_sql ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/runtime_profiler/events/sql_event.rb', line 21 def sanitized_sql sql.squish! sql.gsub!(/(\s(=|>|<|>=|<=|<>|!=)\s)('[^']+'|[\$\+\-\w\.]+)/, '\1xxx') sql.gsub!(/(\sIN\s)\([^\(\)]+\)/i, '\1(xxx)') sql.gsub!(/(\sBETWEEN\s)('[^']+'|[\+\-\w\.]+)(\sAND\s)('[^']+'|[\+\-\w\.]+)/i, '\1xxx\3xxx') sql.gsub!(/(\sVALUES\s)\(.+\)/i, '\1(xxx)') sql.gsub!(/(\s(LIKE|ILIKE|SIMILAR TO|NOT SIMILAR TO)\s)('[^']+')/i, '\1xxx') sql.gsub!(/(\s(LIMIT|OFFSET)\s)(\d+)/i, '\1xxx') sql end |
#total_runtime ⇒ Object
17 18 19 |
# File 'lib/runtime_profiler/events/sql_event.rb', line 17 def total_runtime 1000.0 * (@finished_at - @started_at) end |