gitlab-org--gitlab-foss/scripts/generate-gems-size-metrics-static
Qingyu Zhao 940fcc9ff2 Generate gem size metrics in memory CI
This includes several changes:
  - Rename memory-static to generate-gems-size-metrics-static
  - Rename memory-static-objects to generate-gems-memory-metrics-static
  - Change generate-gems-size-metrics-static interface. The script now
    expect `bundle exec derailed bundle:mem` output as its input. The
    script output to stdout, or stderr for error message.
  - Change generate-gems-memory-metrics-static interface. The script now
    expect `bundle exec derailed bundle:objects` output as its input.
    The script output to stdout, or stderr for error message.
  - Generate gem size metrics. Script generate-gems-size-metrics-static
    extract each gem size from `bundle exec derailed bundle:mem` output.
    Save output to metrics file in format: 'gem_size_mb{name="zip"} 0.5'
2019-06-21 20:05:59 +10:00

30 lines
982 B
Ruby
Executable file

#!/usr/bin/env ruby
abort "usage: #{__FILE__} <memory_bundle_mem_file_name>" unless ARGV.length == 1
memory_bundle_mem_file_name = ARGV.first
full_report = File.readlines(memory_bundle_mem_file_name)
def total_size(memory_bundle_mem_report)
stats = /TOP: (?<total_mibs_str>.*) MiB/.match(memory_bundle_mem_report.first)
abort 'failed to process the benchmark output' unless stats
"gem_total_size_mb #{stats[:total_mibs_str].to_f.round(1)}"
end
TOP_LEVEL_GEM_LOG_FORMAT = /^ (?<gem_name>\S.*):\s*(?<gem_size>\d[.\d]*)\s*MiB/.freeze
def all_gems(memory_bundle_mem_report)
memory_bundle_mem_report.map do |line|
TOP_LEVEL_GEM_LOG_FORMAT.match(line)
end.compact
end
def gems_as_metrics(gems_match_data)
gems_match_data.map do |gem|
gem_name = gem[:gem_name]
gem_size_mb = gem[:gem_size].to_f.round(1)
"gem_size_mb{name=\"#{gem_name}\"} #{gem_size_mb}"
end
end
puts total_size(full_report)
puts gems_as_metrics(all_gems(full_report)).sort(&:casecmp)