Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
gmcgibbon committed Oct 29, 2024
1 parent 871b50a commit e01c7d9
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ require: rubocop-performance

Style/StringLiterals:
EnforcedStyle: double_quotes

AllCops:
SuggestExtensions: false
4 changes: 2 additions & 2 deletions lib/app_profiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ def backend=(new_backend)
end

def stackprof_viewer
@@stackprof_viewer ||= Viewer::SpeedscopeViewer
@@stackprof_viewer ||= Viewer::SpeedscopeViewer # rubocop:disable Style/ClassVars
end

def vernier_viewer
@@vernier_viewer ||= Viewer::FirefoxRemoteViewer
@@vernier_viewer ||= Viewer::FirefoxRemoteViewer # rubocop:disable Style/ClassVars
end

def profile_sampler_enabled=(value)
Expand Down
10 changes: 7 additions & 3 deletions lib/app_profiler/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ class Railtie < Rails::Railtie
AppProfiler.logger = app.config.app_profiler.logger || Rails.logger
AppProfiler.root = app.config.app_profiler.root || Rails.root
AppProfiler.storage = app.config.app_profiler.storage || Storage::FileStorage
AppProfiler.stackprof_viewer = app.config.app_profiler.stackprof_viewer if app.config.app_profiler.stackprof_viewer
AppProfiler.vernier_viewer = app.config.app_profiler.vernier_viewer if app.config.app_profiler.vernier_viewer
if app.config.app_profiler.stackprof_viewer
AppProfiler.stackprof_viewer = app.config.app_profiler.stackprof_viewer
end
if app.config.app_profiler.vernier_viewer
AppProfiler.vernier_viewer = app.config.app_profiler.vernier_viewer
end
AppProfiler.storage.bucket_name = app.config.app_profiler.storage_bucket_name || "profiles"
AppProfiler.storage.credentials = app.config.app_profiler.storage_credentials || {}
AppProfiler.middleware = app.config.app_profiler.middleware || Middleware
Expand Down Expand Up @@ -50,7 +54,7 @@ class Railtie < Rails::Railtie

initializer "app_profiler.add_middleware" do |app|
unless AppProfiler.middleware.disabled
if Rails.env.development? || Rails.env.test? && AppProfiler.stackprof_viewer.remote?
if (Rails.env.development? || Rails.env.test?) && AppProfiler.stackprof_viewer.remote?
app.middleware.insert_before(0, AppProfiler.viewer::Middleware)
end
app.middleware.insert_before(0, AppProfiler.middleware)
Expand Down
2 changes: 1 addition & 1 deletion lib/app_profiler/stackprof_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module AppProfiler
class StackprofProfile < BaseProfile
FILE_EXTENSION = ".json"
FILE_EXTENSION = ".stackprof.json"

def mode
@data[:mode]
Expand Down
2 changes: 1 addition & 1 deletion lib/app_profiler/vernier_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module AppProfiler
class VernierProfile < BaseProfile
FILE_EXTENSION = ".gecko.json"
FILE_EXTENSION = ".vernier.json"

def mode
@data[:meta][:mode]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize(app)

def call(env)
request = Rack::Request.new(env)
@app.call(env) if request.path_info.end_with?(AppProfiler::StackprofProfile::FILE_EXTENSION)
@app.call(env) unless request.path_info.end_with?(AppProfiler::VernierProfile::FILE_EXTENSION)
# Firefox profiler *really* doesn't like for /from-url/ to be at any other mount point
# so with this enabled, we take over both /app_profiler and /from-url in the app in development.
return from(env, Regexp.last_match(1)) if request.path_info =~ %r(\A/from-url(.*)\z)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize(app)

def call(env)
request = Rack::Request.new(env)
@app.call(env) if request.path_info.end_with?(AppProfiler::VernierProfile::FILE_EXTENSION)
@app.call(env) unless request.path_info.end_with?(AppProfiler::StackprofProfile::FILE_EXTENSION)
return viewer(env, Regexp.last_match(1)) if request.path_info =~ %r(\A/app_profiler/speedscope/viewer/(.*)\z)
return show(env, Regexp.last_match(1)) if request.path_info =~ %r(\A/app_profiler/speedscope/(.*)\z)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class MiddlewareTest < TestCase
@app.expects(:system).with("which", "yarn", out: File::NULL).returns(true)
@app.expects(:system).with("yarn", "init", "--yes").returns(true)

url, branch = "https://github.com/tenderlove/profiler", "v0.0.2"
url = "https://github.com/tenderlove/profiler"
branch = "v0.0.2"
@app.expects(:system).with("git", "clone", url, "firefox-profiler", "--branch=#{branch}").returns(true)

File.expects(:read).returns("{}")
Expand Down

0 comments on commit e01c7d9

Please sign in to comment.