From 97ca3a3bf40ca33e6a8abf298c0422a554121285 Mon Sep 17 00:00:00 2001 From: Jake Coffman Date: Wed, 3 Apr 2024 09:23:05 -0500 Subject: [PATCH 1/3] allow flamegraph gathering by the CLI --- updater/Gemfile | 3 +++ updater/Gemfile.lock | 2 ++ updater/bin/update_files.rb | 14 +++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/updater/Gemfile b/updater/Gemfile index 7b12e05d852..3b61f6ffc81 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 "stackprof", "~> 0.2.16" +gem "flamegraph", "~> 0.9.5" + 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..68746d09f09 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["FLAMEGRAPH"] +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 From e756857d3aa24fd1577e20c796f33d0b776f56a6 Mon Sep 17 00:00:00 2001 From: Jake Coffman Date: Wed, 3 Apr 2024 09:54:45 -0500 Subject: [PATCH 2/3] types --- sorbet/rbi/shims/flamegraph.rbi | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 sorbet/rbi/shims/flamegraph.rbi 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 From 84f85cc15b125d699fe65b815441cce03e8bb29a Mon Sep 17 00:00:00 2001 From: Jake Coffman Date: Wed, 3 Apr 2024 09:57:26 -0500 Subject: [PATCH 3/3] lint --- updater/Gemfile | 2 +- updater/bin/update_files.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/updater/Gemfile b/updater/Gemfile index 3b61f6ffc81..d353845a8c8 100644 --- a/updater/Gemfile +++ b/updater/Gemfile @@ -35,8 +35,8 @@ gem "sentry-opentelemetry", "~> 5.16" gem "sentry-ruby", "~> 5.16" gem "terminal-table", "~> 3.0.2" -gem "stackprof", "~> 0.2.16" 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/bin/update_files.rb b/updater/bin/update_files.rb index 68746d09f09..a055b598a5c 100644 --- a/updater/bin/update_files.rb +++ b/updater/bin/update_files.rb @@ -12,7 +12,7 @@ require "dependabot/update_files_command" require "debug" if ENV["DEBUG"] -flamegraph = ENV["FLAMEGRAPH"] +flamegraph = ENV.fetch("FLAMEGRAPH", nil) if flamegraph require "stackprof" require "flamegraph" @@ -37,7 +37,7 @@ class UpdaterKilledError < StandardError; end begin if flamegraph - Flamegraph.generate('/tmp/dependabot-flamegraph.html') do + Flamegraph.generate("/tmp/dependabot-flamegraph.html") do Dependabot::UpdateFilesCommand.new.run end else