From 81aff1cdef71d6c7f1a9f83fb380663f6919a17f Mon Sep 17 00:00:00 2001 From: denny Date: Thu, 31 Dec 2015 08:59:30 -0500 Subject: [PATCH] Adds logging capability for channel status and memory usage --- src/gui/ChannelMemoryLogger.java | 78 ++++++++++++++++++++++++++++++++ src/gui/SDRTrunk.java | 14 ++++++ 2 files changed, 92 insertions(+) create mode 100644 src/gui/ChannelMemoryLogger.java diff --git a/src/gui/ChannelMemoryLogger.java b/src/gui/ChannelMemoryLogger.java new file mode 100644 index 00000000..9cf11951 --- /dev/null +++ b/src/gui/ChannelMemoryLogger.java @@ -0,0 +1,78 @@ +package gui; + +import java.text.NumberFormat; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import controller.channel.ChannelEvent; +import controller.channel.ChannelEventListener; + +public class ChannelMemoryLogger implements Runnable, ChannelEventListener +{ + private final static Logger mLog = LoggerFactory.getLogger( ChannelMemoryLogger.class ); + + public int mChannelCount; + public int mChannelProcessingCount; + public int mTrafficChannelCount; + + @Override + public void run() + { + final Runtime runtime = Runtime.getRuntime(); + + final NumberFormat format = NumberFormat.getInstance(); + + StringBuilder sb = new StringBuilder(); + + sb.append( "CHAN TOT:" + mChannelCount ); + sb.append( " TRFC:" + mTrafficChannelCount ); + sb.append( " PROC:" + mChannelProcessingCount ); + + long maxMemory = runtime.maxMemory(); + long allocatedMemory = runtime.totalMemory(); + long freeMemory = runtime.freeMemory(); + + sb.append(" MEM FREE: " + format.format(freeMemory / 1024) ); + sb.append(" ALLOC: " + format.format(allocatedMemory / 1024) ); + sb.append(" MAX: " + format.format(maxMemory / 1024) ); + sb.append(" TOTAL: " + format.format((freeMemory + (maxMemory - allocatedMemory)) / 1024) ); + + mLog.debug( sb.toString() ); + } + + @Override + public void channelChanged( ChannelEvent event ) + { + switch( event.getEvent() ) + { + case CHANNEL_ADDED: + mChannelCount++; + break; + case CHANNEL_DELETED: + mChannelCount--; + break; + case CHANNEL_DISABLED: + break; + case CHANNEL_ENABLED: + break; + case CHANNEL_PROCESSING_STARTED: + mChannelProcessingCount++; + break; + case CHANNEL_PROCESSING_STOPPED: + mChannelProcessingCount--; + break; + case CHANNEL_STATE_RESET: + break; + case TRAFFIC_CHANNEL_ADDED: + mTrafficChannelCount++; + break; + case TRAFFIC_CHANNEL_DELETED: + mTrafficChannelCount--; + break; + default: + break; + + } + } +} diff --git a/src/gui/SDRTrunk.java b/src/gui/SDRTrunk.java index 1eae1b7b..14470aee 100644 --- a/src/gui/SDRTrunk.java +++ b/src/gui/SDRTrunk.java @@ -32,6 +32,7 @@ import java.io.InputStreamReader; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; +import java.util.concurrent.TimeUnit; import javax.imageio.ImageIO; import javax.swing.JFrame; @@ -62,6 +63,8 @@ import com.jidesoft.swing.JideSplitPane; import controller.ConfigurationControllerModel; import controller.ControllerPanel; import controller.ResourceManager; +import controller.ThreadPoolManager.ThreadType; +import controller.channel.ChannelEventListener; import controller.channel.ChannelManager; public class SDRTrunk @@ -73,6 +76,8 @@ public class SDRTrunk private JFrame mMainGui = new JFrame(); private String mTitle; + + private boolean mLogChannelAndMemoryUsage = false; public SDRTrunk() { @@ -127,6 +132,14 @@ public class SDRTrunk initGUI(); mLog.info( "starting main application gui" ); + + if( mLogChannelAndMemoryUsage ) + { + Runnable cml = new ChannelMemoryLogger(); + resource.getChannelManager().addListener( (ChannelEventListener)cml ); + resource.getThreadPoolManager().scheduleFixedRate( + ThreadType.DECODER, cml, 5, TimeUnit.SECONDS ); + } //Start the gui EventQueue.invokeLater( new Runnable() @@ -419,4 +432,5 @@ public class SDRTrunk return sb.toString(); } + }