Class: Serialbench::Cli::ResultsetCli

Inherits:
BaseCli
  • Object
show all
Defined in:
lib/serialbench/cli/resultset_cli.rb

Overview

CLI for managing benchmark resultsets (collections of runs)

Instance Method Summary collapse

Methods inherited from BaseCli

exit_on_failure?

Instance Method Details

#add_result(resultset_path, *result_paths) ⇒ Object



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
125
126
127
128
129
130
# File 'lib/serialbench/cli/resultset_cli.rb', line 70

def add_result(resultset_path, *result_paths)
  if result_paths.empty?
    say '❌ Error: At least one result path must be provided', :red
    exit 1
  end

  resultset = Serialbench::Models::ResultSet.load(resultset_path)

  say "📦 Adding #{result_paths.size} result(s) to resultset", :cyan
  say "ResultSet: #{resultset_path}", :white
  say ''

  added_count = 0
  failed_count = 0
  skipped_count = 0

  result_paths.each_with_index do |result_path, index|
    say "#{index + 1}/#{result_paths.size} Processing: #{result_path}", :cyan

    # Find results.yaml in the path or subdirectories
    results_file = if File.exist?(File.join(result_path, 'results.yaml'))
                     File.join(result_path, 'results.yaml')
                   else
                     Dir.glob(File.join(result_path, '**/results.yaml')).first
                   end

    unless results_file
      say '  ⚠️  No results.yaml found - skipping', :yellow
      skipped_count += 1
      next
    end

    result_dir = File.dirname(results_file)

    begin
      resultset.add_result(result_dir)
      say '  ✅ Added successfully', :green
      added_count += 1
    rescue StandardError => e
      say "  ❌ Failed: #{e.message}", :red
      failed_count += 1
    end
    say ''
  end

  resultset.save(resultset_path)

  say '=' * 60, :cyan
  say 'Summary:', :green
  say "  Total processed: #{result_paths.size}", :white
  say "  ✅ Successfully added: #{added_count}", :green
  say "  ❌ Failed: #{failed_count}", :red if failed_count > 0
  say "  ⚠️  Skipped: #{skipped_count}", :yellow if skipped_count > 0
  say "  📊 Total results in set: #{resultset.results.count}", :cyan
  say '=' * 60, :cyan

  exit 1 if failed_count > 0 && added_count == 0
rescue StandardError => e
  say "❌ Error: #{e.message}", :red
  exit 1
end

#build_site(resultset_path, output_dir = '_site') ⇒ Object



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/serialbench/cli/resultset_cli.rb', line 186

def build_site(resultset_path, output_dir = '_site')
  unless Dir.exist?(resultset_path)
    say "ResultSet directory not found: #{resultset_path}", :red
    say "Please create a resultset first using 'serialbench resultset create'", :white
    exit 1
  end

  resultset = Serialbench::Models::ResultSet.load(resultset_path)

  if resultset.results.empty?
    say "ResultSet '#{resultset_path}' contains no runs", :yellow
    say "Use 'serialbench resultset add-result' to add runs first", :white
    return
  end

  say "🏗️  Generating HTML site for resultset: #{resultset_path}", :green
  say "Runs in set: #{resultset.results.size}", :cyan

  # Use the unified site generator for resultsets
  Serialbench::SiteGenerator.generate_for_resultset(resultset, output_dir)

  say '✅ HTML site generated successfully!', :green
  say "Site location: #{output_dir}", :cyan
  say "Open: #{File.join(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 options[:verbose]
  exit 1
end

#create(resultset_name, resultset_path) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/serialbench/cli/resultset_cli.rb', line 22

def create(resultset_name, resultset_path)
  Serialbench::Models::ResultStore.default

  # Check if resultset already exists
  definition_path = File.join(resultset_path, 'resultset.yaml')

  if File.exist?(definition_path)
    say "ResultSet at '#{resultset_path}' already exists", :yellow
    return unless yes?('Create anyway with timestamp suffix? (y/n)')

    resultset_path = "#{resultset_path}-#{generate_timestamp}"
  end

  # Create empty resultset using the new ResultSet model
  resultset = Serialbench::Models::ResultSet.new(
    name: resultset_name,
    description: "ResultSet for #{resultset_name} benchmarks",
    created_at: Time.now.utc.iso8601,
    updated_at: Time.now.utc.iso8601
  )
  resultset.save(resultset_path)

  say "✅ Created resultset: #{resultset_path}", :green
  say "Path: #{definition_path}", :cyan
  say "Use 'serialbench resultset add-result' to add benchmark runs", :white
rescue StandardError => e
  say "Error creating resultset: #{e.message}", :red
  exit 1
end

#listObject



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/serialbench/cli/resultset_cli.rb', line 222

def list
  ensure_results_directory

  begin
    store = Serialbench::Models::ResultStore.default
    resultsets = store.find_resultsets

    if resultsets.empty?
      say 'No resultsets found', :yellow
      say "Use 'serialbench resultset create' to create a resultset", :white
      return
    end

    say 'Available ResultSets:', :green
    say '=' * 50, :green

    resultsets.each do |resultset|
      say "📁 #{resultset.name}", :cyan
      say "   Runs: #{resultset.runs.length}", :white
      say "   Created: #{resultset.metadata[:timestamp]}", :white
      say "   Path: #{resultset.directory}", :white

      if resultset.runs.any?
        say '   Contains:', :white
        resultset.runs.first(3).each do |run_info|
          say "     - #{run_info[:name]}", :white
        end
        say "     ... and #{resultset.runs.length - 3} more" if resultset.runs.length > 3
      end

      say ''
    end
  rescue StandardError => e
    say "Error listing resultsets: #{e.message}", :red
    exit 1
  end
end

#remove_result(resultset_path, _result_path) ⇒ Object



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
172
173
# File 'lib/serialbench/cli/resultset_cli.rb', line 143

def remove_result(resultset_path, _result_path)
  Serialbench::Models::ResultStore.default

  # Find the resultset
  resultset = Serialbench::Models::ResultSet.load(resultset_path)
  if resultset.nil?
    say "ResultSet '#{resultset_path}' not found", :red
    exit 1
  end

  # Remove run from resultset
  removed = resultset.remove_run(run_identifier)
  unless removed
    say "Run '#{run_identifier}' not found in resultset", :yellow
    say 'Available runs in resultset:', :white
    resultset.runs.each do |run_info|
      say "  - #{run_info[:name]}", :white
    end
    return
  end

  resultset.save

  say '✅ Removed run from resultset', :green
  say "Run: #{run_identifier}", :cyan
  say "ResultSet: #{resultset_path}", :cyan
  say "Remaining runs in set: #{resultset.runs.length}", :white
rescue StandardError => e
  say "Error removing run from resultset: #{e.message}", :red
  exit 1
end