app_profiler 0.0.1 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e14252a4cfb042174369c9a1db2b36944b69e9ea3a1c5deecda4eb6875b88c66
4
- data.tar.gz: 10c8227518e0cf32755479fc231df4d676c08bdd0052c347372fde5d39a81f73
3
+ metadata.gz: b93daeac19342da210b998d381259941dc1d12c96fa5d58097423d86b32c03f3
4
+ data.tar.gz: d7b50f279a8b197ba847363db5a6e92b394ac506804d9a499c519dcd36b6071c
5
5
  SHA512:
6
- metadata.gz: ad09ac71560705b5ccb548f9fab69c9c7ffa2d1183621ab7eb8faa51af73020b7efa3a9323db65b9a092f98e2e649d31641a92f5ac3d5433d3f8f2f298274b73
7
- data.tar.gz: 95ddee7961e0a52829ea9bc31819c13b8bec3531f00a202cbd03532b11266f52c8c47c5171fed54c7bf55bbe19be4fb2664c08681d38f0229587166d2fa1d1ff
6
+ metadata.gz: d996e6faf3bb8c02e8f34e462d3c74beac53d656d188330972ecba83770524b42dbc36132aa8b6e2cadd57fe0b6b5504a548a1d96ae58b3e7e14ac504d672f2e
7
+ data.tar.gz: 124bc292cff5decf4cdf7f7d4b8b22cc2820123a1fbda5f56970a1fd76da74675e68dbb5a953024c778eb64bb5c9a7ff8b41f0a62be5dcbdd0f6e214a7cc8fc7
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
- "#{AppProfiler.speedscope_host}#profileURL=#{upload.url}"
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)
@@ -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.merge(params))
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
@@ -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|
@@ -4,8 +4,8 @@ require "rack"
4
4
 
5
5
  module AppProfiler
6
6
  class RequestParameters
7
- DEFAULT_INTERVALS = { "cpu" => 1000, "wall" => 1000, "object" => 10000 }.freeze
8
- MIN_INTERVALS = { "cpu" => 200, "wall" => 200, "object" => 10000 }.freeze
7
+ DEFAULT_INTERVALS = { "cpu" => 1000, "wall" => 1000, "object" => 2000 }.freeze
8
+ MIN_INTERVALS = { "cpu" => 200, "wall" => 200, "object" => 400 }.freeze
9
9
  MODES = DEFAULT_INTERVALS.keys.freeze
10
10
 
11
11
  def initialize(request)
@@ -11,6 +11,10 @@ module AppProfiler
11
11
  def url
12
12
  @file
13
13
  end
14
+
15
+ def name
16
+ @file.basename
17
+ end
14
18
  end
15
19
 
16
20
  class << self
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AppProfiler
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.7"
5
5
  end
@@ -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
- yarn("add --dev speedscope")
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.1
4
+ version: 0.0.7
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: 2020-02-19 00:00:00.000000000 Z
16
+ date: 2021-02-19 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: activesupport
@@ -165,7 +165,8 @@ files:
165
165
  - lib/app_profiler/viewer/speedscope_viewer.rb
166
166
  homepage: https://github.com/Shopify/app_profiler
167
167
  licenses: []
168
- metadata: {}
168
+ metadata:
169
+ allowed_push_host: https://rubygems.org
169
170
  post_install_message:
170
171
  rdoc_options: []
171
172
  require_paths: