Adds logging capability for channel status and memory usage

This commit is contained in:
denny
2015-12-31 08:59:30 -05:00
parent b28193acb8
commit 81aff1cdef
2 changed files with 92 additions and 0 deletions

View File

@@ -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;
}
}
}

View File

@@ -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();
}
}