app_profiler 0.2.6 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b5be705606d138c4e042f4d87820e97413be62f3eeeb92cbb34d5e02aac600ea
4
- data.tar.gz: d15e16f16c53f939cb874ab841b60528f4b46b5359e755ba5ce6acfe01265b3e
3
+ metadata.gz: ab22ed223e6cc5f20f3a2541a1ecc17a266591510c199d09ea7b05a91d5b2441
4
+ data.tar.gz: 73e6a570e6a898170f8caa47c1f389a8d13063e39f46bfdcbef7ecac3cdec677
5
5
  SHA512:
6
- metadata.gz: ccbe4b8fb2b5a4a1882fb7e33e03f35b7f91afa2a8eeb836e705bae104131e05b1d48d6c7d118cd1c69665e9736c2d9d621a1b05626ba112d63299615de609b1
7
- data.tar.gz: ff0cb2c2cced5f0edd575d9b6ddb2d6cf83021225d528c4f7e194ed527360bab09a511864e6e5ed047e2e84ddbab737a7060c39b9931ac8fbc976a4489aa128e
6
+ metadata.gz: 1c269a8514ab205bc7081f23e0b9cd914d7b1dbe252f21963e2ddc2cf7ddcf4c717e759eda03179136578b3c3a840f9253e22b21bc5415699ab2e30e32cc5d26
7
+ data.tar.gz: e17b9a934254e1871f34b81c9c66c589aa218d24fc5b2cfa6b0fbc34945313b8e1a0b9866f431b27a6d484694b8a6222cd4739602233020541cc3288c9ee63e9
@@ -34,7 +34,7 @@ module AppProfiler
34
34
  # `data` is assumed to be a Hash for Stackprof,
35
35
  # a vernier "result" object for vernier
36
36
  def initialize(data, id: nil, context: nil)
37
- @id = id.presence || SecureRandom.hex
37
+ @id = id.presence || ProfileId.current
38
38
  @context = context
39
39
  @data = data
40
40
  end
@@ -96,12 +96,16 @@ module AppProfiler
96
96
  private
97
97
 
98
98
  def path
99
- filename = [
100
- AppProfiler.profile_file_prefix.call,
101
- mode,
102
- id,
103
- Socket.gethostname,
104
- ].compact.join("-") << format
99
+ filename = if AppProfiler.profile_file_name.present?
100
+ AppProfiler.profile_file_name.call(metadata) + format
101
+ else
102
+ [
103
+ AppProfiler.profile_file_prefix.call,
104
+ mode,
105
+ id,
106
+ Socket.gethostname,
107
+ ].compact.join("-") << format
108
+ end
105
109
 
106
110
  raise UnsafeFilename if /[^0-9A-Za-z.\-\_]/.match?(filename)
107
111
 
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/current_attributes"
4
+ require "securerandom"
5
+
6
+ module AppProfiler
7
+ class ProfileId
8
+ class Current < ActiveSupport::CurrentAttributes
9
+ attribute :id
10
+ end
11
+
12
+ class << self
13
+ def current
14
+ Current.id ||= SecureRandom.hex
15
+ Current.id
16
+ end
17
+ end
18
+ end
19
+ end
@@ -42,6 +42,7 @@ module AppProfiler
42
42
  AppProfiler.upload_queue_max_length = app.config.app_profiler.upload_queue_max_length || 10
43
43
  AppProfiler.upload_queue_interval_secs = app.config.app_profiler.upload_queue_interval_secs || 5
44
44
  AppProfiler.profile_file_prefix = app.config.app_profiler.profile_file_prefix || DefaultProfilePrefix
45
+ AppProfiler.profile_file_name = app.config.app_profiler.profile_file_name
45
46
  AppProfiler.profile_enqueue_success = app.config.app_profiler.profile_enqueue_success
46
47
  AppProfiler.profile_enqueue_failure = app.config.app_profiler.profile_enqueue_failure
47
48
  AppProfiler.after_process_queue = app.config.app_profiler.after_process_queue
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AppProfiler
4
- VERSION = "0.2.6"
4
+ VERSION = "0.2.8"
5
5
  end
@@ -48,7 +48,7 @@ module AppProfiler
48
48
 
49
49
  def setup_profile_viewer
50
50
  exec("which", "profile-viewer", silent: true) do
51
- gem_install("profile_viewer")
51
+ gem_install("profile-viewer")
52
52
  end
53
53
  @profile_viewer_initialized = true
54
54
  end
data/lib/app_profiler.rb CHANGED
@@ -45,6 +45,7 @@ module AppProfiler
45
45
  autoload(:Backend, "app_profiler/backend")
46
46
  autoload(:Server, "app_profiler/server")
47
47
  autoload(:Sampler, "app_profiler/sampler")
48
+ autoload(:ProfileId, "app_profiler/profile_id")
48
49
 
49
50
  mattr_accessor :logger, default: Logger.new($stdout)
50
51
  mattr_accessor :root
@@ -68,8 +69,8 @@ module AppProfiler
68
69
  mattr_reader :profile_enqueue_failure, default: nil
69
70
  mattr_reader :after_process_queue, default: nil
70
71
  mattr_accessor :forward_metadata_on_upload, default: false
71
-
72
72
  mattr_accessor :profile_sampler_config
73
+ mattr_reader :profile_file_name
73
74
 
74
75
  class << self
75
76
  def deprecator # :nodoc:
@@ -129,6 +130,12 @@ module AppProfiler
129
130
  @@vernier_viewer ||= Viewer::FirefoxViewer # rubocop:disable Style/ClassVars
130
131
  end
131
132
 
133
+ def profile_file_name=(value)
134
+ raise ArgumentError, "profile_file_name must be a proc" if value && !value.is_a?(Proc)
135
+
136
+ @@profile_file_name = value # rubocop:disable Style/ClassVars
137
+ end
138
+
132
139
  def profile_sampler_enabled=(value)
133
140
  if value.is_a?(Proc)
134
141
  raise ArgumentError,
@@ -167,7 +174,7 @@ module AppProfiler
167
174
  end
168
175
 
169
176
  def vernier_supported?
170
- RUBY_VERSION >= "3.2.1"
177
+ RUBY_VERSION >= "3.2.1" && defined?(AppProfiler::Backend::VernierBackend.name)
171
178
  end
172
179
 
173
180
  def profile_header=(profile_header)
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.2.6
4
+ version: 0.2.8
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-01-22 00:00:00.000000000 Z
15
+ date: 2025-02-04 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activesupport
@@ -144,6 +144,7 @@ files:
144
144
  - lib/app_profiler/middleware/upload_action.rb
145
145
  - lib/app_profiler/middleware/view_action.rb
146
146
  - lib/app_profiler/parameters.rb
147
+ - lib/app_profiler/profile_id.rb
147
148
  - lib/app_profiler/railtie.rb
148
149
  - lib/app_profiler/request_parameters.rb
149
150
  - lib/app_profiler/sampler.rb
@@ -186,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
187
  - !ruby/object:Gem::Version
187
188
  version: '0'
188
189
  requirements: []
189
- rubygems_version: 3.6.2
190
+ rubygems_version: 3.6.3
190
191
  specification_version: 4
191
192
  summary: Collect performance profiles for your Rails application.
192
193
  test_files: []