FileDocCategorySizeDatePackage
TransportStats.javaAPI DocAzureus 3.0.3.43695Thu Feb 09 19:42:54 GMT 2006com.aelitis.azureus.core.networkmanager.impl

TransportStats

public class TransportStats extends Object

Fields Summary
private static final int
PRINT_INTERVAL
private static final int
GRANULARITY
private final TreeMap
read_sizes
private final TreeMap
write_sizes
private long
total_reads
private long
total_writes
Constructors Summary
public TransportStats()

  
  
    
    Timer printer = new Timer("TransportStats:Printer");
    printer.addPeriodicEvent(
        PRINT_INTERVAL,
        new TimerEventPerformer() {
          public void perform( TimerEvent ev ) {
            printStats();
          }
        }
    );
  
Methods Summary
public voidbytesRead(int num_bytes_read)

    total_reads++;
    updateSizes( read_sizes, num_bytes_read );
  
public voidbytesWritten(int num_bytes_written)

    total_writes++;
    updateSizes( write_sizes, num_bytes_written );
  
private voidprintSizes(java.util.TreeMap size_map, long num_total)

    int prev_high = 1;
    
    for( Iterator it = size_map.entrySet().iterator(); it.hasNext(); ) {
      Map.Entry entry = (Map.Entry)it.next();
      int key = ((Integer)entry.getKey()).intValue();
      long count = ((Long)entry.getValue()).longValue();
      
      long percentage = (count *100) / num_total;
      
      if( key == 0 ) {   
        if( percentage > 3 ) {
          System.out.println( "[0 bytes]= x" +percentage+ "%" );
        }
      }
      else {
        int high = key * GRANULARITY;
        
        if( percentage > 3 ) {
          System.out.println( "[" +prev_high+ "-" +(high -1)+ " bytes]= x" +percentage+ "%" );
        }
        
        prev_high = high;
      }
    }
  
private voidprintStats()

    System.out.println( "\n------------------------------" );
    System.out.println( "***** TCP SOCKET READ SIZE STATS *****" );
    printSizes( read_sizes, total_reads );
    
    System.out.println( "\n***** TCP SOCKET WRITE SIZE STATS *****" );
    printSizes( write_sizes, total_writes );
    System.out.println( "------------------------------" );
  
private voidupdateSizes(java.util.TreeMap io_sizes, int num_bytes)

    Integer size_key;
    
    if( num_bytes == 0 ) {
      size_key = new Integer( 0 );
    }
    else {
      size_key = new Integer( (num_bytes / GRANULARITY) +1 );
    }
      
    Long count = (Long)io_sizes.get( size_key );
    
    if( count == null ) {
      io_sizes.put( size_key, new Long( 1 ) );
    }
    else {
      io_sizes.put( size_key, new Long( count.longValue() +1 ) );
    }