Update of /cvsroot/javaprofiler/module/net/sourceforge/javaprofiler/module/data
In directory usw-pr-cvs1:/tmp/cvs-serv19585
Added Files:
BacktraceSupport.java
Log Message:
added cpu backtrace view
--- NEW FILE: BacktraceSupport.java ---
/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"); you may not use this file except
* in compliance with the License. A copy of the License is available
* at http://www.sun.com/
*
* The Original Code is the Java Profiler module. The Initial Developers
* of the Original Code are Jan Stola, Pavel Vacha, Michal Pise, Petr Luner,
* Lukas Petru and Marek Przeczek.
*
* Portions created by Jan Stola are Copyright (C) 2000-2001.
* All Rights Reserved.
*
* Portions created by Pavel Vacha are Copyright (C) 2000-2001.
* All Rights Reserved.
*
* Portions created by Michal Pise are Copyright (C) 2000-2001.
* All Rights Reserved.
*
* Portions created by Petr Luner are Copyright (C) 2000-2001.
* All Rights Reserved.
*
* Portions created by Lukas Petru are Copyright (C) 2000-2001.
* All Rights Reserved.
*
* Portions created by Marek Przeczek are Copyright (C) 2000-2001.
* All Rights Reserved.
*
* Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner,
* Lukas Petru and Marek Przeczek.
*/
package net.sourceforge.javaprofiler.module.data;
import java.util.*;
import net.sourceforge.javaprofiler.jpi.TraceRef;
import net.sourceforge.javaprofiler.jpi.FrameRef;
import net.sourceforge.javaprofiler.jpi.CPUStat;
import net.sourceforge.javaprofiler.jpi.CPUStatListener;
/** Support for showing backtrace view.
* @author Lukas Petru
*/
public class BacktraceSupport {
/** Splits a list of <code>TraceRef</code> objects into a map which has
* <code>FrameRef</code> of selected level as key and a list of traces
* containing this frame as a value.
* @param traces List of <code>TraceRef</code>.
* @param level Has value 1 to N, where value 1 means last called method
* and higher numbers mean callers.
*/
public static Map split(List traces, int level) {
if (level < 1)
throw new IllegalArgumentException(String.valueOf(level));
Map map=new HashMap();
Iterator it=traces.iterator();
while (it.hasNext()) {
TraceRef tr=(TraceRef) it.next();
List frames=tr.getFrames();
if (frames.size() < level)
continue;
FrameRef keyFrame=(FrameRef) frames.get(frames.size()-level);
List bucket=(List) map.get(keyFrame);
if (bucket==null) {
bucket=new ArrayList();
map.put(keyFrame, bucket);
}
bucket.add(tr);
}
return map;
}
/** Sums a list of <code>CPUStat</code> and returns a new <code>CPUStat
* </code> with the summed values.
*/
public static CPUStat getSumOfCPUStat(List list) {
CPUStatSum sum=new CPUStatSum();
Iterator it=list.iterator();
while (it.hasNext()) {
CPUStat stat=(CPUStat) it.next();
sum.add(stat);
}
return sum;
}
/** Helper class for summing CPUStat.
*/
private static class CPUStatSum implements CPUStat {
private long hits;
private long time;
private void add(CPUStat stat) {
hits += stat.getCPUHitsCount();
time += stat.getCPUPureTime();
}
public long getCPUHitsCount() {
return hits;
}
public long getCPUPureTime() {
return time;
}
public void addCPUStatListener( CPUStatListener listener) {
throw new UnsupportedOperationException();
}
public void removeCPUStatListener( CPUStatListener listener) {
throw new UnsupportedOperationException();
}
}
}
/*
* $Log: BacktraceSupport.java,v $
* Revision 1.1 2002/08/23 18:13:42 petrul
* added cpu backtrace view
*
*/
|