Module: Datadog::Profiling::Encoding::Profile::Protobuf

Defined in:
lib/datadog/profiling/encoding/profile.rb

Overview

Encodes gathered data into the pprof format

Class Method Summary collapse

Class Method Details

.encode(event_count:, event_groups:, start:, finish:) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/datadog/profiling/encoding/profile.rb', line 13

def encode(event_count:, event_groups:, start:, finish:)
  # Create a pprof template from the list of event types
  event_classes = event_groups.collect(&:event_class).uniq
  template = Pprof::Template.for_event_classes(event_classes)

  # Add all events to the pprof
  event_groups.each { |event_group| template.add_events!(event_group.event_class, event_group.events) }

  Datadog.logger.debug do
    max_events = Datadog.configuration.profiling.advanced.max_events
    events_sampled =
      if event_count == max_events
        'max events limit hit, events were sampled [profile will be biased], '
      else
        ''
      end

    "Encoding profile covering #{start.iso8601} to #{finish.iso8601}, " \
    "events: #{event_count} (#{events_sampled}#{template.debug_statistics})"
  end

  # Build the profile and encode it
  template.to_pprof(start: start, finish: finish)
end