Class: PerfMonger::Command::PlotCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- PerfMonger::Command::PlotCommand
- Defined in:
- lib/perfmonger/command/plot.rb
Instance Method Summary collapse
-
#initialize ⇒ PlotCommand
constructor
A new instance of PlotCommand.
- #parse_args(argv) ⇒ Object
- #run(argv) ⇒ Object
Methods inherited from BaseCommand
register_alias, register_command
Constructor Details
#initialize ⇒ PlotCommand
Returns a new instance of PlotCommand.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/perfmonger/command/plot.rb', line 13 def initialize @parser = OptionParser.new @parser. = "Usage: perfmonger plot [options] LOG_FILE\n\nOptions:\n" @data_file = nil @offset_time = 0.0 @output_dir = Dir.pwd @output_type = 'pdf' @output_prefix = '' @save_gpfiles = false @disk_only = nil @disk_only_regex = nil @disk_plot_read = true @disk_plot_write = true @disk_numkey_threshold = 10 @plot_iops_max = nil @gnuplot_bin = `which gnuplot` end |
Instance Method Details
#parse_args(argv) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/perfmonger/command/plot.rb', line 36 def parse_args(argv) @parser.on('--offset-time TIME') do |time| @offset_time = Float(time) end @parser.on('-o', '--output-dir DIR') do |dir| unless File.directory?(dir) puts("ERROR: no such directory: #{dir}") puts(@parser.help) exit(false) end @output_dir = dir end @parser.on('--with-gnuplot GNUPLOT_BIN') do |gnuplot_bin| @gnuplot_bin = gnuplot_bin end @parser.on('-T', '--output-type TYPE', 'Available: pdf, png') do |typ| unless ['pdf', 'png'].include?(typ) puts("ERROR: non supported image type: #{typ}") puts(@parser.help) exit(false) end if typ != 'pdf' && ! system('which convert >/dev/null 2>&1') puts("ERROR: convert(1) not found.") puts("ERROR: ImageMagick is required for #{typ}") puts(@parser.help) exit(false) end @output_type = typ end @parser.on('-p', '--prefix PREFIX', 'Output file name prefix.') do |prefix| if ! (prefix =~ /-\Z/) prefix += '-' end @output_prefix = prefix end @parser.on('-s', '--save', 'Save GNUPLOT and data files.') do @save_gpfiles = true end @parser.on('--disk-only REGEX', "Select disk devices that matches REGEX") do |regex| @disk_only = regex @disk_only_regex = Regexp.compile(regex) end @parser.on('--plot-read-only', "Plot only READ performance for disks") do @disk_plot_read = true @disk_plot_write = false end @parser.on('--plot-write-only', "Plot only WRITE performance for disks") do @disk_plot_read = false @disk_plot_write = true end @parser.on('--plot-read-write', "Plot READ and WRITE performance for disks") do @disk_plot_read = true @disk_plot_write = true end @parser.on('--plot-numkey-threshold NUM', "Legends of per-disk plots are turned off if the number of disks is larger than this value.") do |num| @disk_numkey_threshold = num.to_i end @parser.on('--plot-iops-max IOPS', "Maximum of IOPS plot range (default: auto)") do |iops| @plot_iops_max = iops.to_f end @parser.parse!(argv) if argv.size == 0 puts("ERROR: PerfMonger log file is required") puts(@parser.help) exit(false) end @data_file = File.(argv.shift) end |
#run(argv) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/perfmonger/command/plot.rb', line 126 def run(argv) unless system('which gnuplot >/dev/null 2>&1') puts("ERROR: gnuplot not found") puts(@parser.help) exit(false) end parse_args(argv) unless system('gnuplot -e "set terminal" < /dev/null 2>&1 | grep pdfcairo >/dev/null 2>&1') puts("ERROR: pdfcairo is not supported by installed gnuplot") puts("ERROR: PerfMonger requires pdfcairo-supported gnuplot") puts(@parser.help) exit(false) end formatter_bin = ::PerfMonger::Command::CoreFinder.plot_formatter() @tmpdir = Dir.mktmpdir @disk_dat = File.("disk.dat", @tmpdir) @cpu_dat = File.("cpu.dat", @tmpdir) = nil cmd = [formatter_bin, "-perfmonger", @data_file, "-cpufile", @cpu_dat, "-diskfile", @disk_dat] if @disk_only_regex cmd << "-disk-only" cmd << @disk_only end IO.popen(cmd, "r") do |io| = io.read end if $?.exitstatus != 0 puts("ERROR: failed to run perfmonger-plot-formatter") exit(false) end = JSON.parse() plot_disk() plot_cpu() FileUtils.rm_rf(@tmpdir) true end |