app_profiler 0.3.0 → 0.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e78035c478029d4ad4de636efab44240957c2bd05ea761dc9fe28b753b4fa1d3
4
- data.tar.gz: c4d6659a31eaa7440c6c8a2550c9cf41fbadb567426cae7c6bd0cd4442e8039a
3
+ metadata.gz: 2e510f0a0d20ec300e0ae5593adbdb03195202ea68e6a8ecad5fb13abfef9473
4
+ data.tar.gz: 66dd66baaa5e863a0b0311431da9ab17f794c3e8902e73b6d29f998c0867db74
5
5
  SHA512:
6
- metadata.gz: 45610912af0b6952b2c104d27bfc3bf2b37b92f91d2c873bdf9e2bfc43498529decf9568af63b9ee47d84794dd921dbf6312de11aac272be296f99416d5f2b31
7
- data.tar.gz: 29ee1a661cc8c81274fbdb7f6123ce90d7dbeaa351ca3b16a8a6bfe933ec3f68385bfe0f2d0afb2ae6c49ba59fa318d733bd23d6cf7724a3d03f1246e36b65ca
6
+ metadata.gz: 67c22d47cea0a3fe91928495b4d14f476c727bd98c976bb7ae310b61b317c0a54dc91d350c870cc8cc155a044f33f49dfc5a1c739bd68609261af537c43b8913
7
+ data.tar.gz: 0e57a16a1bf6195fb8b723ae213e8fb2226a7858448420ef4e495363402033f1e9612971411981f505b9901dde425fc910d82023b788e1d60311d44ff3a0d258
@@ -3,8 +3,27 @@
3
3
  module AppProfiler
4
4
  module Backend
5
5
  class BaseBackend
6
- def run(params = {}, &block)
7
- raise NotImplementedError
6
+ def run(params = {})
7
+ started = start(params)
8
+ start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
9
+
10
+ yield
11
+
12
+ return unless started
13
+
14
+ duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time
15
+
16
+ stop
17
+ results_data = results
18
+
19
+ if results_data
20
+ results_data.metadata[:duration] = duration
21
+ end
22
+
23
+ results_data
24
+ ensure
25
+ # Only stop the profiler if profiling was started in this context.
26
+ stop if started
8
27
  end
9
28
 
10
29
  def start(params = {})
@@ -22,20 +22,6 @@ module AppProfiler
22
22
  end
23
23
  end
24
24
 
25
- def run(params = {})
26
- started = start(params)
27
-
28
- yield
29
-
30
- return unless started
31
-
32
- stop
33
- results
34
- ensure
35
- # Only stop the profiler if profiling was started in this context.
36
- stop if started
37
- end
38
-
39
25
  def start(params = {})
40
26
  # Do not start the profiler if StackProf was started somewhere else.
41
27
  return false if running?
@@ -21,20 +21,6 @@ module AppProfiler
21
21
  end
22
22
  end
23
23
 
24
- def run(params = {})
25
- started = start(params)
26
-
27
- yield
28
-
29
- return unless started
30
-
31
- stop
32
- results
33
- ensure
34
- # Only stop the profiler if profiling was started in this context.
35
- stop if started
36
- end
37
-
38
24
  def start(params = {})
39
25
  # Do not start the profiler if we already have a collector started somewhere else.
40
26
  return false if running?
@@ -47,6 +47,10 @@ module AppProfiler
47
47
  metadata[PROFILE_ID_METADATA_KEY]
48
48
  end
49
49
 
50
+ def duration
51
+ metadata[:duration]
52
+ end
53
+
50
54
  def upload
51
55
  AppProfiler.storage.upload(self).tap do |upload|
52
56
  if upload && defined?(upload.url)
@@ -34,6 +34,7 @@ module AppProfiler
34
34
  )
35
35
  AppProfiler.profile_header = app.config.app_profiler.profile_header || "X-Profile"
36
36
  AppProfiler.profile_async_header = app.config.app_profiler.profile_async_header || "X-Profile-Async"
37
+ AppProfiler.profile_param = app.config.app_profiler.profile_param || "profile"
37
38
  AppProfiler.profile_root = app.config.app_profiler.profile_root || Rails.root.join(
38
39
  "tmp", "app_profiler"
39
40
  )
@@ -66,7 +66,7 @@ module AppProfiler
66
66
  private
67
67
 
68
68
  def mode
69
- query_param("profile") || profile_header_param("mode")
69
+ query_param(AppProfiler.profile_param) || profile_header_param("mode")
70
70
  end
71
71
 
72
72
  def ignore_gc
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AppProfiler
4
- VERSION = "0.3.0"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/app_profiler.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require "active_support"
4
4
  require "active_support/core_ext/class"
5
5
  require "active_support/core_ext/module"
6
+ require "active_support/core_ext/time/zones"
6
7
  require "logger"
7
8
  require "app_profiler/version"
8
9
 
@@ -40,15 +41,16 @@ module AppProfiler
40
41
  end
41
42
 
42
43
  autoload(:Middleware, "app_profiler/middleware")
43
- autoload(:Parameters, "app_profiler/parameters")
44
- autoload(:RequestParameters, "app_profiler/request_parameters")
45
44
  autoload(:BaseProfile, "app_profiler/base_profile")
46
45
  autoload :StackprofProfile, "app_profiler/stackprof_profile"
47
46
  autoload :VernierProfile, "app_profiler/vernier_profile"
48
47
  autoload(:Backend, "app_profiler/backend")
49
48
  autoload(:Server, "app_profiler/server")
50
- autoload(:Sampler, "app_profiler/sampler")
51
- autoload(:ProfileId, "app_profiler/profile_id")
49
+
50
+ require "app_profiler/parameters"
51
+ require "app_profiler/request_parameters"
52
+ require "app_profiler/profile_id"
53
+ require "app_profiler/sampler"
52
54
 
53
55
  mattr_accessor :logger, default: Logger.new($stdout)
54
56
  mattr_accessor :root
@@ -58,6 +60,7 @@ module AppProfiler
58
60
  mattr_accessor :autoredirect, default: false
59
61
  mattr_reader :profile_header, default: "X-Profile"
60
62
  mattr_accessor :profile_async_header, default: "X-Profile-Async"
63
+ mattr_accessor :profile_param, default: "profile"
61
64
  mattr_accessor :context, default: nil
62
65
  mattr_reader :profile_url_formatter, default: DefaultProfileFormatter
63
66
  mattr_accessor :storage, default: Storage::FileStorage
@@ -89,9 +92,13 @@ module AppProfiler
89
92
  end
90
93
  profiler.run(*args, **kwargs, &block)
91
94
  rescue BackendError => e
92
- logger.error(
93
- "[AppProfiler.run] exception #{e} configuring backend #{backend}: #{e.message}",
94
- )
95
+ if ActiveSupport.respond_to?(:error_reporter)
96
+ ActiveSupport.error_reporter.report(e, context: { app_profiler: { backend: backend } })
97
+ else
98
+ logger.error(
99
+ "[AppProfiler.run] exception #{e} configuring backend #{backend}: #{e.message}",
100
+ )
101
+ end
95
102
  yield
96
103
  ensure
97
104
  self.backend = original_backend if backend
@@ -158,9 +165,13 @@ module AppProfiler
158
165
 
159
166
  @profile_sampler_enabled.is_a?(Proc) ? @profile_sampler_enabled.call : @profile_sampler_enabled
160
167
  rescue => e
161
- logger.error(
162
- "[AppProfiler.profile_sampler_enabled] exception: #{e}, message: #{e.message}",
163
- )
168
+ if ActiveSupport.respond_to?(:error_reporter)
169
+ ActiveSupport.error_reporter.report(e)
170
+ else
171
+ logger.error(
172
+ "[AppProfiler.profile_sampler_enabled] exception: #{e}, message: #{e.message}",
173
+ )
174
+ end
164
175
  false
165
176
  end
166
177
 
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.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gannon McGibbon
@@ -12,7 +12,7 @@ authors:
12
12
  - Scott Francis
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2025-02-24 00:00:00.000000000 Z
15
+ date: 1980-01-02 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activesupport
@@ -201,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
201
  - !ruby/object:Gem::Version
202
202
  version: '0'
203
203
  requirements: []
204
- rubygems_version: 3.6.3
204
+ rubygems_version: 4.0.6
205
205
  specification_version: 4
206
206
  summary: Collect performance profiles for your Rails application.
207
207
  test_files: []