gitlab-org--gitlab-foss/scripts/memory-static-objects
Aleksei Lipniagov c3b40ae131 Run static benchmarks from 'derailed_benchmarks'
Two static memory benchmarks will be included in our CI pipeline. It
will load gems from the Gemfile and check the amount of RAM consumed
as well as the number of objects allocated and retained.
Aggregated values will be included as 'metrics' into MRs while full
reports will be downloadable as job artifacts.
2019-06-19 12:16:44 +03:00

27 lines
1.2 KiB
Ruby
Executable file

#!/usr/bin/env ruby
require_relative '../lib/gitlab/popen'
full_report_filename, metrics_filename = ARGV
abort 'usage: memory-static-objects <full_report_filename> <metrics_filename>' unless full_report_filename && metrics_filename
full_report, status = Gitlab::Popen.popen(%w(bundle exec derailed bundle:objects))
abort 'failed to execute the benchmark' unless status.zero?
File.open(full_report_filename, 'w') do |f|
f.write(full_report)
end
allocated_str = full_report.lines[1]
retained_str = full_report.lines[2]
allocated_stats = /Total allocated: (?<bytes>.*) bytes \((?<objects>.*) objects\)/.match(allocated_str)
retained_stats = /Total retained: (?<bytes>.*) bytes \((?<objects>.*) objects\)/.match(retained_str)
abort 'failed to process the benchmark output' unless allocated_stats && retained_stats
File.open(metrics_filename, 'a') do |f|
f.puts "memory_static_objects_allocated_mb #{(allocated_stats[:bytes].to_f / (1024 * 1024)).round(1)}"
f.puts "memory_static_objects_retained_mb #{(retained_stats[:bytes].to_f / (104 * 1024)).round(1)}"
f.puts "memory_static_objects_allocated_items #{allocated_stats[:objects]}"
f.puts "memory_static_objects_retained_items #{retained_stats[:objects]}"
end