Class: AppProfiler::BaseProfile
- Inherits:
-
Object
- Object
- AppProfiler::BaseProfile
show all
- Defined in:
- lib/app_profiler/base_profile.rb
Defined Under Namespace
Classes: UnsafeFilename
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(data, id: nil, context: nil) ⇒ BaseProfile
‘data` is assumed to be a Hash for Stackprof, a vernier “result” object for vernier
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
11
12
13
|
# File 'lib/app_profiler/base_profile.rb', line 11
def context
@context
end
|
Class Method Details
.from_stackprof(data) ⇒ Object
This function should not be called if ‘StackProf.results` returns nil.
17
18
19
20
21
22
23
|
# File 'lib/app_profiler/base_profile.rb', line 17
def from_stackprof(data)
options = INTERNAL_METADATA_KEYS.map { |key| [key, data[:metadata]&.delete(key)] }.to_h
StackprofProfile.new(data, **options).tap do |profile|
raise ArgumentError, "invalid profile data" unless profile.valid?
end
end
|
.from_vernier(data) ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/app_profiler/base_profile.rb', line 25
def from_vernier(data)
options = INTERNAL_METADATA_KEYS.map { |key| [key, data[:meta]&.delete(key)] }.to_h
VernierProfile.new(data, **options).tap do |profile|
raise ArgumentError, "invalid profile data" unless profile.valid?
end
end
|
Instance Method Details
#duration ⇒ Object
50
51
52
|
# File 'lib/app_profiler/base_profile.rb', line 50
def duration
metadata[:duration]
end
|
#enqueue_upload ⇒ Object
73
74
75
|
# File 'lib/app_profiler/base_profile.rb', line 73
def enqueue_upload
AppProfiler.storage.enqueue_upload(self)
end
|
#file ⇒ Object
81
82
83
84
85
86
|
# File 'lib/app_profiler/base_profile.rb', line 81
def file
@file ||= path.tap do |p|
p.dirname.mkpath
p.write(JSON.dump(@data))
end
end
|
100
101
102
|
# File 'lib/app_profiler/base_profile.rb', line 100
def format
raise NotImplementedError
end
|
92
93
94
|
# File 'lib/app_profiler/base_profile.rb', line 92
def metadata
raise NotImplementedError
end
|
#mode ⇒ Object
96
97
98
|
# File 'lib/app_profiler/base_profile.rb', line 96
def mode
raise NotImplementedError
end
|
#to_h ⇒ Object
88
89
90
|
# File 'lib/app_profiler/base_profile.rb', line 88
def to_h
@data
end
|
#upload ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/app_profiler/base_profile.rb', line 54
def upload
AppProfiler.storage.upload(self).tap do |upload|
if upload && defined?(upload.url)
AppProfiler.logger.info(
<<~INFO.squish,
[Profiler] data uploaded:
profile_url=#{upload.url}
profile_viewer_url=#{AppProfiler.profile_url(upload)}
INFO
)
end
end
rescue => error
AppProfiler.logger.info(
"[Profiler] failed to upload profile error_class=#{error.class} error_message=#{error.message}",
)
nil
end
|
#valid? ⇒ Boolean
77
78
79
|
# File 'lib/app_profiler/base_profile.rb', line 77
def valid?
mode.present?
end
|
#view(params = {}) ⇒ Object
104
105
106
|
# File 'lib/app_profiler/base_profile.rb', line 104
def view(params = {})
raise NotImplementedError
end
|