diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/diagnostic-reports-uploader | 29 | ||||
-rwxr-xr-x | bin/profile-url | 22 | ||||
-rwxr-xr-x | bin/rubocop-profile | 39 |
3 files changed, 77 insertions, 13 deletions
diff --git a/bin/diagnostic-reports-uploader b/bin/diagnostic-reports-uploader new file mode 100755 index 00000000000..a19fe15dcb9 --- /dev/null +++ b/bin/diagnostic-reports-uploader @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require 'fog/google' + +require_relative '../lib/gitlab/memory/reports_uploader' +require_relative '../lib/gitlab/memory/upload_and_cleanup_reports' +require_relative '../lib/gitlab/memory/diagnostic_reports_logger' + +# Fail fast if the necessary ENV vars are not set. +reports_path = ENV["GITLAB_DIAGNOSTIC_REPORTS_PATH"].to_s +raise 'GITLAB_DIAGNOSTIC_REPORTS_PATH dir is missing' unless Dir.exist?(reports_path) + +gcs_key = ENV["GITLAB_GCP_KEY_PATH"].to_s +raise "GCS keyfile not found: #{gcs_key}" unless File.exist?(gcs_key) + +gcs_project = ENV["GITLAB_DIAGNOSTIC_REPORTS_PROJECT"].to_s +raise 'GITLAB_DIAGNOSTIC_REPORTS_PROJECT is missing' unless gcs_project && !gcs_project.empty? + +gcs_bucket = ENV["GITLAB_DIAGNOSTIC_REPORTS_BUCKET"].to_s +raise 'GITLAB_DIAGNOSTIC_REPORTS_BUCKET is missing' unless gcs_bucket && !gcs_bucket.empty? + +rails_root = File.expand_path("..", __dir__) +log_file = File.expand_path('log/diagnostic_reports_json.log', rails_root) +logger = Gitlab::Memory::DiagnosticReportsLogger.new(log_file) + +uploader = Gitlab::Memory::ReportsUploader.new(gcs_key: gcs_key, gcs_project: gcs_project, gcs_bucket: gcs_bucket, + logger: logger) +Gitlab::Memory::UploadAndCleanupReports.new(uploader: uploader, reports_path: reports_path, logger: logger).call diff --git a/bin/profile-url b/bin/profile-url index 9e8585aabba..6047cb70b8d 100755 --- a/bin/profile-url +++ b/bin/profile-url @@ -8,15 +8,15 @@ opt_parser = OptionParser.new do |opt| Profile a URL on this GitLab instance. Usage: - #{__FILE__} url --output=<profile-html> --sql=<sql-log> [--user=<user>] [--post=<post-data>] + #{__FILE__} url --output=<profile-dump> --sql=<sql-log> [--user=<user>] [--post=<post-data>] Example: - #{__FILE__} /dashboard/issues --output=dashboard-profile.html --sql=dashboard.log --user=root + #{__FILE__} /dashboard/issues --output=dashboard-profile.dump --sql=dashboard.log --user=root DOCSTRING opt.separator '' opt.separator 'Options:' - opt.on('-o', '--output=/tmp/profile.html', 'profile output filename') do |output| + opt.on('-o', '--output=/tmp/profile.dump', 'profile output filename') do |output| options[:profile_output] = output end @@ -45,13 +45,9 @@ end require File.expand_path('../config/environment', File.dirname(__FILE__)) -result = Gitlab::Profiler.profile(options[:url], - logger: Logger.new(options[:sql_output]), - post_data: options[:post_data], - user: UserFinder.new(options[:username]).find_by_username, - private_token: ENV['PRIVATE_TOKEN']) - -printer = RubyProf::CallStackPrinter.new(result) -file = File.open(options[:profile_output], 'w') -printer.print(file) -file.close +Gitlab::Profiler.profile(options[:url], + logger: Logger.new(options[:sql_output]), + post_data: options[:post_data], + user: UserFinder.new(options[:username]).find_by_username, + private_token: ENV['PRIVATE_TOKEN'], + profiler_options: { out: options[:profile_output] }) diff --git a/bin/rubocop-profile b/bin/rubocop-profile new file mode 100755 index 00000000000..d1e31edbeed --- /dev/null +++ b/bin/rubocop-profile @@ -0,0 +1,39 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# Profile bundled RuboCop version. +# +# See https://github.com/rubocop/rubocop/blob/master/bin/rubocop-profile + +if ARGV.include?('-h') || ARGV.include?('--help') + puts "Usage: same as main `rubocop` command but gathers profiling info" + puts "Additional option: `--memory` to print memory usage" + exit(0) +end +with_mem = ARGV.delete('--memory') +ARGV.unshift '--cache', 'false' unless ARGV.include?('--cache') + +require 'stackprof' +if with_mem + require 'memory_profiler' + MemoryProfiler.start +end +StackProf.start +start = Process.clock_gettime(Process::CLOCK_MONOTONIC) +begin + require 'rubocop' + + exit RuboCop::CLI.new.run +ensure + delta = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start + puts "Finished in #{delta.round(1)} seconds" + StackProf.stop + if with_mem + puts "Building memory report..." + report = MemoryProfiler.stop + end + Dir.mkdir('tmp') unless File.exist?('tmp') + StackProf.results('tmp/stackprof.dump') + report&.pretty_print(scale_bytes: true) + puts "StackProf written to `tmp/stackprof.dump`." +end |