Skip to content

Commit 7b22aa1

Browse files
committed
Fix bugs
1 parent 871b50a commit 7b22aa1

9 files changed

Lines changed: 21 additions & 24 deletions

File tree

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ require: rubocop-performance
55

66
Style/StringLiterals:
77
EnforcedStyle: double_quotes
8+
9+
AllCops:
10+
SuggestExtensions: false

lib/app_profiler.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ def backend=(new_backend)
125125
end
126126

127127
def stackprof_viewer
128-
@@stackprof_viewer ||= Viewer::SpeedscopeViewer
128+
@@stackprof_viewer ||= Viewer::SpeedscopeViewer # rubocop:disable Style/ClassVars
129129
end
130130

131131
def vernier_viewer
132-
@@vernier_viewer ||= Viewer::FirefoxRemoteViewer
132+
@@vernier_viewer ||= Viewer::FirefoxRemoteViewer # rubocop:disable Style/ClassVars
133133
end
134134

135135
def profile_sampler_enabled=(value)

lib/app_profiler/railtie.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ class Railtie < Rails::Railtie
1111
AppProfiler.logger = app.config.app_profiler.logger || Rails.logger
1212
AppProfiler.root = app.config.app_profiler.root || Rails.root
1313
AppProfiler.storage = app.config.app_profiler.storage || Storage::FileStorage
14-
AppProfiler.stackprof_viewer = app.config.app_profiler.stackprof_viewer if app.config.app_profiler.stackprof_viewer
15-
AppProfiler.vernier_viewer = app.config.app_profiler.vernier_viewer if app.config.app_profiler.vernier_viewer
14+
if app.config.app_profiler.stackprof_viewer
15+
AppProfiler.stackprof_viewer = app.config.app_profiler.stackprof_viewer
16+
end
17+
if app.config.app_profiler.vernier_viewer
18+
AppProfiler.vernier_viewer = app.config.app_profiler.vernier_viewer
19+
end
1620
AppProfiler.storage.bucket_name = app.config.app_profiler.storage_bucket_name || "profiles"
1721
AppProfiler.storage.credentials = app.config.app_profiler.storage_credentials || {}
1822
AppProfiler.middleware = app.config.app_profiler.middleware || Middleware
@@ -50,7 +54,7 @@ class Railtie < Rails::Railtie
5054

5155
initializer "app_profiler.add_middleware" do |app|
5256
unless AppProfiler.middleware.disabled
53-
if Rails.env.development? || Rails.env.test? && AppProfiler.stackprof_viewer.remote?
57+
if (Rails.env.development? || Rails.env.test?) && AppProfiler.stackprof_viewer.remote?
5458
app.middleware.insert_before(0, AppProfiler.viewer::Middleware)
5559
end
5660
app.middleware.insert_before(0, AppProfiler.middleware)

lib/app_profiler/stackprof_profile.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module AppProfiler
44
class StackprofProfile < BaseProfile
5-
FILE_EXTENSION = ".json"
5+
FILE_EXTENSION = ".stackprof.json"
66

77
def mode
88
@data[:mode]

lib/app_profiler/vernier_profile.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module AppProfiler
44
class VernierProfile < BaseProfile
5-
FILE_EXTENSION = ".gecko.json"
5+
FILE_EXTENSION = ".vernier.json"
66

77
def mode
88
@data[:meta][:mode]

lib/app_profiler/viewer/firefox_remote_viewer/middleware.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ def initialize(app)
1818

1919
def call(env)
2020
request = Rack::Request.new(env)
21-
@app.call(env) if request.path_info.end_with?(AppProfiler::StackprofProfile::FILE_EXTENSION)
2221
# Firefox profiler *really* doesn't like for /from-url/ to be at any other mount point
2322
# so with this enabled, we take over both /app_profiler and /from-url in the app in development.
24-
return from(env, Regexp.last_match(1)) if request.path_info =~ %r(\A/from-url(.*)\z)
23+
return from(env, Regexp.last_match(1)) if request.path_info =~ %r(\A/from-url/(.*)\z)
2524
return viewer(env, Regexp.last_match(1)) if request.path_info =~ %r(\A/app_profiler/firefox/viewer/(.*)\z)
2625
return show(env, Regexp.last_match(1)) if request.path_info =~ %r(\A/app_profiler/firefox/(.*)\z)
2726

@@ -39,10 +38,9 @@ def viewer(env, path)
3938
proto = env["rack.url_scheme"]
4039
host = env["HTTP_HOST"]
4140
source = "#{proto}://#{host}/app_profiler/firefox/#{path}"
42-
4341
target = "/from-url/#{CGI.escape(source)}"
4442

45-
[302, { "Location" => target }, []]
43+
[302, { "Location" => target }, [""]]
4644
else
4745
env[Rack::PATH_INFO] = path.delete_prefix("/app_profiler")
4846
firefox_profiler.call(env)

lib/app_profiler/viewer/speedscope_remote_viewer/middleware.rb

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def initialize(app)
1818

1919
def call(env)
2020
request = Rack::Request.new(env)
21-
@app.call(env) if request.path_info.end_with?(AppProfiler::VernierProfile::FILE_EXTENSION)
21+
2222
return viewer(env, Regexp.last_match(1)) if request.path_info =~ %r(\A/app_profiler/speedscope/viewer/(.*)\z)
2323
return show(env, Regexp.last_match(1)) if request.path_info =~ %r(\A/app_profiler/speedscope/(.*)\z)
2424

@@ -32,15 +32,8 @@ def call(env)
3232
def viewer(env, path)
3333
setup_yarn unless yarn_setup
3434

35-
if path.end_with?(AppProfiler::StackprofProfile::FILE_EXTENSION)
36-
source = "/app_profiler/speedscope/#{path}"
37-
target = "/app_profiler/speedscope/viewer/index.html#profileURL=#{CGI.escape(source)}"
38-
39-
[302, { "Location" => target }, []]
40-
else
41-
env[Rack::PATH_INFO] = path.delete_prefix("/app_profiler/speedscope")
42-
speedscope.call(env)
43-
end
35+
env[Rack::PATH_INFO] = path.delete_prefix("/app_profiler/speedscope")
36+
speedscope.call(env)
4437
end
4538

4639
def show(_env, name)

lib/app_profiler/yarn/with_firefox_profiler.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ def firefox_profiler_added?
2222
end
2323

2424
def fetch_firefox_profiler
25-
raise ArgumentError unless PACKAGE.start_with?("https://github.com")
26-
2725
repo, branch = PACKAGE.to_s.split("#")
2826

2927
dir = "./tmp"

test/app_profiler/viewer/remote/middleware/firefox_middleware_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ class MiddlewareTest < TestCase
6868
@app.expects(:system).with("which", "yarn", out: File::NULL).returns(true)
6969
@app.expects(:system).with("yarn", "init", "--yes").returns(true)
7070

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

7475
File.expects(:read).returns("{}")

0 commit comments

Comments
 (0)