app_profiler 0.2.8 → 0.2.9
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/base_profile.rb +10 -2
- data/lib/app_profiler/profile_id.rb +24 -4
- data/lib/app_profiler/request_parameters.rb +1 -1
- data/lib/app_profiler/stackprof_profile.rb +11 -0
- data/lib/app_profiler/vernier_profile.rb +13 -0
- data/lib/app_profiler/version.rb +1 -1
- data/lib/app_profiler.rb +6 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88fa4e71be7c319cba26e669752c8a7a46c9b7c56881894944a8ae4b8def6c6f
|
4
|
+
data.tar.gz: 9daa41d818e4fbd0a113186c20e7a18814a3c039bc7dc91d52d26efd7a3ab5c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8471c04250be1ae8b393a804ee83553ccc5c374008f343ab0213464b130658ee69fa77626a0f557e7423350e60d0ac6c803228a656e48be739def63400d34fe3
|
7
|
+
data.tar.gz: 216c13be42bb571a535c894f543889fa114f97ff49aa84fb59d7ab2a39e8b7f2815c5e75399a3d98b7cbcf645376e37bb4899d8e5c63761f3fac6f1ca2483848
|
@@ -8,7 +8,7 @@ module AppProfiler
|
|
8
8
|
private_constant :INTERNAL_METADATA_KEYS
|
9
9
|
class UnsafeFilename < StandardError; end
|
10
10
|
|
11
|
-
attr_reader :
|
11
|
+
attr_reader :context
|
12
12
|
|
13
13
|
delegate :[], to: :@data
|
14
14
|
|
@@ -34,9 +34,17 @@ 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
|
-
|
37
|
+
ProfileId.current = id if id.present?
|
38
|
+
|
38
39
|
@context = context
|
39
40
|
@data = data
|
41
|
+
|
42
|
+
metadata[PROFILE_BACKEND_METADATA_KEY] = self.class.backend_name
|
43
|
+
metadata[PROFILE_ID_METADATA_KEY] = ProfileId.current
|
44
|
+
end
|
45
|
+
|
46
|
+
def id
|
47
|
+
metadata[PROFILE_ID_METADATA_KEY]
|
40
48
|
end
|
41
49
|
|
42
50
|
def upload
|
@@ -1,19 +1,39 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "active_support/current_attributes"
|
4
3
|
require "securerandom"
|
5
4
|
|
6
5
|
module AppProfiler
|
7
6
|
class ProfileId
|
8
|
-
class Current
|
9
|
-
|
7
|
+
class Current
|
8
|
+
PROFILE_ID_KEY = :__app_profiler_profile_id__
|
9
|
+
class << self
|
10
|
+
# This is a thread local variable which gets reset by the middleware at the end of the request.
|
11
|
+
# Need to be mindful of the middleware order. If we try to access ProfileId after the middleware has finished,
|
12
|
+
# lets say in a middleware which runs before Profiling middleware, it will return a different value,
|
13
|
+
# as the middleware has already reset.
|
14
|
+
|
15
|
+
def id
|
16
|
+
Thread.current[PROFILE_ID_KEY] ||= SecureRandom.hex
|
17
|
+
end
|
18
|
+
|
19
|
+
def id=(id)
|
20
|
+
Thread.current[PROFILE_ID_KEY] = id
|
21
|
+
end
|
22
|
+
|
23
|
+
def reset
|
24
|
+
Thread.current[PROFILE_ID_KEY] = nil
|
25
|
+
end
|
26
|
+
end
|
10
27
|
end
|
11
28
|
|
12
29
|
class << self
|
13
30
|
def current
|
14
|
-
Current.id ||= SecureRandom.hex
|
15
31
|
Current.id
|
16
32
|
end
|
33
|
+
|
34
|
+
def current=(id)
|
35
|
+
Current.id = id
|
36
|
+
end
|
17
37
|
end
|
18
38
|
end
|
19
39
|
end
|
@@ -33,7 +33,7 @@ module AppProfiler
|
|
33
33
|
|
34
34
|
return false if backend != AppProfiler::Backend::StackprofBackend.name && !AppProfiler.vernier_supported?
|
35
35
|
|
36
|
-
if AppProfiler.vernier_supported? && backend == AppProfiler::
|
36
|
+
if AppProfiler.vernier_supported? && backend == AppProfiler::VernierProfile::BACKEND_NAME &&
|
37
37
|
!AppProfiler::Backend::VernierBackend::AVAILABLE_MODES.include?(mode.to_sym)
|
38
38
|
AppProfiler.logger.info("[AppProfiler] unsupported profiling mode=#{mode} for backend #{backend}")
|
39
39
|
return false
|
@@ -4,6 +4,17 @@ module AppProfiler
|
|
4
4
|
class StackprofProfile < BaseProfile
|
5
5
|
FILE_EXTENSION = ".stackprof.json"
|
6
6
|
|
7
|
+
class << self
|
8
|
+
def backend_name
|
9
|
+
Backend::StackprofBackend.name.to_s
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(data, id: nil, context: nil)
|
14
|
+
data[:metadata] ||= {}
|
15
|
+
super(data, id: id, context: context)
|
16
|
+
end
|
17
|
+
|
7
18
|
def mode
|
8
19
|
@data[:mode]
|
9
20
|
end
|
@@ -3,6 +3,19 @@
|
|
3
3
|
module AppProfiler
|
4
4
|
class VernierProfile < BaseProfile
|
5
5
|
FILE_EXTENSION = ".vernier.json"
|
6
|
+
BACKEND_NAME = :vernier
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def backend_name
|
10
|
+
# cannot reference Backend::VernierBackend because of different ruby versions we have to support
|
11
|
+
BACKEND_NAME.to_s
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(data, id: nil, context: nil)
|
16
|
+
data[:meta] ||= {}
|
17
|
+
super(data, id: id, context: context)
|
18
|
+
end
|
6
19
|
|
7
20
|
def mode
|
8
21
|
@data[:meta][:mode]
|
data/lib/app_profiler/version.rb
CHANGED
data/lib/app_profiler.rb
CHANGED
@@ -7,6 +7,9 @@ require "logger"
|
|
7
7
|
require "app_profiler/version"
|
8
8
|
|
9
9
|
module AppProfiler
|
10
|
+
PROFILE_ID_METADATA_KEY = :profile_id
|
11
|
+
PROFILE_BACKEND_METADATA_KEY = :profiler
|
12
|
+
|
10
13
|
class ConfigurationError < StandardError
|
11
14
|
end
|
12
15
|
|
@@ -90,6 +93,7 @@ module AppProfiler
|
|
90
93
|
yield
|
91
94
|
ensure
|
92
95
|
self.backend = original_backend if backend
|
96
|
+
ProfileId::Current.reset
|
93
97
|
end
|
94
98
|
|
95
99
|
def start(*args, backend: nil, **kwargs)
|
@@ -160,7 +164,7 @@ module AppProfiler
|
|
160
164
|
|
161
165
|
def backend_for(backend_name)
|
162
166
|
if vernier_supported? &&
|
163
|
-
backend_name&.to_sym == AppProfiler::
|
167
|
+
backend_name&.to_sym == AppProfiler::VernierProfile::BACKEND_NAME
|
164
168
|
AppProfiler::Backend::VernierBackend
|
165
169
|
elsif backend_name&.to_sym == AppProfiler::Backend::StackprofBackend.name
|
166
170
|
AppProfiler::Backend::StackprofBackend
|
@@ -174,7 +178,7 @@ module AppProfiler
|
|
174
178
|
end
|
175
179
|
|
176
180
|
def vernier_supported?
|
177
|
-
RUBY_VERSION >= "3.2.1" && defined?(AppProfiler::
|
181
|
+
RUBY_VERSION >= "3.2.1" && defined?(AppProfiler::VernierProfile::BACKEND_NAME)
|
178
182
|
end
|
179
183
|
|
180
184
|
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.
|
4
|
+
version: 0.2.9
|
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-
|
15
|
+
date: 2025-02-10 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: activesupport
|