Class: Serialbench::Models::Result

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/serialbench/models/result.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_all(base_path = 'results/runs') ⇒ Object



64
65
66
67
68
69
70
71
72
73
# File 'lib/serialbench/models/result.rb', line 64

def self.find_all(base_path = 'results/runs')
  return [] unless Dir.exist?(base_path)

  Dir.glob(File.join(base_path, '*')).select { |path| Dir.exist?(path) }.map do |path|
    load(path)
  rescue StandardError => e
    warn "Failed to load run result from #{path}: #{e.message}"
    nil
  end.compact
end

.load(path) ⇒ Object

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/serialbench/models/result.rb', line 41

def self.load(path)
  raise ArgumentError, "Path does not exist: #{path}" unless Dir.exist?(path)

  # Load benchmark data
  data_file = File.join(path, 'results.yaml')

  raise ArgumentError, "No results data found in #{path}" unless File.exist?(data_file)

  yaml_content = IO.read(data_file)

  # Debug: Check if yaml_content is empty or too small
  if yaml_content.nil? || yaml_content.strip.empty?
    raise ArgumentError, "Results file at #{data_file} is empty"
  end

  if yaml_content.bytesize < 200
    warn "WARNING: Results file at #{data_file} is suspiciously small (#{yaml_content.bytesize} bytes)"
    warn "Content preview: #{yaml_content[0..100]}"
  end

  from_yaml(yaml_content)
end

Instance Method Details

#to_file(path) ⇒ Object



75
76
77
# File 'lib/serialbench/models/result.rb', line 75

def to_file(path)
  File.write(path, to_yaml)
end