Class: MysqlDumpSlow::Counter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(abstract_query) ⇒ Counter

Returns a new instance of Counter.



5
6
7
# File 'lib/mysql_dump_slow/counter.rb', line 5

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



25
26
27
# File 'lib/mysql_dump_slow/counter.rb', line 25

def average_lock_time
  total_lock_time / total_count
end

#average_query_timeObject



21
22
23
# File 'lib/mysql_dump_slow/counter.rb', line 21

def average_query_time
  total_query_time / total_count
end

#average_rows_sentObject



29
30
31
# File 'lib/mysql_dump_slow/counter.rb', line 29

def average_rows_sent
  total_rows_sent / total_count
end

#count_up(log) ⇒ Object



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

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



33
34
35
36
37
38
# File 'lib/mysql_dump_slow/counter.rb', line 33

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



17
18
19
# File 'lib/mysql_dump_slow/counter.rb', line 17

def total_user_host
  @user_hosts.size
end