Class: Txnap::Trace
- Inherits:
-
Object
- Object
- Txnap::Trace
- Defined in:
- lib/txnap/trace.rb
Constant Summary collapse
- TOP_GAPS_LIMIT =
3- LOCK_CANDIDATES_LIMIT =
20- SQL_LENGTH_LIMIT =
500
Instance Attribute Summary collapse
-
#database_time ⇒ Object
readonly
Returns the value of attribute database_time.
-
#sql_count ⇒ Object
readonly
Returns the value of attribute sql_count.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
-
#transaction ⇒ Object
readonly
Returns the value of attribute transaction.
Instance Method Summary collapse
- #bind_transaction(transaction) ⇒ Object
-
#initialize(start:, finish:, sql:) ⇒ Trace
constructor
A new instance of Trace.
- #matches_transaction?(candidate) ⇒ Boolean
- #record_sql(start:, finish:, sql:, name:, call_site:, lock_candidate: nil) ⇒ Object
- #record_terminal(start:, finish:, sql:) ⇒ Object
- #record_transaction(start:, finish:, sql:) ⇒ Object
- #terminal? ⇒ Boolean
- #to_report(outcome) ⇒ Object
- #would_update_longest_gap?(start) ⇒ Boolean
Constructor Details
#initialize(start:, finish:, sql:) ⇒ Trace
Returns a new instance of Trace.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/txnap/trace.rb', line 11 def initialize(start:, finish:, sql:) @started_at = finish @previous_finish = finish @previous_event = (sql, "TRANSACTION", nil) @database_time = positive_duration(start, finish) @sql_count = 0 @gaps = [] @lock_candidates = [] @transaction = nil @ended_at = nil end |
Instance Attribute Details
#database_time ⇒ Object (readonly)
Returns the value of attribute database_time.
9 10 11 |
# File 'lib/txnap/trace.rb', line 9 def database_time @database_time end |
#sql_count ⇒ Object (readonly)
Returns the value of attribute sql_count.
9 10 11 |
# File 'lib/txnap/trace.rb', line 9 def sql_count @sql_count end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
9 10 11 |
# File 'lib/txnap/trace.rb', line 9 def started_at @started_at end |
#transaction ⇒ Object (readonly)
Returns the value of attribute transaction.
9 10 11 |
# File 'lib/txnap/trace.rb', line 9 def transaction @transaction end |
Instance Method Details
#bind_transaction(transaction) ⇒ Object
23 24 25 |
# File 'lib/txnap/trace.rb', line 23 def bind_transaction(transaction) @transaction ||= transaction end |
#matches_transaction?(candidate) ⇒ Boolean
27 28 29 |
# File 'lib/txnap/trace.rb', line 27 def matches_transaction?(candidate) transaction && candidate && transaction.equal?(candidate) end |
#record_sql(start:, finish:, sql:, name:, call_site:, lock_candidate: nil) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/txnap/trace.rb', line 39 def record_sql(start:, finish:, sql:, name:, call_site:, lock_candidate: nil) event = (sql, name, call_site) observe_event(start: start, finish: finish, event: event) @sql_count += 1 add_lock_candidate(lock_candidate) end |
#record_terminal(start:, finish:, sql:) ⇒ Object
54 55 56 57 58 |
# File 'lib/txnap/trace.rb', line 54 def record_terminal(start:, finish:, sql:) effective_start = [start, @previous_finish].max @ended_at = effective_start record_transaction(start: start, finish: finish, sql: sql) end |
#record_transaction(start:, finish:, sql:) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/txnap/trace.rb', line 46 def record_transaction(start:, finish:, sql:) observe_event( start: start, finish: finish, event: (sql, "TRANSACTION", nil) ) end |
#terminal? ⇒ Boolean
31 32 33 |
# File 'lib/txnap/trace.rb', line 31 def terminal? !@ended_at.nil? end |
#to_report(outcome) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/txnap/trace.rb', line 60 def to_report(outcome) return unless terminal? Report.new( outcome: outcome, transaction_duration: positive_duration(started_at, @ended_at), database_time: database_time, gaps: @gaps.dup, sql_count: sql_count ) end |
#would_update_longest_gap?(start) ⇒ Boolean
35 36 37 |
# File 'lib/txnap/trace.rb', line 35 def would_update_longest_gap?(start) gap_duration(start) > longest_gap_duration end |