Class: Pf2::Reporter::Pprof
- Inherits:
-
Object
- Object
- Pf2::Reporter::Pprof
- Defined in:
- lib/pf2/reporter/pprof.rb
Instance Method Summary collapse
- #emit ⇒ Object
-
#initialize(profile) ⇒ Pprof
constructor
A new instance of Pprof.
Constructor Details
#initialize(profile) ⇒ Pprof
Returns a new instance of Pprof.
152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/pf2/reporter/pprof.rb', line 152 def initialize(profile) @profile = profile @stack_weaver = StackWeaver.new(profile) @strings = [] @string_id_table = {} @function_id_map = {} @location_id_map = {} string_index("") # index 0 is empty string end |
Instance Method Details
#emit ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/pf2/reporter/pprof.rb', line 164 def emit pb = Protobuf.new pb.int64(PROTO_TAGS[:profile][:time_nanos], @profile[:start_timestamp_ns] || 0) pb.int64(PROTO_TAGS[:profile][:duration_nanos], @profile[:duration_ns] || 0) # Sample types pb.(PROTO_TAGS[:profile][:sample_type], pb_value_type("samples", "count")) pb.(PROTO_TAGS[:profile][:sample_type], pb_value_type("cpu", "nanoseconds")) # Period pb.(PROTO_TAGS[:profile][:period_type], pb_value_type("cpu", "nanoseconds")) pb.int64(PROTO_TAGS[:profile][:period], inferred_period_ns) build_functions(pb) build_locations(pb) build_samples(pb) # String table @strings.each do |s| pb.string(PROTO_TAGS[:profile][:string_table], s) end buffer = StringIO.new Zlib::GzipWriter.wrap(buffer) { |gz| gz.write(pb.to_bytes) } buffer.string end |