Class: MysqlDumpSlow::Counter

Inherits:
Object
  • Object
show all
Defined in:
lib/mysql_dump_slow/counter.rb

Constant Summary collapse

TIME_BASE_SEC =
Time.utc(2000, 1, 1).to_i

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(abstract_query) ⇒ Counter

Returns a new instance of Counter.



7
8
9
# File 'lib/mysql_dump_slow/counter.rb', line 7

def initialize(abstract_query)
  @abstract_query = abstract_query
end

Instance Attribute Details

#abstract_queryObject (readonly)

Returns the value of attribute abstract_query.



3
4
5
# File 'lib/mysql_dump_slow/counter.rb', line 3

def abstract_query
  @abstract_query
end

#total_countObject (readonly)

Returns the value of attribute total_count.



3
4
5
# File 'lib/mysql_dump_slow/counter.rb', line 3

def total_count
  @total_count
end

#total_lock_timeObject (readonly)

Returns the value of attribute total_lock_time.



3
4
5
# File 'lib/mysql_dump_slow/counter.rb', line 3

def total_lock_time
  @total_lock_time
end

#total_query_timeObject (readonly)

Returns the value of attribute total_query_time.



3
4
5
# File 'lib/mysql_dump_slow/counter.rb', line 3

def total_query_time
  @total_query_time
end

#total_rows_sentObject (readonly)

Returns the value of attribute total_rows_sent.



3
4
5
# File 'lib/mysql_dump_slow/counter.rb', line 3

def total_rows_sent
  @total_rows_sent
end

#user_hostsObject (readonly)

Returns the value of attribute user_hosts.



3
4
5
# File 'lib/mysql_dump_slow/counter.rb', line 3

def user_hosts
  @user_hosts
end

Instance Method Details

#average_lock_timeObject



27
28
29
# File 'lib/mysql_dump_slow/counter.rb', line 27

def average_lock_time
  total_lock_time / total_count
end

#average_query_timeObject



23
24
25
# File 'lib/mysql_dump_slow/counter.rb', line 23

def average_query_time
  total_query_time / total_count
end

#average_rows_sentObject



31
32
33
# File 'lib/mysql_dump_slow/counter.rb', line 31

def average_rows_sent
  total_rows_sent / total_count
end

#count_up(log) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/mysql_dump_slow/counter.rb', line 11

def count_up(log)
  count_up_query_time(log.query_time)
  count_up_lock_time(log.lock_time)
  count_up_rows_sent(log.rows_sent)
  count_up_user_host(log.user_host)
  count_up_counter
end

#to_mysqldumpslowObject



35
36
37
38
39
40
# File 'lib/mysql_dump_slow/counter.rb', line 35

def to_mysqldumpslow
  <<-EOS
Count: #{total_count}  Time=#{average_query_time/1000}s (#{total_query_time/1000}s)  Lock=#{average_lock_time/1000}s (#{total_lock_time/1000}s)  Rows=#{average_rows_sent} (#{total_rows_sent}),  #{ user_hosts.size == 1 ? user_hosts.first : user_hosts.size.to_s + 'hosts'}
  #{abstract_query}
  EOS
end

#total_user_hostObject



19
20
21
# File 'lib/mysql_dump_slow/counter.rb', line 19

def total_user_host
  @user_hosts.size
end