Class MemoryLogger

java.lang.Object
java.lang.Thread
org.apache.flink.runtime.taskmanager.MemoryLogger
All Implemented Interfaces:
Runnable

public class MemoryLogger extends Thread
A thread the periodically logs statistics about:
  • Heap and non-heap memory usage
  • Memory pools and pool usage
  • Garbage collection times and counts
  • Constructor Details

    • MemoryLogger

      public MemoryLogger(org.slf4j.Logger logger, long interval, CompletableFuture<Void> monitored)
      Creates a new memory logger that logs in the given interval and lives until the given termination future completes.
      Parameters:
      logger - The logger to use for outputting the memory statistics.
      interval - The interval in which the thread logs.
      monitored - termination future for the system to whose life the thread is bound. The thread terminates once the system terminates.
  • Method Details

    • startIfConfigured

      public static void startIfConfigured(org.slf4j.Logger logger, org.apache.flink.configuration.Configuration configuration, CompletableFuture<Void> taskManagerTerminationFuture)
    • shutdown

      public void shutdown()
    • run

      public void run()
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • getMemoryUsageStatsAsString

      public static String getMemoryUsageStatsAsString(MemoryMXBean memoryMXBean)
      Gets the memory footprint of the JVM in a string representation.
      Returns:
      A string describing how much heap memory and direct memory are allocated and used.
    • getDirectMemoryStatsAsString

      public static String getDirectMemoryStatsAsString(BufferPoolMXBean bufferPoolMxBean)
      Returns a String with the direct memory footprint.

      These stats are not part of the other memory beans.

      Parameters:
      bufferPoolMxBean - The direct buffer pool bean or null if none available.
      Returns:
      A string with the count, total capacity, and used direct memory.
    • getMemoryPoolStatsAsString

      public static String getMemoryPoolStatsAsString(List<MemoryPoolMXBean> poolBeans)
      Gets the memory pool statistics from the JVM.
      Parameters:
      poolBeans - The collection of memory pool beans.
      Returns:
      A string denoting the names and sizes of the memory pools.
    • getGarbageCollectorStatsAsString

      public static String getGarbageCollectorStatsAsString(List<GarbageCollectorMXBean> gcMXBeans)
      Gets the garbage collection statistics from the JVM.
      Parameters:
      gcMXBeans - The collection of garbage collector beans.
      Returns:
      A string denoting the number of times and total elapsed time in garbage collection.