mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-17 11:07:35 -05:00
Adds logging capability for channel status and memory usage
This commit is contained in:
78
src/gui/ChannelMemoryLogger.java
Normal file
78
src/gui/ChannelMemoryLogger.java
Normal 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;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,6 +32,7 @@ import java.io.InputStreamReader;
|
|||||||
import java.nio.file.FileSystems;
|
import java.nio.file.FileSystems;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
@@ -62,6 +63,8 @@ import com.jidesoft.swing.JideSplitPane;
|
|||||||
import controller.ConfigurationControllerModel;
|
import controller.ConfigurationControllerModel;
|
||||||
import controller.ControllerPanel;
|
import controller.ControllerPanel;
|
||||||
import controller.ResourceManager;
|
import controller.ResourceManager;
|
||||||
|
import controller.ThreadPoolManager.ThreadType;
|
||||||
|
import controller.channel.ChannelEventListener;
|
||||||
import controller.channel.ChannelManager;
|
import controller.channel.ChannelManager;
|
||||||
|
|
||||||
public class SDRTrunk
|
public class SDRTrunk
|
||||||
@@ -73,6 +76,8 @@ public class SDRTrunk
|
|||||||
private JFrame mMainGui = new JFrame();
|
private JFrame mMainGui = new JFrame();
|
||||||
|
|
||||||
private String mTitle;
|
private String mTitle;
|
||||||
|
|
||||||
|
private boolean mLogChannelAndMemoryUsage = false;
|
||||||
|
|
||||||
public SDRTrunk()
|
public SDRTrunk()
|
||||||
{
|
{
|
||||||
@@ -127,6 +132,14 @@ public class SDRTrunk
|
|||||||
initGUI();
|
initGUI();
|
||||||
|
|
||||||
mLog.info( "starting main application gui" );
|
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
|
//Start the gui
|
||||||
EventQueue.invokeLater( new Runnable()
|
EventQueue.invokeLater( new Runnable()
|
||||||
@@ -419,4 +432,5 @@ public class SDRTrunk
|
|||||||
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user