2019-03-12 05:51:37 -04:00
|
|
|
#!/usr/bin/env ruby
|
2021-02-12 07:09:02 -05:00
|
|
|
# frozen_string_literal: true
|
2019-03-12 05:51:37 -04:00
|
|
|
|
|
|
|
require 'csv'
|
|
|
|
require 'rspec_profiling'
|
|
|
|
require 'postgres-copy'
|
|
|
|
|
|
|
|
module RspecProfiling
|
|
|
|
module Collectors
|
|
|
|
class PSQL
|
|
|
|
def establish_connection
|
|
|
|
# This disables the automatic creation of the database and
|
|
|
|
# table. In the future, we may want a way to specify the host of
|
|
|
|
# the database to connect so that we can call #install.
|
|
|
|
Result.establish_connection(results_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
def results_url
|
|
|
|
ENV['RSPEC_PROFILING_POSTGRES_URL']
|
|
|
|
end
|
|
|
|
|
2019-03-29 07:23:05 -04:00
|
|
|
class Result < ActiveRecord::Base # rubocop:disable Rails/ApplicationRecord
|
2019-03-12 05:51:37 -04:00
|
|
|
acts_as_copy_target
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def insert_data(path)
|
|
|
|
puts "#{Time.now} Inserting CI stats..."
|
|
|
|
|
|
|
|
collector = RspecProfiling::Collectors::PSQL.new
|
|
|
|
collector.install
|
|
|
|
|
|
|
|
files = Dir[File.join(path, "*.csv")]
|
|
|
|
|
|
|
|
files.each do |filename|
|
|
|
|
puts "#{Time.now} Inserting #{filename}..."
|
2019-12-22 01:07:52 -05:00
|
|
|
# Strip file of NULL bytes to ensure data gets inserted
|
|
|
|
system("sed", "-i", "-e", "s/\\x00//g", filename)
|
2019-03-12 05:51:37 -04:00
|
|
|
result = RspecProfiling::Collectors::PSQL::Result.copy_from(filename)
|
|
|
|
puts "#{Time.now} Inserted #{result.cmd_tuples} lines in #{filename}, DB response: #{result.cmd_status}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
insert_data('rspec_profiling') if ENV['RSPEC_PROFILING_POSTGRES_URL'].present?
|