Class: RbLineProfFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/pilfer/server.rb

Overview

Formatting a profile as JSON may eventually be provided by rblineprof.

Class Method Summary collapse

Class Method Details

.profile_to_json(profile_data, profile_start) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/pilfer/server.rb', line 74

def self.profile_to_json(profile_data, profile_start)
  files = profile_data.each_with_object({}) do |(file, lines), files|
    profile_lines = lines[1..-1].
                      each_with_index.
                      each_with_object({}) do |(data, number), inner_lines|
      next unless data.any? {|datum| datum > 0 }
      wall_time, cpu_time, calls = data
      inner_lines[number] = { 'wall_time' => wall_time,
                        'cpu_time'  => cpu_time,
                        'calls'     => calls }
    end

    total, child, exclusive, total_cpu, child_cpu, exclusive_cpu = lines[0]

    files[file] = { 'total'         => total,
                    'child'         => child,
                    'exclusive'     => exclusive,
                    'total_cpu'     => total_cpu,
                    'child_cpu'     => child_cpu,
                    'exclusive_cpu' => exclusive_cpu,
                    'lines'         => profile_lines }
  end

  {
    'profile' => {
      'timestamp' => profile_start.to_i,
      'files'     => files
    }
  }
end