Index: lutinutil/src/java/org/codelutin/util/CallAnalyse.java diff -u lutinutil/src/java/org/codelutin/util/CallAnalyse.java:1.3 lutinutil/src/java/org/codelutin/util/CallAnalyse.java:1.4 --- lutinutil/src/java/org/codelutin/util/CallAnalyse.java:1.3 Wed Jan 4 13:26:32 2006 +++ lutinutil/src/java/org/codelutin/util/CallAnalyse.java Thu Feb 21 16:15:49 2008 @@ -1,6 +1,6 @@ /* *##% * Copyright (C) 2005 - * Code Lutin, Cédric Pineau, Benjamin Poussin + * Code Lutin, C�dric Pineau, Benjamin Poussin * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -20,20 +20,23 @@ /* * * CallAnalyse.java * - * Created: 25 août 2005 14:09:22 CEST + * Created: 25 ao�t 2005 14:09:22 CEST * * @author Benjamin POUSSIN - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ * - * Last update: $Date: 2006-01-04 13:26:32 $ - * by : $Author: bpoussin $ + * Last update: $Date: 2008-02-21 16:15:49 $ + * by : $Author: thimel $ */ package org.codelutin.util; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.TreeMap; + import org.apache.commons.collections.primitives.ArrayLongList; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -43,11 +46,11 @@ * En debut de methode on appelle la methode {@link #enter}, et en fin de methode * la methode {@link #exit}. *

-* Ensuite on peut récuperer les statistiques par Thread ou de tous les threads +* Ensuite on peut r�cuperer les statistiques par Thread ou de tous les threads *

* On a comme statistique *

  • le temps d'execution -*
  • la memore utilisé +*
  • la memore utilis� *
  • le nombre d'appels */ public class CallAnalyse { // CallAnalyse @@ -82,7 +85,7 @@ } /** - * Permet de savoir si les statistiques sont activées ou non, pour le + * Permet de savoir si les statistiques sont activ�es ou non, pour le * thread courant */ static public boolean isActivate(){ @@ -100,9 +103,9 @@ } /** - * Indique la sortie de l'appel, name doit avoir ete utilisé lors d'un enter + * Indique la sortie de l'appel, name doit avoir ete utilis� lors d'un enter * @param name le nom de l'appel a monitorer, doit etre identique a - * celui utilisé pour la methode enter + * celui utilis� pour la methode enter */ static public void exit(String name){ ThreadStatistics t = stats.get(); @@ -112,14 +115,14 @@ } /** - * Retourne les statistiques pour le thread courant + * Returns the statistics for the current thread */ static public ThreadStatistics getThreadStatistics(){ return stats.get(); } /** - * Retourne les statistiques pour tous les threads + * Returns the statistics for all threads */ static public List getAllThreadStatistics(){ return listThreadStatistics; @@ -147,7 +150,36 @@ } } - static public class CallStatistics { + /** + * This method will get all the statistics from all the threads and put it + * all together in a {@link Map} which key is the name of the watched + * element and the value is its instance of {@link CallStatisticsSummary} + * + * @return A map with all collected statistics + */ + public static Map getSummary() { + Map results = new HashMap(); + for (ThreadStatistics stats : CallAnalyse.getAllThreadStatistics()) { + for (String name : stats.keySet()) { + CallStatisticsSummary stat = results.get(name); + if (stat == null) { + stat = new CallStatisticsSummary(name); + results.put(name, stat); + } + stat.addCallStats(stats.get(name)); + } + } + return results; + } + + /** + * CallStatistics is the class which handles values on excecution time and + * memory usage. + * Each CallStatistics object is for one particular name. + * + * @author bpoussin + */ + static public class CallStatistics implements Cloneable { protected String name = null; protected long calls = 0; protected long minTime = Long.MAX_VALUE; @@ -249,7 +281,49 @@ + "(" + StringUtil.convertMemory(getMinMemory()) + "/" + StringUtil.convertMemory(getAvgMemory()) + "/" + StringUtil.convertMemory(getMaxMemory()) + ")" ; } - } + + } //CallStatistics + + /** + * This class is collecting data from different CallStatistics classes by + * using the method {@link #addCallStats(org.codelutin.util.CallAnalyse.CallStatistics)}. + * + * @author thimel + */ + static public class CallStatisticsSummary extends CallStatistics { + + public CallStatisticsSummary(String name) { + super(name); + } + + /** + * This methods read the given

    CallStatistics

    and add values to + * its own + * @param other an other CallStatistics object + */ + public void addCallStats(CallStatistics other) { + if (other == null || this.equals(other)) { + return; + } + calls += other.getCalls(); + if(other.getMinTime() < minTime || minTime == Long.MAX_VALUE){ + minTime = other.getMinTime(); + } + if(other.getMaxTime() > maxTime){ + maxTime = other.getMaxTime(); + } + + sumTime += other.getSumTime(); + + if(other.getMinMemory() < minMemory || minMemory == Long.MAX_VALUE){ + minMemory = other.getMinMemory(); + } + if(other.getMaxMemory() > maxMemory){ + maxMemory = other.getMaxMemory(); + } + sumMemory += other.getSumMemory(); + } + } //CallStatisticsSummary } // CallAnalyse