mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 08:37:25 -05:00
* Misc minor performance improvements * Use more concise loop syntax * Use more concise Collection sort syntax * Use StringUtils pad methods * Optimize some loops and double-map-lookups * Optimize array instantiation There are two styles to convert a collection to an array: either using a pre-sized array (like c.toArray(new String[c.size()])) or using an empty array (like c.toArray(new String[0]). In older Java versions using pre-sized array was recommended, as the reflection call which is necessary to create an array of proper size was quite slow. However since late updates of OpenJDK 6 this call was intrinsified, making the performance of the empty array version the same and sometimes even better, compared to the pre-sized version. Also passing pre-sized array is dangerous for a concurrent or synchronized collection as a data race is possible between the size and toArray call which may result in extra nulls at the end of the array, if the collection was concurrently shrunk during the operation. * Cleanup string concatenation * Use EnumMap where possible * Use FastMath instead of Math * Initialize complex things only once * Reduce method size to aloow more JIT inlining * remove map of short->float * Move field to local variable * Cleanup Map lookup Co-authored-by: Rob Ekl <xwq876@zebra.com>
86 lines
2.1 KiB
Java
86 lines
2.1 KiB
Java
package io.github.dsheirer.gui;
|
|
|
|
import io.github.dsheirer.controller.channel.Channel.ChannelType;
|
|
import io.github.dsheirer.controller.channel.ChannelEvent;
|
|
import io.github.dsheirer.controller.channel.ChannelEventListener;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import java.text.NumberFormat;
|
|
|
|
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:").append(mChannelCount);
|
|
sb.append(" TRFC:").append(mTrafficChannelCount);
|
|
sb.append(" PROC:").append(mChannelProcessingCount);
|
|
|
|
long maxMemory = runtime.maxMemory();
|
|
long allocatedMemory = runtime.totalMemory();
|
|
long freeMemory = runtime.freeMemory();
|
|
|
|
sb.append(" MEM FREE: ").append(format.format(freeMemory / 1024));
|
|
sb.append(" ALLOC: ").append(format.format(allocatedMemory / 1024));
|
|
sb.append(" MAX: ").append(format.format(maxMemory / 1024));
|
|
sb.append(" TOTAL: ").append(format.format((freeMemory + (maxMemory - allocatedMemory)) / 1024));
|
|
|
|
mLog.debug( sb.toString() );
|
|
}
|
|
|
|
@Override
|
|
public void channelChanged( ChannelEvent event )
|
|
{
|
|
switch( event.getEvent() )
|
|
{
|
|
case NOTIFICATION_ADD:
|
|
if( event.getChannel().getChannelType() == ChannelType.TRAFFIC )
|
|
{
|
|
mTrafficChannelCount++;
|
|
}
|
|
else
|
|
{
|
|
mChannelCount++;
|
|
}
|
|
break;
|
|
case NOTIFICATION_DELETE:
|
|
if( event.getChannel().getChannelType() == ChannelType.TRAFFIC )
|
|
{
|
|
mTrafficChannelCount--;
|
|
}
|
|
else
|
|
{
|
|
mChannelCount--;
|
|
}
|
|
break;
|
|
case REQUEST_DISABLE:
|
|
break;
|
|
case REQUEST_ENABLE:
|
|
break;
|
|
case NOTIFICATION_PROCESSING_START:
|
|
mChannelProcessingCount++;
|
|
break;
|
|
case NOTIFICATION_PROCESSING_STOP:
|
|
mChannelProcessingCount--;
|
|
break;
|
|
case NOTIFICATION_STATE_RESET:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|