Author: tchemit Date: 2011-08-23 09:37:25 +0200 (Tue, 23 Aug 2011) New Revision: 2180 Url: http://nuiton.org/repositories/revision/nuiton-utils/2180 Log: Evolution #1704: Make works NuitonTrace again Added: trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/NuitonTraceTest.java trunk/nuiton-profiling/src/test/resources/META-INF/ trunk/nuiton-profiling/src/test/resources/META-INF/aop.xml Removed: trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/MyNuitonTrace.java Modified: trunk/nuiton-profiling/pom.xml trunk/nuiton-profiling/src/license/THIRD-PARTY.properties trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java trunk/nuiton-profiling/src/test/resources/log4j.properties Modified: trunk/nuiton-profiling/pom.xml =================================================================== --- trunk/nuiton-profiling/pom.xml 2011-08-22 17:35:46 UTC (rev 2179) +++ trunk/nuiton-profiling/pom.xml 2011-08-23 07:37:25 UTC (rev 2180) @@ -108,8 +108,9 @@ <!-- extra files to include in release --> <redmine.releaseFiles>${redmine.libReleaseFiles}</redmine.releaseFiles> - <!-- Configure aop configuration --> - <maven.surefire.debug>-javaagent:target/lib/aspectwerkz-jdk5-2.0.jar -Daspectwerkz.definition.file=src/test/resources/aop.xml</maven.surefire.debug> + <!-- Configure aop --> + <maven.surefire.debug>-javaagent:target/lib/aspectwerkz-jdk5-2.0.jar</maven.surefire.debug> + <!--<maven.surefire.debug>-javaagent:target/lib/aspectwerkz-jdk5-2.0.jar -Daspectwerkz.definition.file=src/test/resources/aop.xml</maven.surefire.debug>--> </properties> <!-- ************************************************************* --> Modified: trunk/nuiton-profiling/src/license/THIRD-PARTY.properties =================================================================== --- trunk/nuiton-profiling/src/license/THIRD-PARTY.properties 2011-08-22 17:35:46 UTC (rev 2179) +++ trunk/nuiton-profiling/src/license/THIRD-PARTY.properties 2011-08-23 07:37:25 UTC (rev 2180) @@ -1,11 +1,11 @@ # Generated by org.codehaus.mojo.license.AddThirdPartyMojo #------------------------------------------------------------------------------- # Already used licenses in project : -# - ASM License # - Apache Software License # - Apache Software License, Version 2.0 # - BSD License # - COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 +# - Common Public License Version 1.0 # - Indiana University Extreme! Lab Software License, vesion 1.1.1 # - Jaxen license # - Lesser General Public License (LGPL) @@ -18,7 +18,7 @@ # Please fill the missing licenses for dependencies : # # -#Thu Aug 18 07:42:25 CEST 2011 +#Mon Aug 22 19:29:18 CEST 2011 aspectwerkz--aspectwerkz--2.0=GNU Lesser General Public License aspectwerkz--aspectwerkz-core--2.0=GNU Lesser General Public License aspectwerkz--aspectwerkz-jdk5--2.0=GNU Lesser General Public License @@ -27,9 +27,6 @@ jaxen--jaxen--1.0-FCS=Jaxen license jrexx--jrexx--1.1.1=Apache Software License msv--msv--20020414=BSD License -org.nuiton.thirdparty--asm--1.5.4-snapshot=ASM License -org.nuiton.thirdparty--asm-attrs--1.5.4-snapshot=ASM License -org.nuiton.thirdparty--asm-util--1.5.4-snapshot=ASM License qdox--qdox--1.4=Apache Software License, Version 2.0 relaxngDatatype--relaxngDatatype--20020414=BSD License saxpath--saxpath--1.0-FCS=SAXPath License Modified: trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java =================================================================== --- trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java 2011-08-22 17:35:46 UTC (rev 2179) +++ trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java 2011-08-23 07:37:25 UTC (rev 2180) @@ -67,10 +67,10 @@ * </pre> * Ensuite il faut lancer la JVM avec deux options * <pre> - * -Djavaagent:path/to/aspectwerkz-jdk5-2.0.jar + * -javaagent:path/to/aspectwerkz-jdk5-2.0.jar * -Daspectwerkz.definition.file=path/to/trace-aop.xml * </pre> - * il doit être possible d'utiliser des noms normalisé et + * Il est 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 @@ -81,7 +81,7 @@ * <li> NuitonTrace.printStatistiqueAndClear(); * Il doit être possible, plutot que d'écrire un fichier XML, de sous classer * NuitonTrace en ajoutant par exemple - * + * <p/> * <pre> * \@Expression( "execution(* fr.ifremer.isisfish.datastore.ResultStorage.*(..))" + * "|| execution(* fr.ifremer.isisfish.aspect.Cache.*(..))" + @@ -93,38 +93,44 @@ * ) * Pointcut executeMethod; * </pre> - * * <p/> + * Voir la classe de test {@code org.nuiton.profiling.NuitonTraceTest}. * - * @author poussin - * - * </p> + * @author bpoussin <poussin@codelutin.com> + * @author tchemit <chemit@codelutin.com> */ @Aspect("perJVM") public class NuitonTrace { + static private final List<NuitonTrace> instances = new ArrayList<NuitonTrace>(); + /** to use log facility, just put in your code: log.info("..."); */ static private Log log = LogFactory.getLog(NuitonTrace.class); - static private List<NuitonTrace> instances = new ArrayList<NuitonTrace>(); - /** nombre d'appel */ final static public int STAT_CALL = 0; + /** nombre d'appel vers une autre method depuis cette methode */ final static public int STAT_CALL_NEST_METHOD = 1; + /** 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; + /** temps total d'execution de cette methode (sans le temps des autres methodes) */ 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; /** nombre d'appel vers une autre method depuis cette methode */ 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; + /** 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; @@ -216,7 +222,7 @@ /** @return les statistiques */ static public String getStatisticsAndClear() { - StringBuffer result = new StringBuffer(); + StringBuilder result = new StringBuilder(); for (NuitonTrace trace : instances) { result.append("--- Statistics ---\n"); for (Method method : trace.statistics.keySet()) { Deleted: trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/MyNuitonTrace.java =================================================================== --- trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/MyNuitonTrace.java 2011-08-22 17:35:46 UTC (rev 2179) +++ trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/MyNuitonTrace.java 2011-08-23 07:37:25 UTC (rev 2180) @@ -1,64 +0,0 @@ -/* - * #%L - * Nuiton Utils :: Nuiton Profiling - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2011 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.profiling; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.codehaus.aspectwerkz.annotation.Aspect; -import org.codehaus.aspectwerkz.annotation.Expression; -import org.codehaus.aspectwerkz.definition.Pointcut; - -/** - * Lanch this main with -javaagent:target/lib/aspectwerkz-jdk5-2.0.jar - * - * @author tchemit <chemit@codelutin.com> - * @since 2.3 - */ -@Aspect("perJVM") -public class MyNuitonTrace extends NuitonTrace { - - @Expression("execution(* org.apache.commons.logging.Log.*(..))") - Pointcut executeMethod; - - /** Logger. */ - private static final Log log = LogFactory.getLog(MyNuitonTrace.class); - - public static void main(String[] args) { - - log.debug("DEBUG"); - log.info("INFO"); - log.warn("WARN"); - log.warn("TRACE"); - - // trace should have somethin inside it... - String statisticsAndClear = getStatisticsAndClear(); -// Assert.assertTrue(StringUtils.isNotEmpty(statisticsAndClear)); - - if (log.isInfoEnabled()) { - log.info("First trace = " + statisticsAndClear); - } - } - -} Copied: trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/NuitonTraceTest.java (from rev 2178, trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/MyNuitonTrace.java) =================================================================== --- trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/NuitonTraceTest.java (rev 0) +++ trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/NuitonTraceTest.java 2011-08-23 07:37:25 UTC (rev 2180) @@ -0,0 +1,75 @@ +/* + * #%L + * Nuiton Utils :: Nuiton Profiling + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2011 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package org.nuiton.profiling; + +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Assert; +import org.junit.Test; + +/** + * Launch this test with -javaagent:target/lib/aspectwerkz-jdk5-2.0.jar + * + * @author tchemit <chemit@codelutin.com> + * @since 2.3 + */ +public class NuitonTraceTest { + + /** Logger. */ + private static final Log log = LogFactory.getLog(NuitonTraceTest.class); + + @Test + public void testAOP() { + + if (log.isDebugEnabled()) { + log.debug("DEBUG"); + } + if (log.isInfoEnabled()) { + log.info("INFO"); + } + + if (log.isErrorEnabled()) { + log.error("ERROR"); + } + + if (log.isWarnEnabled()) { + log.warn("WARN"); + } + + if (log.isTraceEnabled()) { + log.trace("TRACE"); + } + + // trace should have something inside it... + String statisticsAndClear = NuitonTrace.getStatisticsAndClear(); + Assert.assertTrue(StringUtils.isNotEmpty(statisticsAndClear)); + + if (log.isInfoEnabled()) { + log.info(statisticsAndClear); + } + } + +} Property changes on: trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/NuitonTraceTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/nuiton-profiling/src/test/resources/META-INF/aop.xml =================================================================== --- trunk/nuiton-profiling/src/test/resources/META-INF/aop.xml (rev 0) +++ trunk/nuiton-profiling/src/test/resources/META-INF/aop.xml 2011-08-23 07:37:25 UTC (rev 2180) @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + #%L + Nuiton Utils :: Nuiton Profiling + + $Id$ + $HeadURL$ + %% + Copyright (C) 2004 - 2011 CodeLutin + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + --> + +<!DOCTYPE aspectwerkz PUBLIC + "-//AspectWerkz//DTD//EN" + "http://aspectwerkz.codehaus.org/dtd/aspectwerkz2.dtd"> +<aspectwerkz> + <system id="webapp"> + <aspect class="org.nuiton.profiling.NuitonTrace"> + <pointcut name="executeMethod"> + <![CDATA[ execution(public * org.apache..*.*(..)) && !within(org.apache.log4j..*) && !within(org.apache.commons.lang..*)]]> + <!--<![CDATA[ execution(public * *..*.*(..))]]>--> + </pointcut> + <!--<pointcut name="executeMethod" expression="execution(public * org.apache..*(..))"/>--> + <!--<pointcut name="executeMethod"--> + <!--expression="execution(public * org.apache..*(..))"/>--> + <!--expression="execution(public * org.apache.commons..*(..)) && !within(org.apache.log4j..*) && !within(org.nuiton.profiling..*)"/>--> + </aspect> + <!--</package>--> + + </system> +</aspectwerkz> \ No newline at end of file Property changes on: trunk/nuiton-profiling/src/test/resources/META-INF/aop.xml ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/nuiton-profiling/src/test/resources/log4j.properties =================================================================== --- trunk/nuiton-profiling/src/test/resources/log4j.properties 2011-08-22 17:35:46 UTC (rev 2179) +++ trunk/nuiton-profiling/src/test/resources/log4j.properties 2011-08-23 07:37:25 UTC (rev 2180) @@ -23,19 +23,12 @@ # #L% ### # Global logging configuration -log4j.rootLogger=DEBUG, stdout, fileout +log4j.rootLogger=ERROR, stdout # Console output... log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n -log4j.appender.fileout=org.apache.log4j.FileAppender -log4j.appender.fileout.File=target/nuitontrace.log -log4j.appender.fileout.Append=true -log4j.appender.fileout.Threshold=DEBUG -log4j.appender.fileout.layout=org.apache.log4j.PatternLayout -log4j.appender.fileout.layout.ConversionPattern=%5p (%F:%L) %m%n - # package level -#log4j.logger.org.apache.commons.logging.Log=DEBUG +log4j.logger.org.nuiton.profiling=TRACE