Welcome to mirror list, hosted at ThFree Co, Russian Federation.

memory_usage_helper.rb « helpers « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: aa7b3bae83a976e794cce9f4df9f49e22d1ca1df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# frozen_string_literal: true

module MemoryUsageHelper
  extend ActiveSupport::Concern

  def gather_memory_data(csv_path)
    write_csv_entry(csv_path,
      {
        example_group_path: TestEnv.topmost_example_group[:location],
        example_group_description: TestEnv.topmost_example_group[:description],
        time: Time.current,
        job_name: ENV['CI_JOB_NAME']
      }.merge(get_memory_usage))
  end

  def write_csv_entry(path, entry)
    CSV.open(path, "a", headers: entry.keys, write_headers: !File.exist?(path)) do |file|
      file << entry.values
    end
  end

  def get_memory_usage
    output, status = Gitlab::Popen.popen(%w(free -m))
    abort "`free -m` return code is #{status}: #{output}" unless status == 0

    result = output.split("\n")[1].split(" ")[1..-1]
    attrs = %i(m_total m_used m_free m_shared m_buffers_cache m_available).freeze

    attrs.zip(result).to_h
  end

  included do |config|
    config.after(:all) do
      gather_memory_data(ENV['MEMORY_TEST_PATH']) if ENV['MEMORY_TEST_PATH']
    end
  end
end