Class: Maatkit::MergeMqdResults

Inherits:
Object
  • Object
show all
Defined in:
lib/maatkit-ruby/mk-merge-mqd-results.rb

Overview

Merge multiple mk-query-digest reports into one.

Maatkit::MergeMqdResults.new( array, str, array)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMergeMqdResults

Returns a new MergeMqdResults Object



191
192
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 191

def initialize()
end

Instance Attribute Details

#ask_passObject

Prompt for a password when connecting to MySQL.



17
18
19
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 17

def ask_pass
  @ask_pass
end

#charsetObject

short form: -A; type: string Default character set. If the value is utf8, sets Perl’s binmode on STDOUT to utf8, passes the mysql_enable_utf8 option to DBD::mysql, and runs SET NAMES UTF8 after connecting to MySQL. Any other value sets binmode on STDOUT without the utf8 layer, and runs SET NAMES after connecting to MySQL.



24
25
26
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 24

def charset
  @charset
end

#configObject

type: Array Read this comma-separated list of config files; if specified, this must be the first option on the command line.



30
31
32
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 30

def config
  @config
end

#defaults_fileObject

short form: -F; type: string Only read mysql options from the given file. You must give an absolute pathname.



35
36
37
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 35

def defaults_file
  @defaults_file
end

#expected_rangeObject

type: array; default: 5,10 Explain items when there are more or fewer than expected. Defines the number of items expected to be seen in the report as controlled by “–limit” and “–outliers”. If there are more or fewer items in the report, each one will explain why it was included.



43
44
45
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 43

def expected_range
  @expected_range
end

#explainObject

type: DSN Run EXPLAIN for the sample query with this DSN and print results. This causes mk-merge-mqd-results to run EXPLAIN and include the output into the report. For safety, queries that appear to have a subquery that EXPLAIN will execute won’t be EXPLAINed. Those are typically “derived table” queries of the form

select ... from ( select .... ) der;


52
53
54
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 52

def explain
  @explain
end

#fingerprintsObject

Add query fingerprints to the standard query analysis report. This is mostly useful for debugging purposes.



57
58
59
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 57

def fingerprints
  @fingerprints
end

#for_explainObject

default: yes Print extra information to make analysis easy. This option adds code snippets to make it easy to run SHOW CREATE TABLE and SHOW TABLE STATUS for the query’s tables. It also rewrites non-SELECT queries into a SELECT that might be helpful for determining the non-SELECT statement’s index usage.



65
66
67
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 65

def for_explain
  @for_explain
end

#helpObject

Show help and exit.



69
70
71
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 69

def help
  @help
end

#hostObject

short form: -h; type: string Connect to host.



74
75
76
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 74

def host
  @host
end

#limitObject

type: string; default: 95%:20 Limit output to the given percentage or count. If the argument is an integer, report only the top N worst queries. If the argument is an integer followed by the “%” sign, report that percentage of the worst queries. If the percentage is followed by a colon and another integer, report the top percentage or the number specified by that integer, whichever comes first. See also “–outliers”.



84
85
86
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 84

def limit
  @limit
end

#order_byObject

type: string; default: Query_time:sum Sort events by this attribute and aggregate function.



89
90
91
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 89

def order_by
  @order_by
end

#outliersObject

type: string; default: Query_time:1:10 Report outliers by attribute:percentile:count. The syntax of this option is a comma-separated list of colon-delimited strings. The first field is the attribute by which an outlier is defined. The second is a number that is compared to the attribute’s 95th percentile. The third is optional, and is compared to the attribute’s cnt aggregate. Queries that pass this specification are added to the report, regardless of any limits you specified in “–limit”. For example, to report queries whose 95th percentile Query_time is at least 60 seconds and which are seen at least 5 times, use the following argument:

--outliers Query_time:60:5


102
103
104
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 102

def outliers
  @outliers
end

#passwordObject

short form: -p; type: string Password to use when connecting.



107
108
109
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 107

def password
  @password
end

#path_to_mk_merge_mqd_resultsObject

Sets the executable path, otherwise the environment path will be used.



186
187
188
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 186

def path_to_mk_merge_mqd_results
  @path_to_mk_merge_mqd_results
end

#portObject

short form: -P; type: int Port number to use for connection.



112
113
114
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 112

def port
  @port
end

#report_formatObject

type: Array; default: rusage,date,files,header,profile,query_report,prepared Print these sections of the query analysis report.

SECTION# # PRINTS
============ ==============================================================
rusgae# #  CPU times and memory usage reported by ps
date# # # Current local date and time
files# #   Input files read/parse
header# #  Summary of the entire analysis run
profile# # Compact table of queries for an at-a-glance view of the report
query_report Detailed information about each unique query
prepared#   Prepared statements

The sections are printed in the order specified. The rusage, date, files and header sections are grouped together if specified together; other sections are separted by blank lines.



128
129
130
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 128

def report_format
  @report_format
end

#report_histogramObject

type: string; default: Query_time Chart the distribution of this attribute’s values. The distribution chart is limited to time-based attributes, so charting “Rows_examined”, for example, will produce a useless chart.



135
136
137
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 135

def report_histogram
  @report_histogram
end

#set_varsObject

type: string; default: wait_timeout=10000 Set these MySQL variables. Immediately after connecting to MySQL, this string will be appended to SET and executed.



141
142
143
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 141

def set_vars
  @set_vars
end

#shortenObject

type: int; default: 1024 Shorten long statements in reports. Shortens long statements, replacing the omitted portion with a “/*… omitted …*/” comment. This applies only to the output in reports, not to information stored other places. It prevents a large statement from causing difficulty in a report. The argument is the preferred length of the shortened statement. Not all statements can be shortened, but very large INSERT and similar statements often can; and so can IN() lists, although only the first such list in the statement will be shortened. If it shortens something beyond recognition, you can find the original statement in the log, at the offset shown in the report header.



153
154
155
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 153

def shorten
  @shorten
end

#show_allObject

type: Hash Show all values for these attributes. By default mk-query-digest only shows as many of an attribute’s value that fit on a single line. This option allows you to specify attributes for which all values will be shown (line width is ignored). This only works for attributes with string values like user, host, db, etc. Multiple attributes can be specified, comma-separated.



162
163
164
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 162

def show_all
  @show_all
end

#socketObject

short form: -S; type: string Socket file to use for connection.



167
168
169
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 167

def socket
  @socket
end

#userObject

short form: -u; type: string User for login if not current user.



172
173
174
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 172

def user
  @user
end

#versionObject

Show version and exit.



176
177
178
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 176

def version
  @version
end

#zero_boolObject

default: yes Print 0% boolean values in report.



181
182
183
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 181

def zero_bool
  @zero_bool
end

Instance Method Details

#start(options = nil) ⇒ Object

Execute the command



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/maatkit-ruby/mk-merge-mqd-results.rb', line 197

def start(options = nil)
  tmp = Tempfile.new('tmp')
  command = option_string() + options.to_s + " 2> " + tmp.path
  success = system(command)
  if success
    begin
      while (line = tmp.readline)
        line.chomp
        selected_string = line
      end
    rescue EOFError
      tmp.close
    end
    return selected_string
  else
    tmp.close!
    return success
  end
end