Class: Pf2::Reporter::FirefoxProfilerSer2
- Inherits:
-
Object
- Object
- Pf2::Reporter::FirefoxProfilerSer2
- Defined in:
- lib/pf2/reporter/firefox_profiler_ser2.rb
Overview
Generates Firefox Profiler’s “processed profile format” github.com/firefox-devtools/profiler/blob/main/docs-developer/processed-profile-format.md
Defined Under Namespace
Classes: ThreadReport
Class Method Summary collapse
- .deep_camelize_keys(value) ⇒ Object
- .deep_transform_keys(value, &block) ⇒ Object
- .snake_to_camel(s) ⇒ Object
Instance Method Summary collapse
- #emit ⇒ Object
-
#initialize(profile) ⇒ FirefoxProfilerSer2
constructor
A new instance of FirefoxProfilerSer2.
- #inspect ⇒ Object
Constructor Details
#initialize(profile) ⇒ FirefoxProfilerSer2
Returns a new instance of FirefoxProfilerSer2.
10 11 12 |
# File 'lib/pf2/reporter/firefox_profiler_ser2.rb', line 10 def initialize(profile) @profile = profile end |
Class Method Details
.deep_camelize_keys(value) ⇒ Object
300 301 302 303 304 |
# File 'lib/pf2/reporter/firefox_profiler_ser2.rb', line 300 def deep_camelize_keys(value) deep_transform_keys(value) do |key| snake_to_camel(key.to_s).to_sym end end |
.deep_transform_keys(value, &block) ⇒ Object
289 290 291 292 293 294 295 296 297 298 |
# File 'lib/pf2/reporter/firefox_profiler_ser2.rb', line 289 def deep_transform_keys(value, &block) case value when Array value.map {|v| deep_transform_keys(v, &block) } when Hash Hash[value.map {|k, v| [yield(k), deep_transform_keys(v, &block)] }] else value end end |
.snake_to_camel(s) ⇒ Object
282 283 284 285 286 287 |
# File 'lib/pf2/reporter/firefox_profiler_ser2.rb', line 282 def snake_to_camel(s) return "isJS" if s == "is_js" return "relevantForJS" if s == "relevant_for_js" return "innerWindowID" if s == "inner_window_id" s.split('_').inject([]) {|buffer, p| buffer.push(buffer.size == 0 ? p : p.capitalize) }.join end |
Instance Method Details
#emit ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/pf2/reporter/firefox_profiler_ser2.rb', line 18 def emit grouped_threads = @profile[:samples].group_by {|s| s[:ruby_thread_id] } thread_reports = grouped_threads.map do |thread_id, samples| ThreadReport.new(@profile, thread_id, samples).emit end report = { meta: { interval: 10, # ms; TODO: replace with actual interval start_time: 0, process_type: 0, product: 'ruby', stackwalk: 0, version: 28, preprocessed_profile_version: 47, symbolicated: true, categories: [ { name: "Logs", color: "grey", subcategories: ["Unused"], }, { name: "Ruby", color: "red", subcategories: ["Code"], }, { name: "Native", color: "blue", subcategories: ["Code"], }, { name: "Native", color: "lightblue", subcategories: ["Code"], }, ], marker_schema: [], }, libs: [], counters: [], threads: thread_reports, } FirefoxProfiler.deep_camelize_keys(report) end |
#inspect ⇒ Object
14 15 16 |
# File 'lib/pf2/reporter/firefox_profiler_ser2.rb', line 14 def inspect "#<#{self.class.name} (#{@profile[:samples].length} samples)>" end |