Class: Serialbench::Cli::BenchmarkCli
- Defined in:
- lib/serialbench/cli/benchmark_cli.rb
Overview
CLI for managing individual benchmark runs
Instance Method Summary collapse
- #_docker_execute(environment_config_path, benchmark_config_path) ⇒ Object
- #build_site(result_path) ⇒ Object
- #create(name = nil) ⇒ Object
- #execute(environment_config_path, benchmark_config_path) ⇒ Object
- #list ⇒ Object
Methods inherited from BaseCli
Instance Method Details
#_docker_execute(environment_config_path, benchmark_config_path) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 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 |
# File 'lib/serialbench/cli/benchmark_cli.rb', line 107 def _docker_execute(environment_config_path, benchmark_config_path) environment_config = load_environment_config(environment_config_path) benchmark_config = load_benchmark_config(benchmark_config_path) say '🚀 Executing benchmark run', :green say "Environment: #{environment_config_path} (#{environment_config.kind})", :cyan say "Configuration: #{benchmark_config_path}", :cyan runner = Serialbench::BenchmarkRunner.new( environment_config: environment_config, benchmark_config: benchmark_config ) # Run benchmarks results = runner.run_all_benchmarks platform = Serialbench::Models::Platform.current_local = Models::RunMetadata.new( benchmark_config_path: benchmark_config_path, environment_config_path: environment_config_path, tags: [ 'docker', platform.os, platform.arch, "ruby-#{environment_config.ruby_build_tag}" ] ) # Create results directory result_dir = [:result_dir] FileUtils.mkdir_p(result_dir) # Save results to single YAML file with platform and metadata merged in results_model = Models::Result.new( platform: platform, metadata: , environment_config: environment_config, benchmark_config: benchmark_config, benchmark_result: results ) # Restore YAML to use Psych for output, otherwise lutaml-model's to_yaml # will have no output Object.const_set(:YAML, Psych) results_file = File.join(result_dir, 'results.yaml') results_model.to_file(results_file) say '✅ Local benchmark completed successfully!', :green say 'Results saved.', :cyan rescue StandardError => e say "❌ Local benchmark failed: #{e.message}", :red say "Details: #{e.backtrace.first(3).join("\n")}", :white if [:verbose] raise e end |
#build_site(result_path) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/serialbench/cli/benchmark_cli.rb', line 175 def build_site(result_path) unless Dir.exist?(result_path) say "Result directory not found: #{result_path}", :red say "Please create a result first using 'serialbench benchmark create'", :white exit 1 end result = Serialbench::Models::Result.load(result_path) if result.nil? say "Result '#{result_path}' not found", :yellow say "Use 'serialbench benchmark add-result' to add a result first", :white return end say "🏗️ Generating HTML site for result: #{result_path}", :green # Use the unified site generator for results Serialbench::SiteGenerator.generate_for_result(result, [:output_dir]) say '✅ HTML site generated successfully!', :green say "Site location: #{options[:output_dir]}", :cyan say "Open: #{File.join(options[:output_dir], 'index.html')}", :white rescue StandardError => e say "Error generating site: #{e.message}", :red say "Details: #{e.backtrace.first(3).join("\n")}", :red if [:verbose] exit 1 end |
#create(name = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/serialbench/cli/benchmark_cli.rb', line 31 def create(name = nil) raise 'Run name cannot be empty' if name&.strip&.empty? validate_name(name) config_dir = 'config/runs' FileUtils.mkdir_p(config_dir) benchmark_config_path = File.join(config_dir, "#{name}.yml") if File.exist?(benchmark_config_path) say "Configuration file already exists: #{benchmark_config_path}", :yellow return unless yes?('Overwrite existing file? (y/n)') end benchmark_config = Models::BenchmarkConfig.new( formats: [:formats], warmup: [:warmup], data_sizes: [:data_sizes] ) benchmark_config.to_file(benchmark_config_path) say "✅ Generated run configuration: #{benchmark_config_path}", :green say 'Edit the file to customize benchmark settings', :cyan end |
#execute(environment_config_path, benchmark_config_path) ⇒ Object
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 |
# File 'lib/serialbench/cli/benchmark_cli.rb', line 71 def execute(environment_config_path, benchmark_config_path) environment = load_environment_config(environment_config_path) config = load_benchmark_config(benchmark_config_path) say '🚀 Executing benchmark run', :green say "Environment: #{environment.name} (#{environment.kind})", :cyan say "Configuration: #{benchmark_config_path}", :cyan begin # Execute benchmark based on environment type case environment.kind when 'local' execute_local_benchmark(environment, config, benchmark_config_path) when 'docker' execute_docker_benchmark(environment, config, benchmark_config_path) when 'asdf' execute_asdf_benchmark(environment, config, benchmark_config_path) else raise "Unsupported environment type: #{environment.kind}" end rescue StandardError => e say "❌ Error executing benchmark run: #{e.message}", :red exit 1 end end |
#list ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/serialbench/cli/benchmark_cli.rb', line 211 def list store = Serialbench::Models::ResultStore.default runs = if [:tags] store.find_runs(tags: [:tags]) else store.find_runs end if runs.empty? say 'No runs found', :yellow return end say 'Available Runs:', :green say '=' * 50, :green runs.each do |run| say '📊 Run:', :cyan say " Created: #{run.metadata.created_at}", :white say " Platform: #{run.platform.platform_string} (os: #{run.platform.os}, arch: #{run.platform.arch})", :white say " Environment config: #{run.metadata.environment_config_path}", :white say " Benchmark config: #{run.metadata.benchmark_config_path}", :white say " Environment: #{run.environment_config.name} (#{run.environment_config.kind})", :white say " Tags: [#{run.metadata.tags.join(', ')}]", :white say '' end rescue StandardError => e say "Error listing runs: #{e.message}", :red exit 1 end |