Sha256: b161ca7c2463065e08400f8eb6edcaff8ba623ba83355ecaf1140ed4ebbd4779

Contents?: true

Size: 1.33 KB

Versions: 10

Compression:

Stored size: 1.33 KB

Contents

require 'time'

require_relative '../pprof/template'

module Datadog
  module Profiling
    module Encoding
      module Profile
        # Encodes gathered data into the pprof format
        module Protobuf
          module_function

          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
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ddtrace-1.14.0 lib/datadog/profiling/encoding/profile.rb
ddtrace-1.13.1 lib/datadog/profiling/encoding/profile.rb
ddtrace-1.13.0 lib/datadog/profiling/encoding/profile.rb
ddtrace-1.12.1 lib/datadog/profiling/encoding/profile.rb
ddtrace-1.12.0 lib/datadog/profiling/encoding/profile.rb
ddtrace-1.11.1 lib/datadog/profiling/encoding/profile.rb
ddtrace-1.11.0 lib/datadog/profiling/encoding/profile.rb
ddtrace-1.11.0.beta1 lib/datadog/profiling/encoding/profile.rb
ddtrace-1.10.1 lib/datadog/profiling/encoding/profile.rb
ddtrace-1.10.0 lib/datadog/profiling/encoding/profile.rb