Sha256: 6b6a9931d56bbdc960b51c37f292057db9cecf5ca1abb143a34f6cc13ac9e7ba

Contents?: true

Size: 1.09 KB

Versions: 17

Compression:

Stored size: 1.09 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 = 10_000)
        @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
        unless notification.get_type == Java::ComSunManagement::GarbageCollectionNotificationInfo::GARBAGE_COLLECTION_NOTIFICATION
          return
        end

        info     = Java::ComSunManagement::GarbageCollectionNotificationInfo.from(notification.user_data)
        gc_info  = info.gc_info
        duration = gc_info.duration

        return unless duration >= @min_microseconds

        SemanticLogger["GarbageCollector"].measure_warn(
          "Garbage Collection completed: #{info.gc_name} ##{gc_info.id}",
          duration: duration.to_f / 1000
        )
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
semantic_logger-4.16.1 lib/semantic_logger/jruby/garbage_collection_logger.rb
semantic_logger-4.16.0 lib/semantic_logger/jruby/garbage_collection_logger.rb
semantic_logger-4.15.0 lib/semantic_logger/jruby/garbage_collection_logger.rb
semantic_logger-4.14.0 lib/semantic_logger/jruby/garbage_collection_logger.rb
semantic_logger-4.13.0 lib/semantic_logger/jruby/garbage_collection_logger.rb
semantic_logger-4.12.0 lib/semantic_logger/jruby/garbage_collection_logger.rb
semantic_logger-4.11.0 lib/semantic_logger/jruby/garbage_collection_logger.rb
semantic_logger-4.10.0 lib/semantic_logger/jruby/garbage_collection_logger.rb
semantic_logger-4.9.0 lib/semantic_logger/jruby/garbage_collection_logger.rb
semantic_logger-4.8.2 lib/semantic_logger/jruby/garbage_collection_logger.rb
semantic_logger-4.8.1 lib/semantic_logger/jruby/garbage_collection_logger.rb
semantic_logger-4.8.0 lib/semantic_logger/jruby/garbage_collection_logger.rb
semantic_logger-4.7.4 lib/semantic_logger/jruby/garbage_collection_logger.rb
semantic_logger-4.7.3 lib/semantic_logger/jruby/garbage_collection_logger.rb
semantic_logger-4.7.2 lib/semantic_logger/jruby/garbage_collection_logger.rb
semantic_logger-4.7.1 lib/semantic_logger/jruby/garbage_collection_logger.rb
semantic_logger-4.7.0 lib/semantic_logger/jruby/garbage_collection_logger.rb