diff --git a/sorbet/rbi/shims/flamegraph.rbi b/sorbet/rbi/shims/flamegraph.rbi new file mode 100644 index 00000000000..94601a852f4 --- /dev/null +++ b/sorbet/rbi/shims/flamegraph.rbi @@ -0,0 +1,7 @@ +# typed: strong +# frozen_string_literal: true + +class Flamegraph + sig { params(path: String).void } + def generate(path); end +end diff --git a/updater/Gemfile b/updater/Gemfile index 7b12e05d852..d353845a8c8 100644 --- a/updater/Gemfile +++ b/updater/Gemfile @@ -35,6 +35,9 @@ gem "sentry-opentelemetry", "~> 5.16" gem "sentry-ruby", "~> 5.16" gem "terminal-table", "~> 3.0.2" +gem "flamegraph", "~> 0.9.5" +gem "stackprof", "~> 0.2.16" + group :test do common_gemspec = File.expand_path("../common/dependabot-common.gemspec", __dir__) diff --git a/updater/Gemfile.lock b/updater/Gemfile.lock index a0b75e2c4e0..3733b21a0c4 100644 --- a/updater/Gemfile.lock +++ b/updater/Gemfile.lock @@ -184,6 +184,7 @@ GEM ffi-compiler (1.0.1) ffi (>= 1.0.0) rake + flamegraph (0.9.5) gitlab (4.19.0) httparty (~> 0.20) terminal-table (>= 1.5.1) @@ -387,6 +388,7 @@ DEPENDENCIES dependabot-silent! dependabot-swift! dependabot-terraform! + flamegraph (~> 0.9.5) gpgme (~> 2.0) http (~> 5.1) octokit (= 6.1.1) diff --git a/updater/bin/update_files.rb b/updater/bin/update_files.rb index 1e952609017..a055b598a5c 100644 --- a/updater/bin/update_files.rb +++ b/updater/bin/update_files.rb @@ -12,6 +12,12 @@ require "dependabot/update_files_command" require "debug" if ENV["DEBUG"] +flamegraph = ENV.fetch("FLAMEGRAPH", nil) +if flamegraph + require "stackprof" + require "flamegraph" +end + class UpdaterKilledError < StandardError; end trap("TERM") do @@ -30,7 +36,13 @@ class UpdaterKilledError < StandardError; end end begin - Dependabot::UpdateFilesCommand.new.run + if flamegraph + Flamegraph.generate("/tmp/dependabot-flamegraph.html") do + Dependabot::UpdateFilesCommand.new.run + end + else + Dependabot::UpdateFilesCommand.new.run + end rescue Dependabot::RunFailure exit 1 end