[Lutinutil-commits] r982 - in trunk/lutinutilextra: . doc src/java/org/codelutin/profiling
Author: tchemit Date: 2008-08-04 20:00:39 +0000 (Mon, 04 Aug 2008) New Revision: 982 Modified: trunk/lutinutilextra/doc/index.rst trunk/lutinutilextra/pom.xml trunk/lutinutilextra/src/java/org/codelutin/profiling/LutinTrace.java Log: passage en projet UTF8 reformat nettoyage des import Modified: trunk/lutinutilextra/doc/index.rst =================================================================== (Binary files differ) Modified: trunk/lutinutilextra/pom.xml =================================================================== --- trunk/lutinutilextra/pom.xml 2008-08-04 19:59:45 UTC (rev 981) +++ trunk/lutinutilextra/pom.xml 2008-08-04 20:00:39 UTC (rev 982) @@ -1,138 +1,139 @@ -<?xml version="1.0" encoding="ISO-8859-1"?> +<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <!--The version of maven's project object model--> - <modelVersion>4.0.0</modelVersion> - - <!--lutinproject.xml--> - <parent> - <groupId>lutinlib</groupId> - <artifactId>lutinproject</artifactId> - <version>2.0</version> - </parent> - - <!--A unique name for this project--> - <artifactId>lutinutilextra</artifactId> - <name>Lutin utilities extra library</name> - - <!--ejb, jar, war...--> - <packaging>jar</packaging> - - <!--Version--> - <version>0.1</version> - - <!--Description--> - <description> - Librairie de classe Java utile � tout projet. - </description> - <inceptionYear>2006</inceptionYear> - - <!--Tracking--> - <issueManagement> - <url>http://labs.libre-entreprise.org/tracker/?group_id=12</url> - </issueManagement> - - <!--Librairies--> - <dependencies> - <dependency> - <groupId>lutinlib</groupId> - <artifactId>lutinutil</artifactId> - <version>0.23</version> - <scope>compile</scope> - </dependency> + <!--The version of maven's project object model--> + <modelVersion>4.0.0</modelVersion> - <dependency> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - <version>1.0.3</version> - <scope>compile</scope> - </dependency> + <!--lutinproject.xml--> + <parent> + <groupId>lutinlib</groupId> + <artifactId>lutinproject</artifactId> + <version>2.0</version> + </parent> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.1</version> - <scope>compile</scope> - </dependency> + <!--A unique name for this project--> + <artifactId>lutinutilextra</artifactId> + <name>Lutin utilities extra library</name> - <dependency> - <groupId>aspectwerkz</groupId> - <artifactId>aspectwerkz-core</artifactId> - <version>2.0</version> - <scope>compile</scope> - </dependency> + <!--ejb, jar, war...--> + <packaging>jar</packaging> - <dependency> - <groupId>aspectwerkz</groupId> - <artifactId>aspectwerkz</artifactId> - <version>2.0</version> - <scope>compile</scope> - </dependency> + <!--Version--> + <version>0.1</version> - <dependency> - <groupId>aspectwerkz</groupId> - <artifactId>aspectwerkz-jdk5</artifactId> - <version>2.0</version> - <scope>compile</scope> - </dependency> + <!--Description--> + <description> + Librairie de classe Java utile à tout projet. + </description> + <inceptionYear>2006</inceptionYear> - <dependency> - <groupId>dom4j</groupId> - <artifactId>dom4j</artifactId> - <version>1.6.1</version> - <scope>compile</scope> - </dependency> + <!--Tracking--> + <issueManagement> + <url>http://labs.libre-entreprise.org/tracker/?group_id=12</url> + </issueManagement> - </dependencies> + <!--Librairies--> + <dependencies> + <dependency> + <groupId>lutinlib</groupId> + <artifactId>lutinutil</artifactId> + <version>0.23</version> + <scope>compile</scope> + </dependency> -<!-- - | surcharge des valeurs par defaut - +--> - <mailingLists> - <mailingList> - <name>lutinutil-devel</name> - <subscribe>http://lists.labs.libre-entreprise.org/mailman/listinfo/lutinutil-devel</subscribe> - <unsubscribe>http://lists.labs.libre-entreprise.org/mailman/listinfo/lutinutil-devel</unsubscribe> - <archive>http://lists.labs.libre-entreprise.org/pipermail/lutinutil-devel/</archive> - </mailingList> - <mailingList> - <name>lutinutil-user</name> - <subscribe>http://lists.labs.libre-entreprise.org/mailman/listinfo/lutinutil-user</subscribe> - <unsubscribe>http://lists.labs.libre-entreprise.org/mailman/listinfo/lutinutil-user</unsubscribe> - <archive>http://lists.labs.libre-entreprise.org/pipermail/lutinutil-user/</archive> - </mailingList> - </mailingLists> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + <version>1.0.3</version> + <scope>compile</scope> + </dependency> - <scm> - <url>http://cvs.labs.libre-entreprise.org/cgi-bin/cvsweb.cgi/?cvsroot=lutinutil</url> - <connection>scm:cvs:pserver:anonymous@cvs.labs.libre-entreprise.org:/cvsroot/lutinutil:${pom.artifactId}</connection> - </scm> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.1</version> + <scope>compile</scope> + </dependency> - <profiles> - <profile> - <id>project</id> + <dependency> + <groupId>aspectwerkz</groupId> + <artifactId>aspectwerkz-core</artifactId> + <version>2.0</version> + <scope>compile</scope> + </dependency> - <activation> - <activeByDefault>true</activeByDefault> - </activation> - - <properties> - <!--Source base dir--> - <maven.src.dir>${basedir}/src</maven.src.dir> - - <!--Test--> - <maven.test.skip>true</maven.test.skip> + <dependency> + <groupId>aspectwerkz</groupId> + <artifactId>aspectwerkz</artifactId> + <version>2.0</version> + <scope>compile</scope> + </dependency> - <!--Compile with ?--> - <maven.compile.source>1.5</maven.compile.source> - <maven.compile.target>1.5</maven.compile.target> + <dependency> + <groupId>aspectwerkz</groupId> + <artifactId>aspectwerkz-jdk5</artifactId> + <version>2.0</version> + <scope>compile</scope> + </dependency> - <!--Main class in JAR --> - <maven.jar.main.class>org.codelutin.util.Resource</maven.jar.main.class> - </properties> - </profile> - </profiles> + <dependency> + <groupId>dom4j</groupId> + <artifactId>dom4j</artifactId> + <version>1.6.1</version> + <scope>compile</scope> + </dependency> - + </dependencies> + + <!-- + | surcharge des valeurs par defaut + +--> + <mailingLists> + <mailingList> + <name>lutinutil-devel</name> + <subscribe>http://lists.labs.libre-entreprise.org/mailman/listinfo/lutinutil-devel</subscribe> + <unsubscribe>http://lists.labs.libre-entreprise.org/mailman/listinfo/lutinutil-devel</unsubscribe> + <archive>http://lists.labs.libre-entreprise.org/pipermail/lutinutil-devel/</archive> + </mailingList> + <mailingList> + <name>lutinutil-user</name> + <subscribe>http://lists.labs.libre-entreprise.org/mailman/listinfo/lutinutil-user</subscribe> + <unsubscribe>http://lists.labs.libre-entreprise.org/mailman/listinfo/lutinutil-user</unsubscribe> + <archive>http://lists.labs.libre-entreprise.org/pipermail/lutinutil-user/</archive> + </mailingList> + </mailingLists> + + <scm> + <url>http://cvs.labs.libre-entreprise.org/cgi-bin/cvsweb.cgi/?cvsroot=lutinutil</url> + <connection>scm:cvs:pserver:anonymous@cvs.labs.libre-entreprise.org:/cvsroot/lutinutil:${pom.artifactId} + </connection> + </scm> + + <profiles> + <profile> + <id>project</id> + + <activation> + <activeByDefault>true</activeByDefault> + </activation> + + <properties> + <!--Source base dir--> + <maven.src.dir>${basedir}/src</maven.src.dir> + + <!--Test--> + <maven.test.skip>true</maven.test.skip> + + <!--Compile with ?--> + <maven.compile.source>1.5</maven.compile.source> + <maven.compile.target>1.5</maven.compile.target> + + <!--Main class in JAR --> + <maven.jar.main.class>org.codelutin.util.Resource</maven.jar.main.class> + </properties> + </profile> + </profiles> + + </project> Modified: trunk/lutinutilextra/src/java/org/codelutin/profiling/LutinTrace.java =================================================================== --- trunk/lutinutilextra/src/java/org/codelutin/profiling/LutinTrace.java 2008-08-04 19:59:45 UTC (rev 981) +++ trunk/lutinutilextra/src/java/org/codelutin/profiling/LutinTrace.java 2008-08-04 20:00:39 UTC (rev 982) @@ -1,27 +1,26 @@ - /* *##% - * Copyright (C) 2006 - * Ifremer, 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 - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ +* Copyright (C) 2006 +* Ifremer, 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 +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*##%*/ /* * * Trace.aj * - * Created: 25 ao�t 06 22:19:21 + * Created: 25 août 06 22:19:21 * * @author poussin * @version $Revision$ @@ -32,13 +31,6 @@ package org.codelutin.profiling; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Stack; - import org.apache.commons.lang.time.DurationFormatUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -49,76 +41,82 @@ import org.codehaus.aspectwerkz.joinpoint.JoinPoint; import org.codehaus.aspectwerkz.joinpoint.MethodSignature; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Stack; + /** * Permet de tracer les appels aux methodes. - * <p> - * Pour l'utiliser il faut d�finir un fichier XML qui intercepte les methodes + * <p/> + * Pour l'utiliser il faut définir un fichier XML qui intercepte les methodes * souhaiter. * <pre> -<?xml version="1.0" encoding="ISO-8859-1"?> - -<!DOCTYPE aspectwerkz PUBLIC - "-//AspectWerkz//DTD//EN" - "http://aspectwerkz.codehaus.org/dtd/aspectwerkz2.dtd"> - -<aspectwerkz> - <system id="sample"> - <aspect class="fr.ifremer.isisfish.aspect.TraceIsis"> - <pointcut name="executeMethod"> - execution(* fr.ifremer.isisfish.datastore.ResultStorage.*(..)) - || execution(* fr.ifremer.isisfish.aspect.Cache.*(..)) - || execution(* fr.ifremer.isisfish.aspect.Trace.*(..)) - || execution(* org.codelutin.topia..*(..)) - || execution(* org.codelutin.math.matrix..*(..)) - || execution(* fr.ifremer.isisfish.types..*(..)) - || execution(* org.apache.commons.collections..*(..)) - </pointcut> - </aspect> - </system> -</aspectwerkz> - * + * <?xml version="1.0" encoding="ISO-8859-1"?> + * <p/> + * <!DOCTYPE aspectwerkz PUBLIC + * "-//AspectWerkz//DTD//EN" + * "http://aspectwerkz.codehaus.org/dtd/aspectwerkz2.dtd"> + * <p/> + * <aspectwerkz> + * <system id="sample"> + * <aspect class="fr.ifremer.isisfish.aspect.TraceIsis"> + * <pointcut name="executeMethod"> + * execution(* fr.ifremer.isisfish.datastore.ResultStorage.*(..)) + * || execution(* fr.ifremer.isisfish.aspect.Cache.*(..)) + * || execution(* fr.ifremer.isisfish.aspect.Trace.*(..)) + * || execution(* org.codelutin.topia..*(..)) + * || execution(* org.codelutin.math.matrix..*(..)) + * || execution(* fr.ifremer.isisfish.types..*(..)) + * || execution(* org.apache.commons.collections..*(..)) + * </pointcut> + * </aspect> + * </system> + * </aspectwerkz> + * <p/> * </pre> * Ensuite il faut lancer la JVM avec deux options * <li> -javaagent:path/to/aspectwerkz-jdk5-2.0.jar * <li> -Daspectwerkz.definition.file=path/to/trace-aop.xml - * - * il doit �tre possible d'utiliser des noms normalis� et + * <p/> + * il doit être possible d'utiliser des noms normalisé et * trouvable dans le classpath a la place de -Daspectwerkz.definition.file * <li> /aspectwerkz.xml * <li> META-INF/aop.xml * <li> WEB-INF/aop.xml - * + * <p/> * Ensuite pour afficher les statistiques dans votre programme * <li> log.info(LutinTrace.getStatistiqueAndClear()); * <li> LutinTrace.printStatistiqueAndClear(); - * - * <p> - * - * Il doit �tre possible, plutot que d'�crire un fichier XML, de sous classer + * <p/> + * <p/> + * <p/> + * Il doit être possible, plutot que d'écrire un fichier XML, de sous classer * LutinTrace en ajoutant par exemple - * <p> - * @Expression( - "execution(* fr.ifremer.isisfish.datastore.ResultStorage.*(..))" + - "|| execution(* fr.ifremer.isisfish.aspect.Cache.*(..))" + - "|| execution(* fr.ifremer.isisfish.aspect.Trace.*(..))" + - "|| execution(* org.codelutin.topia..*(..))" + - "|| execution(* org.codelutin.math.matrix..*(..))" + - "|| execution(* fr.ifremer.isisfish.types..*(..))" + - "|| execution(* org.apache.commons.collections..*(..))" - ) - Pointcut executeMethod; - * </p> - * + * <p/> + * * @author poussin + * @Expression( "execution(* fr.ifremer.isisfish.datastore.ResultStorage.*(..))" + + * "|| execution(* fr.ifremer.isisfish.aspect.Cache.*(..))" + + * "|| execution(* fr.ifremer.isisfish.aspect.Trace.*(..))" + + * "|| execution(* org.codelutin.topia..*(..))" + + * "|| execution(* org.codelutin.math.matrix..*(..))" + + * "|| execution(* fr.ifremer.isisfish.types..*(..))" + + * "|| execution(* org.apache.commons.collections..*(..))" + * ) + * Pointcut executeMethod; + * </p> */ @Aspect("perJVM") public class LutinTrace { /** to use log facility, just put in your code: log.info("..."); */ static private Log log = LogFactory.getLog(LutinTrace.class); - + static private List<LutinTrace> instances = new ArrayList<LutinTrace>(); - + /** nombre d'appel */ final static public int STAT_CALL = 0; /** nombre d'appel vers une autre method depuis cette methode */ @@ -126,26 +124,26 @@ /** temps mini d'execution de cette methode (sans le temps des autres methodes) */ final static public int STAT_TIME_MIN = 2; /** temps max d'execution de cette methode (sans le temps des autres methodes) */ - final static public int STAT_TIME_MAX = 3; + final static public int STAT_TIME_MAX = 3; /** temps total d'execution de cette methode (sans le temps des autres methodes) */ - final static public int STAT_TIME_TOTAL = 4; + final static public int STAT_TIME_TOTAL = 4; /** temps total d'execution de cette methode (avec le temps des autres methodes) */ - final static public int STAT_TIME_TOTAL_NEST_METHOD = 5; + final static public int STAT_TIME_TOTAL_NEST_METHOD = 5; /** nombre d'appel vers une autre method depuis cette methode */ - final static private int STACK_CALL_NEST_METHOD = 0; + final static private int STACK_CALL_NEST_METHOD = 0; /** heure de depart de l'appel a la methode (sans le temps des autres methodes) */ - final static private int STACK_TIME_START = 1; + final static private int STACK_TIME_START = 1; /** heure de depart de l'appel a la methode (avec le temps des autres methodes) */ - final static private int STACK_TIME_START_NEST_METHOD = 2; - - - /** array : [call's numbers, call do, min time, max time, total time, total time with child]*/ + final static private int STACK_TIME_START_NEST_METHOD = 2; + + + /** array : [call's numbers, call do, min time, max time, total time, total time with child] */ protected Map<Method, long[]> statistiques = new LinkedHashMap<Method, long[]>(); - + /** array : [nest method call, start time, start time with child] */ - protected Stack<long[]> callStack = new Stack<long[]>(); - + protected Stack<long[]> callStack = new Stack<long[]>(); + // @Expression( // "execution(* fr.ifremer.isisfish.datastore.ResultStorage.*(..))" + // "|| execution(* fr.ifremer.isisfish.aspect.Cache.*(..))" + @@ -156,50 +154,50 @@ // "|| execution(* org.apache.commons.collections..*(..))" // ) // Pointcut executeMethod; - + public LutinTrace() { instances.add(this); } - + public long[] getStatistiques(Method method) { - long [] result = statistiques.get(method); + long[] result = statistiques.get(method); if (result == null) { result = new long[]{0, 0, 0, 0, 0, 0}; statistiques.put(method, result); } return result; } - + @Before("executeMethod") - public void traceBeforeExecute (JoinPoint jp) { + public void traceBeforeExecute(JoinPoint jp) { // ajout dans le stack long current = System.nanoTime(); - long [] stackItem = new long[]{0, current, current}; + long[] stackItem = new long[]{0, current, current}; callStack.push(stackItem); - - + + } - + @AfterThrowing("executeMethod") - public void traceAfterThrowingExecute (JoinPoint jp) { + public void traceAfterThrowingExecute(JoinPoint jp) { // si une exeption est leve, il faut faire la meme chose traceAfterExecute(jp); } - + @After("executeMethod") - public void traceAfterExecute (JoinPoint jp) { - Method method = ((MethodSignature)jp.getSignature()).getMethod(); + public void traceAfterExecute(JoinPoint jp) { + Method method = ((MethodSignature) jp.getSignature()).getMethod(); long current = System.nanoTime(); - + if (callStack.isEmpty()) { log.warn("Empty stack in afterExecute for method " + method.getName()); } else { - long [] stackItem = callStack.pop(); + long[] stackItem = callStack.pop(); long timeSpent = current - stackItem[STACK_TIME_START]; long timeSpentNestMethod = current - stackItem[STACK_TIME_START_NEST_METHOD]; - - long [] stat = getStatistiques(method); + + long[] stat = getStatistiques(method); stat[STAT_CALL]++; // add +1 to call number stat[STAT_CALL_NEST_METHOD] += stackItem[STACK_CALL_NEST_METHOD]; stat[STAT_TIME_TOTAL] += timeSpent; @@ -210,17 +208,17 @@ if (stat[STAT_TIME_MAX] < timeSpent) { stat[STAT_TIME_MAX] = timeSpent; } - + if (!callStack.isEmpty()) { - long [] parent = callStack.peek(); + long[] parent = callStack.peek(); parent[STACK_CALL_NEST_METHOD]++; // add +1 to call number nest method parent[STACK_TIME_START] += timeSpentNestMethod; // remove to time all time spent in nest method (yes + to remove :) } } - - // ajouter le delta de temps dans le temps pass� dans la m�thod - - // il faud garder le temps pass� dans l'appel d'autre methode de la stack + + // ajouter le delta de temps dans le temps passé dans la méthod + + // il faud garder le temps passé dans l'appel d'autre methode de la stack // --> A // ========= // --> B @@ -232,22 +230,19 @@ // <-- C // ========= // <-- A - - // le temps reellement pass� dans A est represent� par les ===== + + // le temps reellement passé dans A est representé par les ===== } - /** - * Affiche les statistiques - * - */ + /** Affiche les statistiques */ static public String getStatistiqueAndClear() { StringBuffer result = new StringBuffer(); for (LutinTrace trace : instances) { result.append("--- Statistiques ---\n"); for (Method method : trace.statistiques.keySet()) { - long [] stat = trace.getStatistiques(method); + long[] stat = trace.getStatistiques(method); long meanTime = stat[STAT_TIME_TOTAL] / stat[STAT_CALL]; - result.append(method + "\t" + + result.append(method + "\t" + " call: " + stat[STAT_CALL] + // TIme is in nano not millis, we must divide by 1000000 " min: " + DurationFormatUtils.formatDuration(stat[STAT_TIME_MIN] / 1000000, "s'.'S") + @@ -264,7 +259,7 @@ instances.clear(); return result.toString(); } - + static public void printStatistiqueAndClear() { String stat = getStatistiqueAndClear(); if (stat != null && !"".equals(stat)) {
participants (1)
-
tchemit@users.labs.libre-entreprise.org