Class: SemanticLogger::JRuby::GarbageCollectionLogger
- Inherits:
-
Object
- Object
- SemanticLogger::JRuby::GarbageCollectionLogger
- Includes:
- Java::JavaxManagement::NotificationListener
- Defined in:
- lib/semantic_logger/jruby/garbage_collection_logger.rb
Instance Method Summary collapse
-
#handleNotification(notification, _) ⇒ Object
Must leave the method name as-is so that it can be found by Java.
-
#initialize(min_microseconds = 10_000) ⇒ GarbageCollectionLogger
constructor
Only log the garbage collection if the number of microseconds exceeds this value.
Constructor Details
#initialize(min_microseconds = 10_000) ⇒ GarbageCollectionLogger
Only log the garbage collection if the number of microseconds exceeds this value
8 9 10 |
# File 'lib/semantic_logger/jruby/garbage_collection_logger.rb', line 8 def initialize(min_microseconds = 10_000) @min_microseconds = min_microseconds end |
Instance Method Details
#handleNotification(notification, _) ⇒ Object
Must leave the method name as-is so that it can be found by Java
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/semantic_logger/jruby/garbage_collection_logger.rb', line 13 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 |