app_profiler 0.0.3 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/app_profiler.rb +15 -1
- data/lib/app_profiler/middleware/upload_action.rb +5 -1
- data/lib/app_profiler/profile.rb +3 -0
- data/lib/app_profiler/profiler.rb +16 -16
- data/lib/app_profiler/railtie.rb +1 -0
- data/lib/app_profiler/storage/file_storage.rb +4 -0
- data/lib/app_profiler/version.rb +1 -1
- data/lib/app_profiler/viewer/speedscope_viewer.rb +9 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4342f9415d422d77b172d358f968f9bc6c0ae670364e2ed351c7d1daf7cfcd3f
|
4
|
+
data.tar.gz: 4868b701483cc23fef7dad0432437afe61a65ff4ff5bcd752eec37636f4eeddb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab3d7f1677cc9f3a645ca23cf5fc2b3125cd498cbaace7640e31aad8b45e8f9c23bda135bf470b105e723cafeb1c0456149618c3268cc9ea5674fe2427b00fe0
|
7
|
+
data.tar.gz: 12189f7de4e869d34939d9c3cdbeeb94d257de0f31c232f2deff2011a879fadc8aaccfde44f9780eec6bd863375f9a098f3c571ed53bc65c9e9825f83be6d96a
|
data/lib/app_profiler.rb
CHANGED
@@ -24,7 +24,7 @@ module AppProfiler
|
|
24
24
|
autoload :Profiler, "app_profiler/profiler"
|
25
25
|
autoload :Profile, "app_profiler/profile"
|
26
26
|
|
27
|
-
mattr_accessor :logger
|
27
|
+
mattr_accessor :logger, default: Logger.new($stdout)
|
28
28
|
mattr_accessor :root
|
29
29
|
mattr_accessor :profile_root
|
30
30
|
|
@@ -32,6 +32,7 @@ module AppProfiler
|
|
32
32
|
mattr_accessor :autoredirect, default: false
|
33
33
|
mattr_reader :profile_header, default: "X-Profile"
|
34
34
|
mattr_accessor :context, default: nil
|
35
|
+
mattr_reader :profile_url_formatter, default: nil
|
35
36
|
|
36
37
|
mattr_accessor :storage, default: Storage::FileStorage
|
37
38
|
mattr_accessor :viewer, default: Viewer::SpeedscopeViewer
|
@@ -42,6 +43,15 @@ module AppProfiler
|
|
42
43
|
Profiler.run(*args, &block)
|
43
44
|
end
|
44
45
|
|
46
|
+
def start(*args)
|
47
|
+
Profiler.start(*args)
|
48
|
+
end
|
49
|
+
|
50
|
+
def stop
|
51
|
+
Profiler.stop
|
52
|
+
Profiler.results
|
53
|
+
end
|
54
|
+
|
45
55
|
def profile_header=(profile_header)
|
46
56
|
@@profile_header = profile_header # rubocop:disable Style/ClassVars
|
47
57
|
@@request_profile_header = nil # rubocop:disable Style/ClassVars
|
@@ -57,5 +67,9 @@ module AppProfiler
|
|
57
67
|
def profile_data_header
|
58
68
|
@@profile_data_header ||= profile_header.dup << "-Data" # rubocop:disable Style/ClassVars
|
59
69
|
end
|
70
|
+
|
71
|
+
def profile_url_formatter=(block)
|
72
|
+
@@profile_url_formatter = block # rubocop:disable Style/ClassVars
|
73
|
+
end
|
60
74
|
end
|
61
75
|
end
|
@@ -34,7 +34,11 @@ module AppProfiler
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def profile_url(upload)
|
37
|
-
|
37
|
+
if AppProfiler.profile_url_formatter.nil?
|
38
|
+
"#{AppProfiler.speedscope_host}#profileURL=#{upload.url}"
|
39
|
+
else
|
40
|
+
AppProfiler.profile_url_formatter.call(upload)
|
41
|
+
end
|
38
42
|
end
|
39
43
|
|
40
44
|
def profile_data_url(upload)
|
data/lib/app_profiler/profile.rb
CHANGED
@@ -4,6 +4,7 @@ module AppProfiler
|
|
4
4
|
class Profile
|
5
5
|
INTERNAL_METADATA_KEYS = %i(id context)
|
6
6
|
private_constant :INTERNAL_METADATA_KEYS
|
7
|
+
class UnsafeFilename < StandardError; end
|
7
8
|
|
8
9
|
delegate :[], to: :@data
|
9
10
|
attr_reader :id, :context
|
@@ -70,6 +71,8 @@ module AppProfiler
|
|
70
71
|
Socket.gethostname,
|
71
72
|
].compact.join("-") << ".json"
|
72
73
|
|
74
|
+
raise UnsafeFilename if /[^0-9A-Za-z.\-\_]/.match(filename)
|
75
|
+
|
73
76
|
AppProfiler.profile_root.join(filename)
|
74
77
|
end
|
75
78
|
end
|
@@ -24,28 +24,13 @@ module AppProfiler
|
|
24
24
|
stop if started
|
25
25
|
end
|
26
26
|
|
27
|
-
def results
|
28
|
-
stackprof_profile = stackprof_results
|
29
|
-
|
30
|
-
return unless stackprof_profile
|
31
|
-
|
32
|
-
Profile.from_stackprof(stackprof_profile)
|
33
|
-
rescue => error
|
34
|
-
AppProfiler.logger.info(
|
35
|
-
"[Profiler] failed to obtain the profile error_class=#{error.class} error_message=#{error.message}"
|
36
|
-
)
|
37
|
-
nil
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
27
|
def start(params = {})
|
43
28
|
# Do not start the profiler if StackProf was started somewhere else.
|
44
29
|
return false if running?
|
45
30
|
|
46
31
|
clear
|
47
32
|
|
48
|
-
StackProf.start(DEFAULTS
|
33
|
+
StackProf.start(**DEFAULTS, **params)
|
49
34
|
rescue => error
|
50
35
|
AppProfiler.logger.info(
|
51
36
|
"[Profiler] failed to start the profiler error_class=#{error.class} error_message=#{error.message}"
|
@@ -59,6 +44,21 @@ module AppProfiler
|
|
59
44
|
StackProf.stop
|
60
45
|
end
|
61
46
|
|
47
|
+
def results
|
48
|
+
stackprof_profile = stackprof_results
|
49
|
+
|
50
|
+
return unless stackprof_profile
|
51
|
+
|
52
|
+
Profile.from_stackprof(stackprof_profile)
|
53
|
+
rescue => error
|
54
|
+
AppProfiler.logger.info(
|
55
|
+
"[Profiler] failed to obtain the profile error_class=#{error.class} error_message=#{error.message}"
|
56
|
+
)
|
57
|
+
nil
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
62
|
def stackprof_results
|
63
63
|
StackProf.results
|
64
64
|
end
|
data/lib/app_profiler/railtie.rb
CHANGED
@@ -25,6 +25,7 @@ module AppProfiler
|
|
25
25
|
"tmp", "app_profiler"
|
26
26
|
)
|
27
27
|
AppProfiler.context = app.config.app_profiler.context || Rails.env
|
28
|
+
AppProfiler.profile_url_formatter = app.config.app_profiler.profile_url_formatter
|
28
29
|
end
|
29
30
|
|
30
31
|
initializer "app_profiler.add_middleware" do |app|
|
data/lib/app_profiler/version.rb
CHANGED
@@ -14,6 +14,7 @@ module AppProfiler
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def initialize(profile)
|
17
|
+
super()
|
17
18
|
@profile = profile
|
18
19
|
end
|
19
20
|
|
@@ -33,7 +34,10 @@ module AppProfiler
|
|
33
34
|
def setup_yarn
|
34
35
|
ensure_yarn_installed
|
35
36
|
yarn("init --yes") unless package_json_exists?
|
36
|
-
|
37
|
+
# We currently only support this gem in the root Gemfile.
|
38
|
+
# See https://github.com/Shopify/app_profiler/issues/15
|
39
|
+
# for more information
|
40
|
+
yarn("add --dev --ignore-workspace-root-check speedscope") unless speedscope_added?
|
37
41
|
end
|
38
42
|
|
39
43
|
def ensure_yarn_installed
|
@@ -53,6 +57,10 @@ module AppProfiler
|
|
53
57
|
AppProfiler.root.join("package.json").exist?
|
54
58
|
end
|
55
59
|
|
60
|
+
def speedscope_added?
|
61
|
+
AppProfiler.root.join("node_modules/speedscope").exist?
|
62
|
+
end
|
63
|
+
|
56
64
|
def exec(command)
|
57
65
|
system(command).tap do |return_code|
|
58
66
|
yield unless return_code
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: app_profiler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gannon McGibbon
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date:
|
16
|
+
date: 2021-06-09 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: activesupport
|
@@ -182,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
182
|
- !ruby/object:Gem::Version
|
183
183
|
version: '0'
|
184
184
|
requirements: []
|
185
|
-
rubygems_version: 3.
|
185
|
+
rubygems_version: 3.2.17
|
186
186
|
signing_key:
|
187
187
|
specification_version: 4
|
188
188
|
summary: Collect performance profiles for your Rails application.
|