Sha256: 85028f28064d91081697b565b588859e6c22b92462153d59cbe1c98cc7c41e19

Contents?: true

Size: 1.05 KB

Versions: 8

Compression:

Stored size: 1.05 KB

Contents

module SemanticLogger
  module JRuby
    class GarbageCollectionLogger
      include Java::JavaxManagement::NotificationListener

      # Only log the garbage collection if the number of microseconds exceeds
      # this value
      def initialize(min_microseconds = 10000)
        @min_microseconds = min_microseconds
      end

      # Must leave the method name as-is so that it can be found by Java
      def handleNotification(notification, _)
        # Only care about GARBAGE_COLLECTION_NOTIFICATION notifications
        return unless notification.get_type == Java::ComSunManagement::GarbageCollectionNotificationInfo::GARBAGE_COLLECTION_NOTIFICATION

        info     = Java::ComSunManagement::GarbageCollectionNotificationInfo.from(notification.user_data)
        gc_info  = info.gc_info
        duration = gc_info.duration
        if duration >= @min_microseconds
          SemanticLogger['GarbageCollector'].benchmark_warn "Garbage Collection completed: #{info.gc_name} ##{gc_info.id}", duration: duration.to_f / 1000
        end
      end
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
semantic_logger-3.0.1 lib/semantic_logger/jruby/garbage_collection_logger.rb
semantic_logger-3.0.0 lib/semantic_logger/jruby/garbage_collection_logger.rb
semantic_logger-2.21.0 lib/semantic_logger/jruby/garbage_collection_logger.rb
semantic_logger-2.20.0 lib/semantic_logger/jruby/garbage_collection_logger.rb
semantic_logger-2.19.0 lib/semantic_logger/jruby/garbage_collection_logger.rb
semantic_logger-2.18.0 lib/semantic_logger/jruby/garbage_collection_logger.rb
semantic_logger-2.17.0 lib/semantic_logger/jruby/garbage_collection_logger.rb
semantic_logger-2.16.0 lib/semantic_logger/jruby/garbage_collection_logger.rb