-
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.
Adds local firefox viewer and mkes it the default for vernier viewing.
- Loading branch information
Showing
9 changed files
with
181 additions
and
54 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
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,37 @@ | ||
# frozen_string_literal: true | ||
|
||
module AppProfiler | ||
module Exec # :nodoc: | ||
protected | ||
|
||
def valid_commands | ||
raise NotImplementedError | ||
end | ||
|
||
def ensure_command_valid(command) | ||
unless valid_command?(command) | ||
raise ArgumentError, "Illegal command: #{command.join(" ")}." | ||
end | ||
end | ||
|
||
def valid_command?(command) | ||
valid_commands.any? do |valid_command| | ||
next unless valid_command.size == command.size | ||
|
||
valid_command.zip(command).all? do |valid_part, part| | ||
part.match?(valid_part) | ||
end | ||
end | ||
end | ||
|
||
def exec(*command, silent: false, environment: {}) | ||
ensure_command_valid(command) | ||
|
||
if silent | ||
system(environment, *command, out: File::NULL).tap { |return_code| yield unless return_code } | ||
else | ||
system(environment, *command).tap { |return_code| yield unless return_code } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# frozen_string_literal: true | ||
|
||
require "app_profiler/exec" | ||
|
||
module AppProfiler | ||
module Viewer | ||
class FirefoxViewer < BaseViewer | ||
include Exec | ||
|
||
CHILD_PIDS = [] | ||
|
||
at_exit { Process.wait if CHILD_PIDS.any? } | ||
|
||
trap("INT") do | ||
CHILD_PIDS.each { |pid| Process.kill("INT", pid) } | ||
sleep(0.5) | ||
end | ||
|
||
class ProfileViewerError < StandardError; end | ||
|
||
VALID_COMMANDS = [ | ||
["which", "profile-viewer"], | ||
["gem", "install", "profile-viewer"], | ||
["profile-viewer", /.*\.json/], | ||
] | ||
private_constant(:VALID_COMMANDS) | ||
|
||
class << self | ||
def view(profile, params = {}) | ||
new(profile).view(**params) | ||
end | ||
end | ||
|
||
def valid_commands | ||
VALID_COMMANDS | ||
end | ||
|
||
def initialize(profile) | ||
super() | ||
@profile = profile | ||
end | ||
|
||
def view(_params = {}) | ||
profile_viewer(@profile.file.to_s) | ||
end | ||
|
||
private | ||
|
||
def setup_profile_viewer | ||
exec("which", "profile-viewer", silent: true) do | ||
gem_install("profile_viewer") | ||
end | ||
@profile_viewer_initialized = true | ||
end | ||
|
||
def profile_viewer_setup | ||
@profile_viewer_initialized || false | ||
end | ||
|
||
def gem_install(gem) | ||
exec("gem", "install", gem) do | ||
raise ProfileViewerError, "Failed to run gem install #{gem}." | ||
end | ||
end | ||
|
||
def profile_viewer(path) | ||
setup_profile_viewer unless profile_viewer_setup | ||
|
||
CHILD_PIDS << fork do | ||
Bundler.with_unbundled_env do | ||
exec("profile-viewer", path) do | ||
raise ProfileViewerError, "Failed to run profile-viewer." | ||
end | ||
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
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