Class: Vernier::ParsedProfile

Inherits:
Object
  • Object
show all
Defined in:
lib/vernier/parsed_profile.rb

Defined Under Namespace

Classes: StackTable, Thread

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ ParsedProfile

Returns a new instance of ParsedProfile.



87
88
89
# File 'lib/vernier/parsed_profile.rb', line 87

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



86
87
88
# File 'lib/vernier/parsed_profile.rb', line 86

def data
  @data
end

Class Method Details

.read_file(filename) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/vernier/parsed_profile.rb', line 8

def self.read_file(filename)
  # Print the inverted tree from a Vernier profile
  is_gzip = File.binread(filename, 2) == "\x1F\x8B".b # check for gzip header

  json = if is_gzip
    require "zlib"
    Zlib::GzipReader.open(filename) { |gz| gz.read }
  else
    File.read filename
  end

  info = JSON.load json

  new(info)
end

Instance Method Details

#main_threadObject



98
99
100
# File 'lib/vernier/parsed_profile.rb', line 98

def main_thread
  threads.detect(&:main_thread?)
end

#threadsObject



91
92
93
94
95
96
# File 'lib/vernier/parsed_profile.rb', line 91

def threads
  @threads ||=
    @data["threads"].map do |thread_data|
      Thread.new(thread_data)
    end
end