[jboss-cvs] JBoss Profiler SVN: r479 - in branches/JBossProfiler2/src/main/org/jboss/profiler: ui and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Oct 5 21:44:48 EDT 2008


Author: Huijuan Shao
Date: 2008-10-05 21:44:47 -0400 (Sun, 05 Oct 2008)
New Revision: 479

Added:
   branches/JBossProfiler2/src/main/org/jboss/profiler/ui/
   branches/JBossProfiler2/src/main/org/jboss/profiler/ui/BasicOptBean.java
   branches/JBossProfiler2/src/main/org/jboss/profiler/ui/ClassBean.java
   branches/JBossProfiler2/src/main/org/jboss/profiler/ui/CompareSnapshotBean.java
   branches/JBossProfiler2/src/main/org/jboss/profiler/ui/LoadSnapshotBean.java
   branches/JBossProfiler2/src/main/org/jboss/profiler/ui/MethodBean.java
   branches/JBossProfiler2/src/main/org/jboss/profiler/ui/OverviewBean.java
   branches/JBossProfiler2/src/main/org/jboss/profiler/ui/ThreadHotspotBean.java
   branches/JBossProfiler2/src/main/org/jboss/profiler/ui/TreeFrameBean.java
   branches/JBossProfiler2/src/main/org/jboss/profiler/ui/TreeThreadBean.java
   branches/JBossProfiler2/src/main/org/jboss/profiler/ui/util/
   branches/JBossProfiler2/src/main/org/jboss/profiler/ui/util/PostbackPhaseListener.java
   branches/JBossProfiler2/src/main/org/jboss/profiler/ui/util/Profiler.java
   branches/JBossProfiler2/src/main/org/jboss/profiler/ui/util/SnapshotUtility.java
   branches/JBossProfiler2/src/main/org/jboss/profiler/ui/util/TreeDemoStateAdvisor.java
Log:


Added: branches/JBossProfiler2/src/main/org/jboss/profiler/ui/BasicOptBean.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/ui/BasicOptBean.java	                        (rev 0)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/ui/BasicOptBean.java	2008-10-06 01:44:47 UTC (rev 479)
@@ -0,0 +1,184 @@
+package org.jboss.profiler.ui;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.faces.model.SelectItem;
+
+import org.jboss.profiler.agent.Agent;
+import org.jboss.profiler.shared.Snapshot;
+import org.jboss.profiler.shared.SnapshotHelper;
+import org.jboss.profiler.ui.util.Profiler;
+/**
+ at author Huijuan Shao <hjshao at hitachi.cn>
+*/
+public class BasicOptBean {
+	Profiler profiler1=new Profiler();
+	boolean start=profiler1.isRunning();
+	boolean enabled=Agent.isEnabled();
+	String lastestOpts="";
+	private String addClass;
+	private String visibility;
+	private String removeClass;
+	private String selectSnapshot;
+	private String saveSnapshotName;
+	private boolean panelShows=false;
+	private String saveEcho="";
+	
+	public boolean isStart() {
+		return start;
+	}
+	public void setStart(boolean start) {
+		this.start = start;
+	}
+	public boolean isEnabled() {
+		return enabled;
+	}
+	public void setEnabled(boolean enabled) {
+		this.enabled = enabled;
+	}
+	public String getLastestOpts() {
+		return lastestOpts;
+	}
+	public void setLastestOpts(String lastestOpts) {
+		this.lastestOpts = lastestOpts;
+	}
+	public String getAddClass() {
+		return addClass;
+	}
+	public void setAddClass(String addClass) {
+		this.addClass = addClass;
+	}
+	public String getVisibility() {
+		return visibility;
+	}
+	public void setVisibility(String visibility) {
+		this.visibility = visibility;
+	}
+	public String getRemoveClass() {
+		return removeClass;
+	}
+	public void setRemoveClass(String removeClass) {
+		this.removeClass = removeClass;
+	}
+	public String getSelectSnapshot() {
+		return selectSnapshot;
+	}
+	public void setSelectSnapshot(String selectSnapshot) {
+		this.selectSnapshot = selectSnapshot;
+	}
+	public String getSaveSnapshotName() {
+		return saveSnapshotName;
+	}
+	public void setSaveSnapshotName(String saveSnapshotName) {
+		this.saveSnapshotName = saveSnapshotName;
+	}
+	public boolean isPanelShows() {
+		return panelShows;
+	}
+	public void setPanelShows(boolean panelShows) {
+		this.panelShows = panelShows;
+	}
+	public String getSaveEcho() {
+		return saveEcho;
+	}
+	public void setSaveEcho(String saveEcho) {
+		this.saveEcho = saveEcho;
+	}
+	
+	public void clickStart(){
+		//start or stop, the profiler should be enabled.
+		if(Agent.isEnabled()){
+			if(this.start==false){
+				setStart(true);
+				this.setLastestOpts("Profiler has started.");
+				profiler1.startProfiler();
+			}else{
+				setStart(false);
+				this.setLastestOpts("Profiler has stopped.");
+				profiler1.stopProfiler();
+			}
+		}
+	}
+	public void clickEnable(){
+		if(this.enabled==false && !Agent.isEnabled()){
+				this.setEnabled(true);
+				this.setLastestOpts("Profiler has enabled.");
+				profiler1.enableProfiler();
+		}else if(this.enabled==true && Agent.isEnabled()){
+				this.setEnabled(false);
+				this.setLastestOpts("Profiler has disabled.");
+				profiler1.stopProfiler();
+				profiler1.disableProfiler();
+		}
+	}
+	public void clearSnapshot(){
+		//this.setLastestOpts("clear all snapshots.");
+		profiler1.clearSnapshots();
+		this.setPanelShows(false);
+	}
+	public void gc(){
+		if(Agent.isEnabled()){
+			this.setLastestOpts("begins garbage collection.");
+			org.jboss.profiler.agent.Profiler.garbageCollection();
+		}
+	}
+	
+	public void takeSnapshot(){
+		org.jboss.profiler.agent.Profiler.snapshot();
+		//this.setLastestOpts("take snapshot.");
+		this.setPanelShows(false);
+	}
+	
+	public String[] getSnapshots(){
+		String[] snapshots=org.jboss.profiler.agent.Profiler.listSnapshots();
+		return snapshots;
+	}
+	
+	public void selectSnapshotAction(){
+		this.setPanelShows(true);
+	}
+	
+	public void selectSaveSnapshotAction(){
+		String[] snapshots=this.getSnapshots();
+		int k=0;
+		for(int i=0;i<snapshots.length;i++){
+			if(snapshots[i].equals(this.selectSnapshot))
+				k=i;
+		}
+		Snapshot selectSnapshot1=org.jboss.profiler.agent.Profiler.getSnapshot(k);
+		try {
+			if(this.saveSnapshotName=="")
+				SnapshotHelper.save(selectSnapshot1);
+			else
+				SnapshotHelper.save(selectSnapshot1, new File(this.saveSnapshotName));
+			
+			this.saveEcho="snapshot "+this.saveSnapshotName+" is just saved!";
+			this.saveSnapshotName="";
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+		
+	public List<SelectItem> getVisibilities(){
+		List<SelectItem> allSelectItems=null;
+		allSelectItems=new ArrayList<SelectItem>(4);
+		allSelectItems.add(new SelectItem("public"));
+		allSelectItems.add(new SelectItem("package"));
+		allSelectItems.add(new SelectItem("protected"));
+		allSelectItems.add(new SelectItem("private"));
+		return allSelectItems;
+	}
+	
+	public void addClassAction(){
+		Profiler profiler=new Profiler();
+		profiler.addClasses(this.addClass, this.visibility);
+	}
+	
+	public void removeClassAction(){
+		Profiler profiler=new Profiler();
+		profiler.removeClasses(this.removeClass);
+	}
+}


Property changes on: branches/JBossProfiler2/src/main/org/jboss/profiler/ui/BasicOptBean.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/JBossProfiler2/src/main/org/jboss/profiler/ui/ClassBean.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/ui/ClassBean.java	                        (rev 0)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/ui/ClassBean.java	2008-10-06 01:44:47 UTC (rev 479)
@@ -0,0 +1,177 @@
+package org.jboss.profiler.ui;
+
+import java.text.DecimalFormat;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.profiler.client.CombinedFrameComparator;
+import org.jboss.profiler.client.CombinedFrameInfo;
+import org.jboss.profiler.client.TimedClassComparator;
+import org.jboss.profiler.client.TimedClassInfo;
+import org.jboss.profiler.client.Util;
+import org.jboss.profiler.shared.AllocationInfo;
+import org.jboss.profiler.shared.Math;
+import org.jboss.profiler.shared.Snapshot;
+import org.jboss.profiler.ui.util.SnapshotUtility;
+
+/**
+ at author Huijuan Shao <hjshao at hitachi.cn>
+*/
+public class ClassBean {
+	private String className;
+	private String type;
+	private String totalTime;
+	private String waitTime;
+	long allocCount;
+	private String selectedClass="";
+	
+	private Map<String, List<CombinedFrameInfo>> info=null;
+	private List<TimedClassInfo> classes=null;
+	
+	//the class info in which the methods will be shown.
+	
+	public ClassBean(String className,String type, String totalTime) {
+		super();
+		this.className = className;
+		this.totalTime = totalTime;
+		this.type = type;
+		this.waitTime="";
+		this.allocCount=-1;
+	}
+	
+	public ClassBean(String className,String type, String totalTime,String waitTime, long allocations) {
+		super();
+		this.className = className;
+		this.totalTime = totalTime;
+		this.type = type;
+		this.waitTime=waitTime;
+		this.allocCount=allocations;
+	}
+	
+	public ClassBean() {
+		super();
+		// TODO Auto-generated constructor stub
+	}
+	public String getClassName() {
+		return className;
+	}
+	public void setClassName(String className) {
+		this.className = className;
+	}
+	public String getType() {
+		return type;
+	}
+	public void setType(String type) {
+		this.type = type;
+	}
+	public String getTotalTime() {
+		return totalTime;
+	}
+	public void setTotalTime(String totalTime) {
+		this.totalTime = totalTime;
+	}
+
+	public String getWaitTime() {
+		return waitTime;
+	}
+	public void setWaitTime(String waitTime) {
+		this.waitTime = waitTime;
+	}
+
+	public long getAllocCount() {
+		return allocCount;
+	}
+	public void setAllocCount(long allocCount) {
+		this.allocCount = allocCount;
+	}
+
+	private long getAllocations(TimedClassInfo tci, List<AllocationInfo> allocs){
+			String prettyClassName = Util.getPrettyName(tci);
+			long alloc = 0;
+			    
+			if (allocs != null && allocs.size() > 0) {
+	
+			boolean found = false;
+	
+			for (int i = 0; !found && i < allocs.size(); i++) {
+				AllocationInfo ai = allocs.get(i);
+			    if (ai.getClassName().equals(prettyClassName)) {
+			    	alloc = ai.getCount();
+			        found = true;
+			    }
+			 }
+		  }
+		  return alloc;
+	  }
+	
+	public String getSelectedClass() {
+		return selectedClass;
+	}
+
+	public void setSelectedClass(String selectedClass) {
+		this.selectedClass = selectedClass;
+	}
+
+	
+	
+	public Set<String> getAjaxRowKeys(){
+		ClassBean[] clazz=this.getClasses();
+		Set<String> keys=new HashSet<String>();
+		for(int i=0;i<clazz.length;i++){
+			keys.add(clazz[i].className);
+		}
+		return keys;
+	}
+	
+	public void fireMethodsInfo(){
+		//Maybe this part needs to integrate with getClasses to keep accord with snapshot.    
+	    TimedClassInfo selectedTimedClassInfo=null,tmpTimedClassInfo=null;
+	    String tmpString;
+	    if(this.classes!=null){
+		    for(int i=0;i<classes.size();i++){
+		    	tmpTimedClassInfo=(TimedClassInfo)(classes.get(i));
+		    	tmpString=tmpTimedClassInfo.getClassName();
+		    	//have to replace / with .
+		    	tmpString=tmpString.replace('/', '.');
+		    	if(this.getSelectedClass().equals(tmpString)) {
+		    		selectedTimedClassInfo=tmpTimedClassInfo;	
+		    		break;
+		    	}
+		    }
+	    }
+
+	    MethodBean.setTci(selectedTimedClassInfo);
+	    List<CombinedFrameInfo> l = info.get(selectedTimedClassInfo.getClassName());
+	    MethodBean.setCfs(l);
+	}
+	public ClassBean[] getClasses(){
+		ClassBean[] classBeans=null;
+		
+		if(LoadSnapshotBean.getSnapshot()!=null){
+			DecimalFormat df = new DecimalFormat("#0.00");
+			SnapshotUtility su=new SnapshotUtility();
+		    Map<String, List<CombinedFrameInfo>> info = su.getInformation(LoadSnapshotBean.getSnapshot());
+	    
+		    List<TimedClassInfo> classes = su.getTimedClasses(LoadSnapshotBean.getSnapshot().getClasses(), info);
+		    
+		    this.info=info;
+		    this.classes=classes;
+			
+		    Collections.sort(classes, new TimedClassComparator(TimedClassComparator.NAME));
+		    
+		    int j=0;
+		    long tmpCount=0;
+		    classBeans=new ClassBean[classes.size()];
+		    
+		    for (TimedClassInfo tci: classes) {
+		    	tmpCount=this.getAllocations(tci, LoadSnapshotBean.getSnapshot().getAllocations());
+		    	classBeans[j++]=new ClassBean(Util.getPrettyName(tci),Util.getDescription(tci),
+		    			df.format(tci.getTotalTime()), df.format(tci.getWaitTime()),tmpCount);
+		    }	   
+		}
+		return classBeans;
+	}
+}


Property changes on: branches/JBossProfiler2/src/main/org/jboss/profiler/ui/ClassBean.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/JBossProfiler2/src/main/org/jboss/profiler/ui/CompareSnapshotBean.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/ui/CompareSnapshotBean.java	                        (rev 0)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/ui/CompareSnapshotBean.java	2008-10-06 01:44:47 UTC (rev 479)
@@ -0,0 +1,238 @@
+package org.jboss.profiler.ui;
+
+import java.io.File;
+import java.io.IOException;
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.model.SelectItem;
+
+import org.jboss.profiler.client.CombinedFrameComparator;
+import org.jboss.profiler.client.CombinedFrameInfo;
+import org.jboss.profiler.client.TimedClassInfo;
+import org.jboss.profiler.shared.Snapshot;
+import org.jboss.profiler.shared.SnapshotHelper;
+import org.jboss.profiler.ui.util.SnapshotUtility;
+
+/**
+ at author Huijuan Shao <hjshao at hitachi.cn>
+*/
+public class CompareSnapshotBean {
+	private String[] snapshotsToCompare=new String[2];
+	
+	CompareSnapshotBean[] compareSnapshotBeans;
+	
+	private String difftime;
+	
+	private String oTime;
+	
+	private String nTime;
+	
+	private long diffCount;
+	
+	private long oCount;
+	private long nCount;
+	private String methodName;
+	
+	public CompareSnapshotBean(){}
+	
+	public CompareSnapshotBean(String difftime,String oTime,String nTime,long diffCount,long oCount,long nCount, String methodName){
+		this.difftime=difftime;
+		this.oTime=oTime;
+		this.nTime=nTime;
+		this.diffCount=diffCount;
+		this.oCount=oCount;
+		this.nCount=nCount;
+		this.methodName=methodName;
+	}
+	
+	public String getDifftime() {
+		return difftime;
+	}
+	public void setDifftime(String difftime) {
+		this.difftime = difftime;
+	}
+	public String getOTime() {
+		return oTime;
+	}
+	public void setOTime(String time) {
+		oTime = time;
+	}
+	public String getNTime() {
+		return nTime;
+	}
+	public void setNTime(String time) {
+		nTime = time;
+	}
+	public long getDiffCount() {
+		return diffCount;
+	}
+	public void setDiffCount(long diffCount) {
+		this.diffCount = diffCount;
+	}
+	public long getOCount() {
+		return oCount;
+	}
+	public void setOCount(long count) {
+		oCount = count;
+	}
+	public long getNCount() {
+		return nCount;
+	}
+	public void setNCount(long count) {
+		nCount = count;
+	}
+	public String getMethodName() {
+		return methodName;
+	}
+	public void setMethodName(String methodName) {
+		this.methodName = methodName;
+	}
+	public CompareSnapshotBean[] getCompareSnapshotBeans() {
+		return compareSnapshotBeans;
+	}
+	public String[] getSnapshotsToCompare() {
+		return snapshotsToCompare;
+	}
+	public void setSnapshotsToCompare(String[] snapshotsToCompare) {
+		this.snapshotsToCompare = snapshotsToCompare;
+	}
+	
+	public List<SelectItem> getJPSs(){
+		List<SelectItem> allSelectItems=null;
+		File tempFile=new File(".");
+		String[] fileStr=tempFile.list();
+		List<String> jpsFiles=new ArrayList<String>();
+		allSelectItems=new ArrayList<SelectItem>();
+		for(int i=0;i<fileStr.length;i++){
+			if(fileStr[i].endsWith("jps")){
+				jpsFiles.add(fileStr[i]);
+				allSelectItems.add(new SelectItem(fileStr[i]));
+			}
+		}
+		
+		return allSelectItems;
+	}
+	
+	public void analyzeAction() throws Exception{
+		File file1=new File(this.snapshotsToCompare[0]);
+		File file2=new File(this.snapshotsToCompare[1]);
+		
+
+		try {
+			Snapshot os= SnapshotHelper.load(file1);
+
+			Snapshot ns = SnapshotHelper.load(file2);
+
+			SnapshotUtility su=new SnapshotUtility(); 
+		
+			Map<String, List<CombinedFrameInfo>> oInfo = su.getInformation(os);
+
+			Map<String, List<CombinedFrameInfo>> nInfo = su.getInformation(ns);
+			
+			compareSnapshotBeans= this.compareMethods(oInfo, nInfo);
+			
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+	}
+	
+	private CompareSnapshotBean[] compareMethods(Map<String, List<CombinedFrameInfo>> oInfo, Map<String, List<CombinedFrameInfo>> nInfo) throws Exception {
+
+		  	List<CombinedFrameInfo> methods = new ArrayList<CombinedFrameInfo>();
+		  	Map<String, CombinedFrameInfo> oMap = new HashMap<String, CombinedFrameInfo>();
+		  	Map<String, CombinedFrameInfo> nMap = new HashMap<String, CombinedFrameInfo>();
+
+		  	Map<String, CombinedFrameInfo> tMap = new HashMap<String, CombinedFrameInfo>();
+
+			Iterator it = oInfo.values().iterator();
+			while (it.hasNext()) {
+				List<CombinedFrameInfo> l = (List<CombinedFrameInfo>)it.next();
+				for (CombinedFrameInfo cfi : l) {
+					oMap.put(cfi.getPrettyName(), cfi);
+					tMap.put(cfi.getPrettyName(), cfi);
+				}
+			}
+			
+			it = nInfo.values().iterator();
+			while (it.hasNext()) {
+				List<CombinedFrameInfo> l = (List<CombinedFrameInfo>)it.next();
+				for (CombinedFrameInfo cfi : l) {
+						nMap.put(cfi.getPrettyName(), cfi);
+				}
+			}
+				
+			it = nMap.entrySet().iterator();
+			while (it.hasNext()) {
+				Map.Entry entry = (Map.Entry)it.next();
+				String key = (String)entry.getKey();
+				CombinedFrameInfo cfi = (CombinedFrameInfo)entry.getValue();
+				
+				double oTime = 0.0;
+				long oCount = 0;
+				if (oMap.containsKey(key)) {
+					CombinedFrameInfo oCfi = oMap.get(key);
+					oTime = oCfi.getTotalTime();
+					oCount = oCfi.getCount();
+					tMap.remove(key);
+				}
+				
+				CombinedFrameInfo c = new CombinedFrameInfo(cfi.getClassName(), cfi.getPrettyName());
+				c.increaseTotalTime(cfi.getTotalTime() - oTime);
+				c.increaseCount(cfi.getCount() - oCount);
+				
+				methods.add(c);
+			}
+			
+			it = tMap.entrySet().iterator();
+			while (it.hasNext()) {
+				Map.Entry entry = (Map.Entry)it.next();
+				String key = (String)entry.getKey();
+				CombinedFrameInfo cfi = (CombinedFrameInfo)entry.getValue();
+				
+				CombinedFrameInfo c = new CombinedFrameInfo(cfi.getClassName(), cfi.getPrettyName());
+				c.increaseTotalTime(-cfi.getTotalTime());
+				c.increaseCount(-cfi.getCount());
+				
+				methods.add(c);
+			}
+
+			Collections.sort(methods, new CombinedFrameComparator(CombinedFrameComparator.TOTAL_TIME));
+			Collections.reverse(methods);
+		
+			DecimalFormat df = new DecimalFormat("#0.00");
+			
+			this.compareSnapshotBeans=new CompareSnapshotBean[methods.size()];
+			
+			for (int i = 0; i < methods.size(); i++) {
+				CombinedFrameInfo h = methods.get(i);
+				CombinedFrameInfo o = oMap.get(h.getPrettyName());
+				CombinedFrameInfo n = nMap.get(h.getPrettyName());
+				
+				double oTime = 0.0;
+				long oCount = 0;
+				if (o != null) {
+					oTime = o.getTotalTime();
+					oCount = o.getCount();
+				}
+				
+				double nTime = 0.0;
+				long nCount = 0;
+				if (n != null) {
+					nTime = n.getTotalTime();
+					nCount = n.getCount();
+				}
+					
+				compareSnapshotBeans[i]=new CompareSnapshotBean(df.format(h.getTotalTime()),df.format(oTime),
+							df.format(nTime),h.getCount(),oCount,nCount,h.getPrettyName());
+				}
+				
+				return compareSnapshotBeans;
+			}
+}


Property changes on: branches/JBossProfiler2/src/main/org/jboss/profiler/ui/CompareSnapshotBean.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/JBossProfiler2/src/main/org/jboss/profiler/ui/LoadSnapshotBean.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/ui/LoadSnapshotBean.java	                        (rev 0)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/ui/LoadSnapshotBean.java	2008-10-06 01:44:47 UTC (rev 479)
@@ -0,0 +1,61 @@
+package org.jboss.profiler.ui;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.faces.model.SelectItem;
+
+import org.jboss.profiler.shared.Snapshot;
+import org.jboss.profiler.shared.SnapshotHelper;
+
+/**
+ at author Huijuan Shao <hjshao at hitachi.cn>
+*/
+public class LoadSnapshotBean {
+	private String snapshotToLoad;	
+	private static Snapshot snapshot=null;
+
+	public static Snapshot getSnapshot() {
+		return snapshot;
+	}
+
+	public static void setSnapshot(Snapshot snapshot) {
+		LoadSnapshotBean.snapshot = snapshot;
+	}
+
+	public String getSnapshotToLoad() {
+		return snapshotToLoad;
+	}
+	public void setSnapshotToLoad(String snapshotToLoad) {
+		this.snapshotToLoad = snapshotToLoad;
+	}
+
+	public List<SelectItem> getJPSs(){
+		List<SelectItem> allSelectItems=null;
+		File tempFile=new File(".");
+		String[] fileStr=tempFile.list();
+		List<String> jpsFiles=new ArrayList<String>();
+		allSelectItems=new ArrayList<SelectItem>();
+		for(int i=0;i<fileStr.length;i++){
+			if(fileStr[i].endsWith("jps")){
+				jpsFiles.add(fileStr[i]);
+				allSelectItems.add(new SelectItem(fileStr[i]));
+			}
+		}	
+		return allSelectItems;
+	}
+	
+	public void analyzeAction(){
+		File file=new File(this.snapshotToLoad);
+		Snapshot snapshot;
+		try {
+			snapshot = SnapshotHelper.load(file);
+			LoadSnapshotBean.setSnapshot(snapshot); 
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+	}
+}


Property changes on: branches/JBossProfiler2/src/main/org/jboss/profiler/ui/LoadSnapshotBean.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/JBossProfiler2/src/main/org/jboss/profiler/ui/MethodBean.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/ui/MethodBean.java	                        (rev 0)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/ui/MethodBean.java	2008-10-06 01:44:47 UTC (rev 479)
@@ -0,0 +1,135 @@
+package org.jboss.profiler.ui;
+
+import java.text.DecimalFormat;
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.profiler.client.CombinedFrameComparator;
+import org.jboss.profiler.client.CombinedFrameInfo;
+import org.jboss.profiler.client.TimedClassInfo;
+import org.jboss.profiler.shared.Math;
+
+/**
+ at author Huijuan Shao <hjshao at hitachi.cn>
+*/
+public class MethodBean {
+	private long count;
+	private String totalTime;
+	private String cPercent;
+	private String tPercent;
+	private String prettyName;
+	
+	private MethodBean[] methods=null;
+	
+	//the class info in which the methods will be shown.
+	private static TimedClassInfo tci;
+	private static List<CombinedFrameInfo> cfs;
+	
+	public MethodBean(){}
+	
+	public MethodBean(long count, String totalTime, String cPercent,
+			String tPercent, String prettyName) {
+		this.count=count;
+		this.totalTime=totalTime;
+		this.cPercent=cPercent;
+		this.tPercent=tPercent;
+		this.prettyName=prettyName;
+	}
+	
+	public long getCount() {
+		return count;
+	}
+
+	public void setCount(long count) {
+		this.count = count;
+	}
+
+	public String getTotalTime() {
+		return totalTime;
+	}
+
+	public void setTotalTime(String totalTime) {
+		this.totalTime = totalTime;
+	}
+
+	public String getCPercent() {
+		return cPercent;
+	}
+
+	public void setCPercent(String percent) {
+		cPercent = percent;
+	}
+
+	public String getTPercent() {
+		return tPercent;
+	}
+
+	public void setTPercent(String percent) {
+		tPercent = percent;
+	}
+
+	public String getPrettyName() {
+		return prettyName;
+	}
+
+	public void setPrettyName(String prettyName) {
+		this.prettyName = prettyName;
+	}
+	
+	public static TimedClassInfo getTci() {
+		return tci;
+	}
+
+	public static void setTci(TimedClassInfo tci) {
+		MethodBean.tci = tci;
+	}
+
+	public static List<CombinedFrameInfo> getCfs() {
+		return cfs;
+	}
+
+	public static void setCfs(List<CombinedFrameInfo> cfs) {
+		MethodBean.cfs = cfs;
+	}
+
+	public void setMethods(){
+		if (cfs!=null) {
+			DecimalFormat df = new DecimalFormat("#0.00");
+			Collections.sort(cfs, new CombinedFrameComparator(CombinedFrameComparator.TOTAL_TIME));
+			int j=0;
+			methods=new MethodBean[cfs.size()];
+			
+			for (CombinedFrameInfo cfi : cfs) {		
+				methods[j++]= new MethodBean(cfi.getCount(),
+						df.format(cfi.getTotalTime()),
+						df.format(Math.toPercent(cfi.getTotalTime(), tci.getTotalTime())),
+						df.format(cfi.getPercent()),
+						cfi.getPrettyName());
+			}
+		}
+	}
+
+	public MethodBean[] getMethods(){
+		this.setMethods();
+		return this.methods;
+	}
+}
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+


Property changes on: branches/JBossProfiler2/src/main/org/jboss/profiler/ui/MethodBean.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/JBossProfiler2/src/main/org/jboss/profiler/ui/OverviewBean.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/ui/OverviewBean.java	                        (rev 0)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/ui/OverviewBean.java	2008-10-06 01:44:47 UTC (rev 479)
@@ -0,0 +1,148 @@
+package org.jboss.profiler.ui;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.profiler.client.CombinedFrameComparator;
+import org.jboss.profiler.client.CombinedFrameInfo;
+import org.jboss.profiler.client.TimedClassInfo;
+import org.jboss.profiler.shared.AllocationComparator;
+import org.jboss.profiler.shared.AllocationInfo;
+import org.jboss.profiler.shared.ThreadComparator;
+import org.jboss.profiler.shared.ThreadInfo;
+import org.jboss.profiler.ui.util.SnapshotUtility;
+
+/**
+ at author Huijuan Shao <hjshao at hitachi.cn>
+*/
+public class OverviewBean {
+	private String title;
+	private int packageUnderThreshCount;
+
+	public String getTitle() {
+		return title;
+	}
+	public void setTitle(String title) {
+		this.title = title;
+	}
+	public String[] getTitles(){
+		String[] titles={
+			"Threads","Most Time","Hotspots","Allocations","classes"	
+		};
+		return titles;
+	}
+
+	public int getPackageUnderThreshCount() {
+		return packageUnderThreshCount;
+	}
+	public void setPackageUnderThreshCount(int packageUnderThreshCount) {
+		this.packageUnderThreshCount = packageUnderThreshCount;
+	}
+	public List<AllocationInfo> getAllocations() {
+		List<AllocationInfo> allocationList=null;
+		if(LoadSnapshotBean.getSnapshot()!=null){
+			Collections.sort(LoadSnapshotBean.getSnapshot().getAllocations(), new AllocationComparator());
+			allocationList=LoadSnapshotBean.getSnapshot().getAllocations();
+		}
+
+		return allocationList;
+	}
+
+	public List<CombinedFrameInfo> getHotspots(){
+		
+		if(LoadSnapshotBean.getSnapshot()!=null){
+			SnapshotUtility su=new SnapshotUtility();
+		    Map<String, List<CombinedFrameInfo>> info = su.getInformation(LoadSnapshotBean.getSnapshot());	  
+		    List<CombinedFrameInfo> hotspotsInfo = new ArrayList<CombinedFrameInfo>();
+		    Iterator it = info.values().iterator();
+		    while (it.hasNext()) {
+		      List<CombinedFrameInfo> l = (List<CombinedFrameInfo>)it.next();
+		      hotspotsInfo.addAll(l);
+		    }
+		    Collections.sort(hotspotsInfo,new CombinedFrameComparator(CombinedFrameComparator.TOTAL_TIME_AVG));
+		    
+		    return hotspotsInfo;
+		}	
+		else return null;
+	}
+	
+	public List<CombinedFrameInfo> getMostTime(){
+		  SnapshotUtility su=new SnapshotUtility();
+		  
+		  if(LoadSnapshotBean.getSnapshot()!=null)
+		  {
+			  Map<String, List<CombinedFrameInfo>> info = su.getInformation(LoadSnapshotBean.getSnapshot());
+			  List<TimedClassInfo> classes = su.getTimedClasses(LoadSnapshotBean.getSnapshot().getClasses(), info);
+	      
+			  List<CombinedFrameInfo> allMethods = new ArrayList<CombinedFrameInfo>();
+
+			  Iterator it = info.values().iterator();
+			  while (it.hasNext()) {
+				  List<CombinedFrameInfo> l = (List<CombinedFrameInfo>)it.next();
+				  allMethods.addAll(l);
+			  }
+
+			  Collections.sort(allMethods, new CombinedFrameComparator(CombinedFrameComparator.TOTAL_TIME));
+			  return allMethods;
+		  }
+		  else return null;		  
+	}
+	
+	public List<ThreadInfo> getThreads(){		
+		List<ThreadInfo> threads=null;
+		if(LoadSnapshotBean.getSnapshot()!=null){
+		    Collections.sort(LoadSnapshotBean.getSnapshot().getThreads(), new ThreadComparator());
+		    threads=LoadSnapshotBean.getSnapshot().getThreads();
+		    return threads;
+		}
+		else return null;
+	}
+	
+	public List<CombinedFrameInfo> getPackages(){	
+		if(LoadSnapshotBean.getSnapshot()!=null){
+			SnapshotUtility su=new SnapshotUtility();
+		    Map<String, List<CombinedFrameInfo>> info = su.getInformation(LoadSnapshotBean.getSnapshot());
+		    List<TimedClassInfo> classes = su.getTimedClasses(LoadSnapshotBean.getSnapshot().getClasses(), info);
+		    
+		    Map<String, CombinedFrameInfo> packages = new HashMap<String, CombinedFrameInfo>();
+
+		    Iterator it = info.entrySet().iterator();
+		    while (it.hasNext()) {
+		      Map.Entry entry = (Map.Entry)it.next();
+		      String key = (String)entry.getKey();
+		      List<CombinedFrameInfo> value = (List<CombinedFrameInfo>)entry.getValue();
+
+		      for (CombinedFrameInfo cfi : value) {
+		        String cn = cfi.getClassName();
+		        cn = cn.replace('/', '.');
+		        if (cn.lastIndexOf(".") != -1) {
+		          cn = cn.substring(0, cn.lastIndexOf("."));
+		        }
+
+		        CombinedFrameInfo ci = packages.get(cn);
+		        if (ci == null) {
+		          ci = new CombinedFrameInfo(cn, cn);
+		        }
+		        ci.increaseTotalTime(cfi.getTotalTime());
+		        ci.increasePercent(cfi.getPercent());
+		        packages.put(cn, ci);
+		      }
+		    }
+
+		    List<CombinedFrameInfo> result = new ArrayList<CombinedFrameInfo>(packages.values());
+		    Collections.sort(result, new CombinedFrameComparator(CombinedFrameComparator.TOTAL_TIME));
+
+		    int count = 0;
+		    
+		    int j=0;
+		   
+		    this.packageUnderThreshCount=count;
+		    return result;
+		}
+		else return null;
+		}
+}


Property changes on: branches/JBossProfiler2/src/main/org/jboss/profiler/ui/OverviewBean.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/JBossProfiler2/src/main/org/jboss/profiler/ui/ThreadHotspotBean.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/ui/ThreadHotspotBean.java	                        (rev 0)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/ui/ThreadHotspotBean.java	2008-10-06 01:44:47 UTC (rev 479)
@@ -0,0 +1,222 @@
+package org.jboss.profiler.ui;
+
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.AbstractMap.SimpleEntry;
+import java.util.Map.Entry;
+
+import javax.faces.model.SelectItem;
+
+import org.jboss.profiler.client.CombinedFrameComparator;
+import org.jboss.profiler.client.CombinedFrameInfo;
+import org.jboss.profiler.client.Util;
+import org.jboss.profiler.shared.FrameInfo;
+import org.jboss.profiler.shared.Math;
+import org.jboss.profiler.shared.ThreadInfo;
+
+/**
+ at author Huijuan Shao <hjshao at hitachi.cn>
+*/
+public class ThreadHotspotBean {
+	private String selectItem=null;
+	private ThreadInfo selectThreadInfo=null;
+	
+	private ArrayList<String> mainKeys;
+	private ArrayList<String> subKeys;
+	private ArrayList<CombinedFrameInfo> subValues;
+	private HashMap<String,CombinedFrameInfo> newMap;
+
+	public ThreadHotspotBean() {
+	}
+	
+	public String getSelectItem() {
+		return selectItem;
+	}
+	public void setSelectItem(String selectItem) {
+		this.selectItem = selectItem;
+	}
+	
+	public ThreadInfo getSelectThreadInfo() {
+		return selectThreadInfo;
+	}
+	public void setSelectThreadInfo(ThreadInfo selectThreadInfo) {
+		this.selectThreadInfo = selectThreadInfo;
+		this.selectItem=selectThreadInfo.getName();
+	}
+	
+	public ArrayList<String> getMainKeys() {
+		return mainKeys;
+	}
+
+	public void setMainKeys(ArrayList<String> mainKeys) {
+		this.mainKeys = mainKeys;
+	}
+
+	public ArrayList<String> getSubKeys() {
+		return subKeys;
+	}
+	public void setSubKeys(ArrayList<String> subKeys) {
+		this.subKeys = subKeys;
+	}
+
+	public ArrayList<CombinedFrameInfo> getSubValues() {
+		return subValues;
+	}
+	public void setSubValues(ArrayList<CombinedFrameInfo> subValues) {
+		this.subValues = subValues;
+	}
+
+	public HashMap<String, CombinedFrameInfo> getNewMap() {
+		return newMap;
+	}
+
+	public void setNewMap(HashMap<String, CombinedFrameInfo> newMap) {
+		this.newMap = newMap;
+	}
+
+	public List<ThreadInfo> getAllThreads(){
+		List<ThreadInfo> threadsList=null;
+		if(LoadSnapshotBean.getSnapshot()!=null){
+			threadsList=LoadSnapshotBean.getSnapshot().getThreads();
+		}
+
+		return threadsList;
+	}
+
+	public void selectionChanged(javax.faces.event.ValueChangeEvent evt){
+		this.setSelectItem(((String)evt.getNewValue()));
+		
+		//get the selected thread
+		List<ThreadInfo> allThreads=this.getAllThreads();
+		Iterator<ThreadInfo> it=allThreads.iterator();
+		ThreadInfo tmpThreadInfo=null;
+		while(it.hasNext()){
+			tmpThreadInfo=it.next();
+			if(tmpThreadInfo.getName().endsWith(this.selectItem))
+				break;
+		}
+		generateArrayFromMap(tmpThreadInfo);
+	}
+	
+	public List<SelectItem> getAllSelectItems(){
+		List<SelectItem> allSelectItems=null;
+		List<ThreadInfo> threadsList=null;
+		if(LoadSnapshotBean.getSnapshot()!=null){
+			threadsList=LoadSnapshotBean.getSnapshot().getThreads();
+			allSelectItems=new ArrayList<SelectItem>(threadsList.size());
+			for(int i=0;i<threadsList.size();i++){
+				allSelectItems.add(new SelectItem(threadsList.get(i).getName()));
+			}
+		}
+		return allSelectItems;
+	}
+	
+	public void showMapInfo(ThreadInfo threadInfo){
+		Map<String, Map<String, CombinedFrameInfo>> data = new HashMap<String, Map<String, CombinedFrameInfo>>();
+		   
+		//only one thread information, not all threadList
+		for (FrameInfo fi: threadInfo.getFrames()) {
+			getCallerInformation(fi, data);
+		}
+		
+		Iterator dit = data.entrySet().iterator();
+		DecimalFormat df = new DecimalFormat("#0.00");
+		
+		while (dit.hasNext()) {
+		      Map.Entry entry = (Map.Entry)dit.next();
+		      String key = (String)entry.getKey();
+		      Map<String, CombinedFrameInfo> value = (Map<String, CombinedFrameInfo>)entry.getValue();
+
+		      Map<String, List<CombinedFrameInfo>> m = new HashMap<String, List<CombinedFrameInfo>>();
+		      Iterator vit = value.values().iterator();
+		      while (vit.hasNext()) {
+		        CombinedFrameInfo cfi = (CombinedFrameInfo)vit.next();
+
+		        List<CombinedFrameInfo> l = m.get(cfi.getClassName());
+		        if (l == null) {
+		          l = new ArrayList<CombinedFrameInfo>();
+		          m.put(cfi.getClassName(), l);
+		        }
+		        l.add(cfi);
+		      }
+
+		      Iterator mit = m.entrySet().iterator();
+		      while (mit.hasNext()) {
+		        Map.Entry mentry = (Map.Entry)mit.next();
+		        String methodName = (String)mentry.getKey();
+		        List<CombinedFrameInfo> callers = (List<CombinedFrameInfo>)mentry.getValue();
+		        Collections.sort(callers, new CombinedFrameComparator(CombinedFrameComparator.TOTAL_TIME));
+		      }// show List information.
+		}//show map information
+	}
+	
+	public void generateArrayFromMap(ThreadInfo threadInfo){
+		Map<String, Map<String, CombinedFrameInfo>> map = new HashMap<String, Map<String, CombinedFrameInfo>>();
+		   
+		for (FrameInfo fi: threadInfo.getFrames()) {
+			getCallerInformation(fi, map);
+		}
+		
+		HashMap<String,CombinedFrameInfo> newMap=new HashMap();
+		Set<String> set=map.keySet();
+		ArrayList<String> mainKeys=new ArrayList(set);
+		this.mainKeys=mainKeys;
+		
+		ArrayList subKeys=new ArrayList();
+		ArrayList subValues=new ArrayList();
+		
+		Iterator it = map.values().iterator();
+		while(it.hasNext()){
+			Map<String, CombinedFrameInfo> subMap=(Map<String, CombinedFrameInfo>) it.next();
+			Set entrySet=subMap.entrySet();
+			Iterator entryIt=entrySet.iterator();
+			while(entryIt.hasNext()){
+				Map.Entry<String, CombinedFrameInfo> entry=(Entry<String, CombinedFrameInfo>) entryIt.next();
+				subKeys.add(entry.getKey());
+				subValues.add(entry.getValue());
+				newMap.put(entry.getKey(), entry.getValue());
+			}
+		}
+		
+		this.setSubKeys(subKeys);
+		this.setSubValues(subValues);
+		this.setNewMap(newMap);
+	}
+	
+	  /**
+	   * Get caller information
+	   * @param fi The frame
+	   * @param data The data
+	   */
+	  public void getCallerInformation(FrameInfo fi, Map<String, Map<String, CombinedFrameInfo>> data) {
+	    Map<String, CombinedFrameInfo> entry = data.get(fi.getMethod().getClassName());
+	    if (entry == null) {
+	      entry = new HashMap<String, CombinedFrameInfo>();
+	      data.put(fi.getMethod().getClassName(), entry);
+	    }
+	    if (fi.getParent() != null) {
+	      String parentName = Util.getPrettyName(fi.getParent().getMethod());
+	      CombinedFrameInfo cfi = entry.get(parentName);
+	      if (cfi == null) {
+	        cfi = new CombinedFrameInfo(Util.getPrettyName(fi.getMethod()), parentName);
+	        entry.put(parentName, cfi);
+	      }
+
+	      cfi.increaseCount(fi.getParent().getCount());
+	      cfi.increaseTotalTime(Math.nanoToMilli(fi.getParent().getNetTime()));
+	    }
+
+	    if (fi.getChildren() != null && fi.getChildren().size() > 0) {
+	      for (FrameInfo child : fi.getChildren()) {
+	        getCallerInformation(child, data);
+	      }
+	    }
+	  }
+}


Property changes on: branches/JBossProfiler2/src/main/org/jboss/profiler/ui/ThreadHotspotBean.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/JBossProfiler2/src/main/org/jboss/profiler/ui/TreeFrameBean.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/ui/TreeFrameBean.java	                        (rev 0)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/ui/TreeFrameBean.java	2008-10-06 01:44:47 UTC (rev 479)
@@ -0,0 +1,32 @@
+package org.jboss.profiler.ui;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.jboss.profiler.shared.FrameInfo;
+
+/**
+ at author Huijuan Shao <hjshao at hitachi.cn>
+*/
+public class TreeFrameBean {
+
+	private static List<FrameInfo> enterFrames=null;
+	private List<FrameInfo> srcRoots=null;
+
+	public static List<FrameInfo> getEnterFrames() {
+		return enterFrames;
+	}
+
+	public static void setEnterFrames(List<FrameInfo> enterFrames) {
+		TreeFrameBean.enterFrames = enterFrames;
+	}
+
+	public synchronized List<FrameInfo> getSrcRoots() {
+		
+		if(enterFrames==null) return null;
+			srcRoots=new ArrayList<FrameInfo>(enterFrames.size());
+			for(int i=0;i<enterFrames.size();i++){
+				srcRoots.add(enterFrames.get(i));
+			}
+			return srcRoots;
+	}
+}


Property changes on: branches/JBossProfiler2/src/main/org/jboss/profiler/ui/TreeFrameBean.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/JBossProfiler2/src/main/org/jboss/profiler/ui/TreeThreadBean.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/ui/TreeThreadBean.java	                        (rev 0)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/ui/TreeThreadBean.java	2008-10-06 01:44:47 UTC (rev 479)
@@ -0,0 +1,57 @@
+package org.jboss.profiler.ui;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.Writer;
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.swing.tree.DefaultMutableTreeNode;
+
+import org.jboss.profiler.client.Util;
+import org.jboss.profiler.shared.FrameInfo;
+import org.jboss.profiler.shared.Math;
+import org.jboss.profiler.shared.Snapshot;
+import org.jboss.profiler.shared.ThreadInfo;
+import org.richfaces.model.TreeNode;
+import org.richfaces.model.TreeNodeImpl;
+
+/**
+ at author Huijuan Shao <hjshao at hitachi.cn>
+*/
+public class TreeThreadBean {
+	//the id of selectedThread
+	private long selectedThread;
+
+	public TreeThreadBean() {
+	}
+
+	public long getSelectedThread() {
+		return selectedThread;
+	}
+	public void setSelectedThread(long selectedThread) {
+		this.selectedThread = selectedThread;
+	}
+	public List<ThreadInfo> getAllThreads(){
+		List<ThreadInfo> threadsList=null;
+		if(LoadSnapshotBean.getSnapshot()!=null){
+			threadsList=LoadSnapshotBean.getSnapshot().getThreads();
+		}
+		return threadsList;
+	}
+	
+	public void fireSelectedThread(){
+		List<ThreadInfo> allthreads=this.getAllThreads();
+		ThreadInfo tmpThreadInfo=null;
+		for(int i=0;i<allthreads.size();i++){
+			tmpThreadInfo=allthreads.get(i);
+			if(tmpThreadInfo.getId()==this.getSelectedThread()) break;
+		}
+		
+		List<FrameInfo> frames=tmpThreadInfo.getFrames();
+		TreeFrameBean.setEnterFrames(tmpThreadInfo.getFrames());
+	}
+}


Property changes on: branches/JBossProfiler2/src/main/org/jboss/profiler/ui/TreeThreadBean.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/JBossProfiler2/src/main/org/jboss/profiler/ui/util/PostbackPhaseListener.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/ui/util/PostbackPhaseListener.java	                        (rev 0)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/ui/util/PostbackPhaseListener.java	2008-10-06 01:44:47 UTC (rev 479)
@@ -0,0 +1,41 @@
+package org.jboss.profiler.ui.util;
+
+import java.util.Map;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.event.PhaseListener;
+
+public class PostbackPhaseListener implements PhaseListener {
+
+	private static final long serialVersionUID = 1L;
+	public static final String POSTBACK_ATTRIBUTE_NAME = PostbackPhaseListener.class.getName();
+	
+	public void afterPhase(PhaseEvent event) {
+	}
+
+	public void beforePhase(PhaseEvent event) {
+		FacesContext facesContext = event.getFacesContext();
+		Map requestMap = facesContext.getExternalContext().getRequestMap();
+		requestMap.put(POSTBACK_ATTRIBUTE_NAME, Boolean.TRUE);
+	}
+
+	public PhaseId getPhaseId() {
+		return PhaseId.APPLY_REQUEST_VALUES;
+	}
+
+	public static boolean isPostback() {
+		FacesContext facesContext = FacesContext.getCurrentInstance();
+		if (facesContext != null) {
+			ExternalContext externalContext = facesContext.getExternalContext();
+			if (externalContext != null) {
+				return Boolean.TRUE.equals(
+						externalContext.getRequestMap().get(POSTBACK_ATTRIBUTE_NAME));
+			}
+		}
+		return false;
+	}
+	
+}


Property changes on: branches/JBossProfiler2/src/main/org/jboss/profiler/ui/util/PostbackPhaseListener.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/JBossProfiler2/src/main/org/jboss/profiler/ui/util/Profiler.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/ui/util/Profiler.java	                        (rev 0)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/ui/util/Profiler.java	2008-10-06 01:44:47 UTC (rev 479)
@@ -0,0 +1,195 @@
+package org.jboss.profiler.ui.util;
+
+import org.jboss.profiler.agent.Agent;
+import org.jboss.profiler.connectors.LocalHandler;
+import org.jboss.profiler.shared.Command;
+import org.jboss.profiler.shared.CommandType;
+import org.jboss.profiler.shared.Visibility;
+
+import org.jboss.logging.Logger;
+
+/**
+ * The profiler mbean class
+ * @author Jesper Pedersen <jesper.pedersen at jboss.org>
+ */
+public class Profiler{
+  /** The logger */
+  private static Logger log = Logger.getLogger(Profiler.class);
+
+  /**
+   * Constructor
+   */
+  public Profiler() {
+  }
+
+  /**
+   * Is the profiler enabled ?
+   * @return True if enabled; otherwise false
+   */
+  public boolean isEnabled() {
+    return Agent.isEnabled();
+  }
+
+  /**
+   * Is the profiler running ?
+   * @return True if running; otherwise false
+   */
+  public boolean isRunning() {
+    return org.jboss.profiler.agent.Profiler.isRunning();
+  }
+
+  /**
+   * Is the profiler using a memory store ?
+   * @return True if memory store; otherwise false
+   */
+  public boolean isMemory() {
+    return Agent.isMemoryStore();
+  }
+
+  /**
+   * Is the profiler using a file store ?
+   * @return True if file store; otherwise false
+   */
+  public boolean isFile() {
+    return !Agent.isMemoryStore();
+  }
+
+  /**
+   * Is EJB ?
+   * @return True if enabled; otherwise false
+   */
+  public boolean isEJB() {
+    return Agent.isEJB();
+  }
+
+  /**
+   * Is Servlet ?
+   * @return True if enabled; otherwise false
+   */
+  public boolean isServlet() {
+    return Agent.isServlet();
+  }
+
+  /**
+   * Is JSF ?
+   * @return True if enabled; otherwise false
+   */
+  public boolean isJSF() {
+    return Agent.isJSF();
+  }
+
+  /**
+   * Is JMX ?
+   * @return True if enabled; otherwise false
+   */
+  public boolean isJMX() {
+    return Agent.isJMX();
+  }
+
+  /**
+   * Is RMI ?
+   * @return True if enabled; otherwise false
+   */
+  public boolean isRMI() {
+    return Agent.isRMI();
+  }
+
+  /**
+   * Is CORBA ?
+   * @return True if enabled; otherwise false
+   */
+  public boolean isCORBA() {
+    return Agent.isCORBA();
+  }
+
+  /**
+   * Start the profiler
+   */
+  public void startProfiler() {
+    LocalHandler lh = new LocalHandler();
+    lh.handleCommand(new Command(CommandType.START_PROFILER));
+  }
+
+  /**
+   * Stop the profiler
+   */
+  public void stopProfiler() {
+    LocalHandler lh = new LocalHandler();
+    lh.handleCommand(new Command(CommandType.STOP_PROFILER));
+  }
+
+  /**
+   * Enable the profiler
+   */
+  public void enableProfiler() {
+    LocalHandler lh = new LocalHandler();
+    lh.handleCommand(new Command(CommandType.ENABLE));
+  }
+
+  /**
+   * Disable the profiler
+   */
+  public void disableProfiler() {
+    LocalHandler lh = new LocalHandler();
+    lh.handleCommand(new Command(CommandType.DISABLE));
+  }
+
+  /**
+   * Add classes
+   * @param classes The classes
+   * @param v The visibility
+   */
+  public void addClasses(String classes, String v) {
+    LocalHandler lh = new LocalHandler();
+
+    if (v == null || v.trim().equals("")) {
+      v = "public";
+    }
+
+    Visibility vi = null;
+    if (v.equalsIgnoreCase("private")) {
+      vi = Visibility.PRIVATE;
+    } else if (v.equalsIgnoreCase("protected")) {
+      vi = Visibility.PROTECTED;
+    } else if (v.equalsIgnoreCase("package")) {
+      vi = Visibility.PACKAGE;
+    } else {
+      vi = Visibility.PUBLIC;
+    }
+
+    lh.handleCommand(new Command(CommandType.ADD_CLASSES, new Object[] { classes, vi }));
+  }
+
+  /**
+   * Remove classes
+   * @param classes The classes
+   */
+  public void removeClasses(String classes) {
+    LocalHandler lh = new LocalHandler();
+    lh.handleCommand(new Command(CommandType.REMOVE_CLASSES, new Object[] { classes }));
+  }
+
+  /**
+   * Clear snapshots
+   */
+  public void clearSnapshots() {
+    LocalHandler lh = new LocalHandler();
+    lh.handleCommand(new Command(CommandType.CLEAR_SNAPSHOTS));
+  }
+
+  /**
+   * Start the service
+   * @exception Exception Thrown if an exception occurs
+   */
+  public void start() throws Exception {
+    log.info("JBoss Profiler: ProfilerMBean started");
+  }
+
+  /**
+   * Stop the service
+   * @exception Exception Thrown if an exception occurs
+   */
+  public void stop() throws Exception {
+    log.info("JBoss Profiler: ProfilerMBean stopped");
+  }
+}


Property changes on: branches/JBossProfiler2/src/main/org/jboss/profiler/ui/util/Profiler.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/JBossProfiler2/src/main/org/jboss/profiler/ui/util/SnapshotUtility.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/ui/util/SnapshotUtility.java	                        (rev 0)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/ui/util/SnapshotUtility.java	2008-10-06 01:44:47 UTC (rev 479)
@@ -0,0 +1,259 @@
+package org.jboss.profiler.ui.util;
+
+import org.jboss.profiler.client.CombinedFrameComparator;
+import org.jboss.profiler.client.CombinedFrameInfo;
+import org.jboss.profiler.client.TimedClassComparator;
+import org.jboss.profiler.client.TimedClassInfo;
+import org.jboss.profiler.shared.AllocationComparator;
+import org.jboss.profiler.shared.AllocationInfo;
+import org.jboss.profiler.shared.ClassComparator;
+import org.jboss.profiler.shared.ClassInfo;
+import org.jboss.profiler.shared.FrameComparator;
+import org.jboss.profiler.shared.FrameInfo;
+import org.jboss.profiler.shared.Math;
+import org.jboss.profiler.shared.Snapshot;
+import org.jboss.profiler.shared.SnapshotHelper;
+import org.jboss.profiler.shared.ThreadComparator;
+import org.jboss.profiler.shared.ThreadInfo;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.Writer;
+import java.text.DecimalFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.List;
+import java.util.Map;
+import java.util.Iterator;
+import java.util.Vector;
+
+import org.jboss.logging.Logger;
+import org.jboss.profiler.client.Util;
+
+/**
+ * The snapshot utility class
+ * @author Jesper Pedersen <jesper.pedersen at jboss.org>
+ */
+public class SnapshotUtility {
+  /** The logger */
+  private static Logger log = Logger.getLogger(SnapshotUtility.class);
+
+  /** New line character */
+  protected static final String NEW_LINE = System.getProperty("line.separator");
+
+  /** Threshold */
+  protected double threshold;
+
+  /**
+   * Constructor
+   */
+  public SnapshotUtility() {
+    this(1.0);
+  }
+
+  /**
+   * Constructor
+   * @param threshold The threshold
+   */
+  public SnapshotUtility(double threshold) {
+    this.threshold = threshold;
+  }
+
+  /**
+   * Get information about the snapshot
+   * @param snapshot The snapshot
+   * @return The information
+   */
+  //changed by shj 20080814 from protected-> public
+  public Map<String, List<CombinedFrameInfo>> getInformation(Snapshot snapshot) {
+    Map<String, Map<String, CombinedFrameInfo>> data = 
+      new HashMap<String, Map<String, CombinedFrameInfo>>();
+
+    long tt = 0;
+    for (ThreadInfo ti: snapshot.getThreads()) {
+      tt += ti.getTotalTime();
+    }
+
+    for (ThreadInfo ti: snapshot.getThreads()) {
+      for (FrameInfo fi: ti.getFrames()) {
+        frameInformation(fi, tt, data);
+      }
+    }
+
+    Map<String, List<CombinedFrameInfo>> result = new HashMap<String, List<CombinedFrameInfo>>();
+
+    Iterator it = data.entrySet().iterator();
+    while (it.hasNext()) {
+      Map.Entry entry = (Map.Entry)it.next();
+      String key = (String)entry.getKey();
+      Map<String, CombinedFrameInfo> value = (Map<String, CombinedFrameInfo>)entry.getValue();
+      
+      result.put(key, new ArrayList<CombinedFrameInfo>(value.values()));
+    }
+
+    return result;
+  }
+
+  /**
+   * Generate frame information
+   * @param fi The frame
+   * @param tt The total time (ns)
+   * @param data The data
+   */
+  public void frameInformation(FrameInfo fi, long tt, Map<String, Map<String, CombinedFrameInfo>> data) {
+    Map<String, CombinedFrameInfo> classData = data.get(fi.getMethod().getClassName());
+      
+    if (classData == null) {
+      classData = new HashMap<String, CombinedFrameInfo>();
+      data.put(fi.getMethod().getClassName(), classData);
+    }
+
+    String prettyName = Util.getPrettyName(fi.getMethod());
+    CombinedFrameInfo methodData = classData.get(prettyName);
+    
+    if (methodData == null) {
+      methodData = new CombinedFrameInfo(fi.getMethod().getClassName(), prettyName);
+      classData.put(prettyName, methodData);
+    }
+    
+    long net = fi.getNetTime();
+    double percent = Math.toPercent(net, (double)tt);
+    double time = Math.nanoToMilli(net);
+    
+    methodData.increaseCount(fi.getCount());
+    methodData.increaseTotalTime(time);
+    methodData.increasePercent(percent);
+    methodData.increaseWaitTime(Math.nanoToMilli(fi.getWaitTime()));
+
+    List<FrameInfo> l = fi.getChildren();
+    if (l != null) {
+      for (FrameInfo child: l) {
+        frameInformation(child, tt, data);
+      }
+    }
+  }
+
+  /**
+   * Get the timed classes
+   * @param classes The classes
+   * @param info The information
+   * @return The timed classes
+   */
+  public List<TimedClassInfo> getTimedClasses(List<ClassInfo> classes,
+                                                 Map<String, List<CombinedFrameInfo>> info) {
+    List<TimedClassInfo> result = new ArrayList<TimedClassInfo>();
+
+    for (ClassInfo ci : classes) {
+      List<CombinedFrameInfo> l = info.get(ci.getClassName());
+
+      double time = 0.0;
+      double wait = 0.0;
+      
+      if (l != null) {
+        for (CombinedFrameInfo cfi: l) {
+          time += cfi.getTotalTime();
+          wait += cfi.getWaitTime();
+        }
+      }
+
+      TimedClassInfo tci = new TimedClassInfo(ci, time, wait);
+      result.add(tci);
+    }
+
+    return result;
+  }
+
+  /**
+   * Dump the hotspots
+   * @param info The information
+   * @param directory The directory
+   * @exception Exception If an error occurs
+   */
+  public Vector getHotspots(Map<String, List<CombinedFrameInfo>> info) throws Exception {
+	Vector<Object> vector_total=new Vector();
+	  
+    List<CombinedFrameInfo> hotspots = new ArrayList<CombinedFrameInfo>();
+    Iterator it = info.values().iterator();
+    while (it.hasNext()) {
+      List<CombinedFrameInfo> l = (List<CombinedFrameInfo>)it.next();
+      hotspots.addAll(l);
+    }
+
+    Collections.sort(hotspots, new CombinedFrameComparator(CombinedFrameComparator.TOTAL_TIME_AVG));
+    DecimalFormat df = new DecimalFormat("#0.00");
+
+    int count = 0;
+    
+    int countArray[]=new int[1000];
+    double totalTimeArray[]=new double[1000];
+    double avgArray[]=new double[1000];
+    double percentArray[]=new double[1000];
+    String nameArray[]=new String[1000];
+    
+    int j=0;
+    for (int i = 0; i < hotspots.size(); i++) {
+      CombinedFrameInfo h = hotspots.get(i);
+
+      double avg = h.getTotalTime() / h.getCount();
+
+      if (avg >= threshold) {
+    	countArray[j]=(int) h.getCount();
+    	totalTimeArray[j]=h.getTotalTime();
+    	avgArray[j]=avg;
+    	percentArray[j]=h.getPercent();
+    	nameArray[j]= h.getPrettyName();
+    	j++;
+      } else {
+        count++;
+      }
+    }
+    
+    vector_total.add(countArray);
+    vector_total.add(totalTimeArray);
+    vector_total.add(avgArray);
+    vector_total.add(percentArray);
+    vector_total.add(nameArray);
+    vector_total.add(count);
+    return vector_total;
+  }
+  
+  public Vector getHotspots(Snapshot snapshot) throws Exception{
+	  Map<String, List<CombinedFrameInfo>> info = this.getInformation(snapshot);
+	  return getHotspots(info);
+  }
+
+  /**
+   * Get caller information
+   * @param fi The frame
+   * @param data The data
+   */
+  protected void getCallerInformation(FrameInfo fi, Map<String, Map<String, CombinedFrameInfo>> data) {
+    Map<String, CombinedFrameInfo> entry = data.get(fi.getMethod().getClassName());
+    if (entry == null) {
+      entry = new HashMap<String, CombinedFrameInfo>();
+      data.put(fi.getMethod().getClassName(), entry);
+    }
+    if (fi.getParent() != null) {
+      String parentName = Util.getPrettyName(fi.getParent().getMethod());
+      CombinedFrameInfo cfi = entry.get(parentName);
+      if (cfi == null) {
+        cfi = new CombinedFrameInfo(Util.getPrettyName(fi.getMethod()), parentName);
+        entry.put(parentName, cfi);
+      }
+
+      cfi.increaseCount(fi.getParent().getCount());
+      cfi.increaseTotalTime(Math.nanoToMilli(fi.getParent().getNetTime()));
+    }
+
+    if (fi.getChildren() != null && fi.getChildren().size() > 0) {
+      for (FrameInfo child : fi.getChildren()) {
+        getCallerInformation(child, data);
+      }
+    }
+  }
+}


Property changes on: branches/JBossProfiler2/src/main/org/jboss/profiler/ui/util/SnapshotUtility.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/JBossProfiler2/src/main/org/jboss/profiler/ui/util/TreeDemoStateAdvisor.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/ui/util/TreeDemoStateAdvisor.java	                        (rev 0)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/ui/util/TreeDemoStateAdvisor.java	2008-10-06 01:44:47 UTC (rev 479)
@@ -0,0 +1,24 @@
+package org.jboss.profiler.ui.util;
+
+import org.richfaces.component.UITree;
+import org.richfaces.component.state.TreeStateAdvisor;
+import org.richfaces.model.TreeRowKey;
+
+public class TreeDemoStateAdvisor implements TreeStateAdvisor {
+
+	public Boolean adviseNodeOpened(UITree tree) {
+		if (!PostbackPhaseListener.isPostback()) {
+			Object key = tree.getRowKey();
+			TreeRowKey treeRowKey = (TreeRowKey) key;
+			if (treeRowKey == null || treeRowKey.depth() <= 2) {
+				return Boolean.TRUE;
+			}
+		}
+		return null;
+	}
+
+	public Boolean adviseNodeSelected(UITree tree) {
+		return null;
+	}
+
+}
\ No newline at end of file


Property changes on: branches/JBossProfiler2/src/main/org/jboss/profiler/ui/util/TreeDemoStateAdvisor.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain




More information about the jboss-cvs-commits mailing list