FileDocCategorySizeDatePackage
AzureusCoreStats.javaAPI DocAzureus 3.0.3.413296Wed Mar 21 15:16:16 GMT 2007com.aelitis.azureus.core.stats

AzureusCoreStats

public class AzureusCoreStats extends Object

Fields Summary
public static final String
ST_ALL
public static final String
ST_DISK
public static final String
ST_DISK_READ_QUEUE_LENGTH
public static final String
ST_DISK_READ_QUEUE_BYTES
public static final String
ST_DISK_READ_REQUEST_COUNT
public static final String
ST_DISK_READ_REQUEST_SINGLE
public static final String
ST_DISK_READ_REQUEST_MULTIPLE
public static final String
ST_DISK_READ_REQUEST_BLOCKS
public static final String
ST_DISK_READ_BYTES_TOTAL
public static final String
ST_DISK_READ_BYTES_SINGLE
public static final String
ST_DISK_READ_BYTES_MULTIPLE
public static final String
ST_DISK_READ_IO_TIME
public static final String
ST_DISK_WRITE_QUEUE_LENGTH
public static final String
ST_DISK_WRITE_QUEUE_BYTES
public static final String
ST_DISK_WRITE_REQUEST_COUNT
public static final String
ST_DISK_WRITE_REQUEST_BLOCKS
public static final String
ST_DISK_WRITE_BYTES_TOTAL
public static final String
ST_DISK_WRITE_BYTES_SINGLE
public static final String
ST_DISK_WRITE_BYTES_MULTIPLE
public static final String
ST_DISK_WRITE_IO_TIME
public static final String
ST_NET_WRITE_CONTROL_WAIT_COUNT
public static final String
ST_NET_WRITE_CONTROL_NP_COUNT
public static final String
ST_NET_WRITE_CONTROL_P_COUNT
public static final String
ST_NET_WRITE_CONTROL_ENTITY_COUNT
public static final String
ST_NET_WRITE_CONTROL_CON_COUNT
public static final String
ST_NET_WRITE_CONTROL_READY_CON_COUNT
public static final String
ST_NET_WRITE_CONTROL_READY_BYTE_COUNT
public static final String
ST_NET_READ_CONTROL_LOOP_COUNT
public static final String
ST_NET_READ_CONTROL_NP_COUNT
public static final String
ST_NET_READ_CONTROL_P_COUNT
public static final String
ST_NET_READ_CONTROL_WAIT_COUNT
public static final String
ST_NET_READ_CONTROL_ENTITY_COUNT
public static final String
ST_NET_READ_CONTROL_CON_COUNT
public static final String
ST_NET_READ_CONTROL_READY_CON_COUNT
public static final String
ST_NET_TCP_OUT_CONNECT_QUEUE_LENGTH
public static final String
ST_NET_TCP_OUT_PENDING_QUEUE_LENGTH
public static final String
ST_NET_TCP_OUT_CANCEL_QUEUE_LENGTH
public static final String
ST_NET_TCP_OUT_CLOSE_QUEUE_LENGTH
public static final String
ST_NET_TCP_SELECT_WRITE_COUNT
public static final String
ST_NET_TCP_SELECT_READ_COUNT
public static final String
ST_PEER_CONTROL_LOOP_COUNT
public static final String
ST_PEER_CONTROL_YIELD_COUNT
public static final String
ST_PEER_CONTROL_WAIT_COUNT
public static final String
ST_PEER_CONTROL_WAIT_TIME
public static final String
ST_PEER_MANAGER_COUNT
public static final String
ST_PEER_MANAGER_PEER_COUNT
public static final String
ST_PEER_MANAGER_PEER_SNUBBED_COUNT
public static final String
ST_PEER_MANAGER_PEER_STALLED_DISK_COUNT
public static final String
POINT
public static final String
CUMULATIVE
private static final List
stats_names
private static final Map
stats_types
private static final String[]
_ST_ALL
private static final List
providers
private static Map
averages
private static boolean
enable_averages
private static org.gudy.azureus2.core3.util.Timer
average_timer
Constructors Summary
Methods Summary
public static voidaddStatsDefinitions(java.lang.String[][] stats)

	
	  
	
				 
	
		for (int i=0;i<stats.length;i++){
			
			String	name = stats[i][0];
			
			stats_names.add( name );
			
			stats_types.put( name, stats[i][1] );
		}
	
public static booleangetEnableAverages()

		return( enable_averages );
	
public static java.util.MapgetStats(java.util.Set types)

		Set	expanded = new HashSet();
		
		Iterator	it = types.iterator();
		
		while( it.hasNext()){
			
			String	type = (String)it.next();
			
			if ( !type.endsWith("*")){
				
				type = type + ".*";
			}
			
			Pattern pattern = Pattern.compile( type );
						
			for (int i=0;i<stats_names.size();i++){
				
				String	s = (String)stats_names.get(i);
				
				if ( pattern.matcher( s ).matches()){
					
					expanded.add( s );
				}
			}
		}
		
		Map	result = getStatsSupport( expanded );
		
		Map	ave = averages;
		
		if ( ave != null ){
			
			it = result.keySet().iterator();
			
			Map	ave_results = new HashMap();
			
			while( it.hasNext()){
								
				String	key = (String)it.next();
				
				Object[]	a_entry = (Object[])ave.get( key );
				
				if ( a_entry != null ){
					
					Average	average = (Average)a_entry[0];
					
					ave_results.put( key + ".average", new Long( average.getAverage()));
				}
			}
			
			result.putAll( ave_results );
		}
		
		return( result );
	
protected static java.util.MapgetStatsSupport(java.util.Set types)

		Map	result = new HashMap();
		
		for (int i=0;i<providers.size();i++){
			
			Object[]	provider_entry = (Object[])providers.get(i);
			
			Map	provider_result = new HashMap();

			Set	target_types;
			
			if ( types == null ){
				
				target_types = (Set)provider_entry[0];
			}else{
			
				target_types = types;
			}
			
			try{
				((AzureusCoreStatsProvider)provider_entry[1]).updateStats( target_types, provider_result );
				
				Iterator pit = provider_result.entrySet().iterator();
				
				while( pit.hasNext()){
					
					Map.Entry	pe = (Map.Entry)pit.next();
					
					String	key = (String)pe.getKey();
					Object	obj	= pe.getValue();
					
					if ( obj instanceof Long ){
						
						Long	old = (Long)result.get(key);
						
						if ( old == null ){
							
							result.put( key, obj );
							
						}else{
							
							long	v = ((Long)obj).longValue();
							
							result.put( key, new Long( v + old.longValue()));
						}
					}else{
						
						result.put( key, obj );
					}
				}
			}catch( Throwable e ){
				
				Debug.printStackTrace(e);
			}
		}
		
		return( result );
	
public static voidregisterProvider(java.util.Set types, AzureusCoreStatsProvider provider)

		synchronized( providers ){
			
			providers.add( new Object[]{ types, provider });
		}
	
public static synchronized voidsetEnableAverages(boolean enabled)

		if ( enabled == enable_averages ){
			
			return;
		}
		
		enable_averages = enabled;
		
		if ( enabled ){
			
			if ( average_timer == null ){
				
				average_timer = new Timer( "AzureusCoreStats:average" );
				
				averages = new HashMap();
				
				average_timer.addPeriodicEvent(
					1000,
					new TimerEventPerformer()
					{
						private Map	ave = averages;

						public void
						perform(
							TimerEvent	event )
						{
							Map	stats = getStatsSupport( null );
																
							Iterator	it = stats.entrySet().iterator();
							
							while( it.hasNext()){
								
								Map.Entry	entry = (Map.Entry)it.next();
								
								String	key 	= (String)entry.getKey();
								Object	value 	= entry.getValue();
								
								if ( value instanceof Long ){
									
									long	last_value;
									Average	a;
									
									Object[] a_entry = (Object[])ave.get( key );
									
									if ( a_entry == null ){
	
										a 			= Average.getInstance( 1000, 10 );
										last_value	= 0;
										
										a_entry = new Object[]{ a, value };
										
										ave.put( key, a_entry );
										
									}else{
										a			= (Average)a_entry[0];
										last_value	= ((Long)a_entry[1]).longValue();
									}
									
									if ( stats_types.get( key ) == CUMULATIVE ){
									
										a.addValue(((Long)value).longValue() - last_value);
										
									}else{
										
										a.addValue(((Long)value).longValue());

									}
									
									a_entry[1] = value;
								}
							}
						}
					});
			}
		}else{
			
			if ( average_timer != null ){
				
				average_timer.destroy();
				
				average_timer = null;
				
				averages	= null;
			}
		}