FileDocCategorySizeDatePackage
ProfilerImpl.javaAPI DocGlassfish v2 API5694Fri May 04 22:32:14 BST 2007com.sun.enterprise.util.diagnostics

ProfilerImpl

public class ProfilerImpl extends Object
Simple class for profiling code. beginItem/endItem pairs start and stop the timing for an item.
author
bnevins
version

Fields Summary
Item
currItem
List
items
int
numBegins
int
numEnds
int
numActualEnds
Constructors Summary
public ProfilerImpl()
Create an empty object

    
Methods Summary
public voidbeginItem()
Start timing an item.

		beginItem("No Description");
	
public voidbeginItem(java.lang.String desc)
Start timing an item.

param
desc - Descriptive text for the item

		//if(currItem != null)
			//Reporter.assert(currItem.hasEnded());
		
		currItem = new Item(desc);
		items.add(currItem);
		++numBegins;
	
public voidendItem()
Stop timing an item and store the information.

		++numEnds;
		Item item = getLastNotEnded();
		
		if(item != null)
			item.end();
		++numActualEnds;
	
private com.sun.enterprise.util.diagnostics.ProfilerImpl$ItemgetLastNotEnded()

		int index = items.size();
		
		while(--index >= 0)
		{
			Item item = (Item)items.get(index);
			
			if(!item.hasEnded())
				return item;
		}
		return null;
	
public static voidmain(java.lang.String[] notUsed)
Simple unit test

	
	////////////////////////////////////////////////////////////////////////////
	   	 
	    
	
		ProfilerImpl p = new ProfilerImpl();
		
		try
		{
			p.beginItem("first item");
			Thread.sleep(3000);
			p.beginItem("second item here dude whoa yowser yowser");
			Thread.sleep(1500);
			p.endItem();
			p.endItem();
			System.out.println("" + p);
		}
		catch(Exception e)
		{
		}
	
public voidreset()
Reset all the timing information

		currItem		= null;
		items.clear();
		numBegins		= 0;
		numEnds			= 0;
		numActualEnds	= 0;
	
public java.lang.StringtoString()
Return a formatted String with the timing information

		StringBuffer sb = new StringBuffer();
		sb.append("\nBegins: " + numBegins + ", Ends: " + numEnds + 
				", Actual Ends: " + numActualEnds + "\n");
		
		sb.append(Item.getHeader());
		sb.append("\n");

		
		for(Iterator iter = items.iterator(); iter.hasNext(); )
		{
			Item item = (Item)iter.next();
			sb.append(item.toString());
			sb.append("\n");
		}
		return sb.toString();