-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for vernier profile vieweing
Adds RemoteFirefoxViewer which uses the Firefox Profiler via middleware to serve profiles. - Fixes deprecation syntax - Fixes several warnings - Deprecates AppProfiler.viewer - Removes deprecard AppProfiler::Profile constant - Fixes directory structure to make files easier to find Co-authored-by: Gannon McGibbon <[email protected]>
- Loading branch information
Showing
30 changed files
with
610 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,6 @@ require: rubocop-performance | |
|
||
Style/StringLiterals: | ||
EnforcedStyle: double_quotes | ||
|
||
AllCops: | ||
SuggestExtensions: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
# frozen_string_literal: true | ||
|
||
gem "rails-html-sanitizer", ">= 1.6.0" | ||
require "rails-html-sanitizer" | ||
|
||
module AppProfiler | ||
module Viewer | ||
class BaseMiddleware | ||
class Sanitizer < Rails::HTML::Sanitizer.best_supported_vendor.safe_list_sanitizer | ||
self.allowed_tags = Set.new([ | ||
"strong", | ||
"em", | ||
"b", | ||
"i", | ||
"p", | ||
"code", | ||
"pre", | ||
"tt", | ||
"samp", | ||
"kbd", | ||
"var", | ||
"sub", | ||
"sup", | ||
"dfn", | ||
"cite", | ||
"big", | ||
"small", | ||
"address", | ||
"hr", | ||
"br", | ||
"div", | ||
"span", | ||
"h1", | ||
"h2", | ||
"h3", | ||
"h4", | ||
"h5", | ||
"h6", | ||
"ul", | ||
"ol", | ||
"li", | ||
"dl", | ||
"dt", | ||
"dd", | ||
"abbr", | ||
"acronym", | ||
"a", | ||
"img", | ||
"blockquote", | ||
"del", | ||
"ins", | ||
"script", | ||
]) | ||
end | ||
|
||
private_constant(:Sanitizer) | ||
|
||
class << self | ||
def id(file) | ||
file.basename.to_s | ||
end | ||
end | ||
|
||
def initialize(app) | ||
@app = app | ||
end | ||
|
||
def call(env) | ||
request = Rack::Request.new(env) | ||
|
||
return index(env) if %r(\A/app_profiler/?\z).match?(request.path_info) | ||
|
||
@app.call(env) | ||
end | ||
|
||
protected | ||
|
||
def id(file) | ||
self.class.id(file) | ||
end | ||
|
||
def profile_files | ||
AppProfiler.profile_root.glob("**/*.json") | ||
end | ||
|
||
def render(html) | ||
[ | ||
200, | ||
{ "Content-Type" => "text/html" }, | ||
[ | ||
+<<~HTML, | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>App Profiler</title> | ||
</head> | ||
<body> | ||
#{sanitizer.sanitize(html)} | ||
</body> | ||
</html> | ||
HTML | ||
], | ||
] | ||
end | ||
|
||
def sanitizer | ||
@sanitizer ||= Sanitizer.new | ||
end | ||
|
||
def viewer(_env, path) | ||
raise NotImplementedError | ||
end | ||
|
||
def show(env, id) | ||
raise NotImplementedError | ||
end | ||
|
||
def index(_env) | ||
render( | ||
(+"").tap do |content| | ||
content << "<h1>Profiles</h1>" | ||
profile_files.each do |file| | ||
viewer = if file.to_s.end_with?(AppProfiler::VernierProfile::FILE_EXTENSION) | ||
AppProfiler::Viewer::FirefoxRemoteViewer::NAME | ||
else | ||
AppProfiler::Viewer::SpeedscopeRemoteViewer::NAME | ||
end | ||
content << <<~HTML | ||
<p> | ||
<a href="/app_profiler/#{viewer}/viewer/#{id(file)}"> | ||
#{id(file)} | ||
</a> | ||
</p> | ||
HTML | ||
end | ||
end, | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.