Sha256: 8b07f959e79523a0ce667edd72d09a7718025204f85a2792c6342b1ebf304974

Contents?: true

Size: 944 Bytes

Versions: 4

Compression:

Stored size: 944 Bytes

Contents

# typed: true

require 'datadog/core/buffer/thread_safe'
require 'datadog/core/utils/object_set'
require 'datadog/core/utils/string_table'

module Datadog
  module Profiling
    # Profiling buffer that stores profiling events. The buffer has a maximum size and when
    # the buffer is full, a random event is discarded. This class is thread-safe.
    class Buffer < Core::Buffer::ThreadSafe
      def initialize(*args)
        super
        @caches = {}
        @string_table = Core::Utils::StringTable.new
      end

      def cache(cache_name)
        synchronize do
          @caches[cache_name] ||= Core::Utils::ObjectSet.new
        end
      end

      def string_table
        synchronize do
          @string_table
        end
      end

      protected

      def drain!
        items = super

        # Clear caches
        @caches = {}
        @string_table = Core::Utils::StringTable.new

        items
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ddtrace-1.2.0 lib/datadog/profiling/buffer.rb
ddtrace-1.1.0 lib/datadog/profiling/buffer.rb
ddtrace-1.0.0 lib/datadog/profiling/buffer.rb
ddtrace-1.0.0.beta2 lib/datadog/profiling/buffer.rb