org.nuiton.profiling
Class NuitonTrace

java.lang.Object
  extended by org.nuiton.profiling.NuitonTrace

public abstract class NuitonTrace
extends Object

TODO poussin 20110824 check documentation: this documentation is for aspectwerkz, there are little change for aspectj. see example file aop.xml Permet de tracer les appels aux methodes.

Pour l'utiliser il faut définir un fichier XML qui intercepte les methodes souhaiter.

 <?xml version="1.0" encoding="UTF-8"?>
 <!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.nuiton.topia..*(..))
 || execution(* org.nuiton.math.matrix..*(..))
 || execution(* fr.ifremer.isisfish.types..*(..))
 || execution(* org.apache.commons.collections..*(..))
 </pointcut>
 </aspect>
 </system>
 </aspectwerkz>
 
Ensuite il faut lancer la JVM avec deux options
 -javaagent:path/to/aspectwerkz-jdk5-2.0.jar
 -Daspectwerkz.definition.file=path/to/trace-aop.xml
 
Il est possible d'utiliser des noms normalisé et trouvable dans le classpath a la place de -Daspectwerkz.definition.file
  • /aspectwerkz.xml
  • META-INF/aop.xml
  • WEB-INF/aop.xml
    Ensuite pour afficher les statistiques dans votre programme
  • log.info(NuitonTrace.getStatisticsAndClear());
  • NuitonTrace.printStatistiqueAndClear(); Il doit être possible, plutot que d'écrire un fichier XML, de sous classer NuitonTrace en ajoutant par exemple

     \@Expression( "execution(* fr.ifremer.isisfish.datastore.ResultStorage.*(..))" +
     "|| execution(* fr.ifremer.isisfish.aspect.Cache.*(..))" +
     "|| execution(* fr.ifremer.isisfish.aspect.Trace.*(..))" +
     "|| execution(* org.nuiton.topia..*(..))" +
     "|| execution(* org.nuiton.math.matrix..*(..))" +
     "|| execution(* fr.ifremer.isisfish.types..*(..))" +
     "|| execution(* org.apache.commons.collections..*(..))"
     )
     Pointcut executeMethod;
     

    Voir la classe de test org.nuiton.profiling.NuitonTraceTest.

    Author:
    bpoussin , tchemit
    See Also:
    http://aspectwerkz.codehaus.org/definition_issues.html

    Nested Class Summary
    protected static class NuitonTrace.Call
              Represente un call de methode
    protected static class NuitonTrace.Caller<E>
              Classe qui permet d'ajouter un element et compte le nombre de fois que l'on a ajoute cet element.
    protected static class NuitonTrace.Statistic
              Statistique sur un appele de methode
     
    Field Summary
    protected  Map<Method,NuitonTrace.Caller<Method>> callers
               
    protected static ThreadLocal<Stack<NuitonTrace.Call>> callStack
              array : [nest method call, start time, start time with child] On ne melange pas les stack entre les threads, sinon les resultats ne veulent plus rien dire car toutes les methodes des threads sont melangees
    protected  Map<Method,NuitonTrace.Statistic> statistics
              array : [call's numbers, call do, min time, max time, total time, total time with child]
     
    Constructor Summary
    NuitonTrace()
               
     
    Method Summary
     NuitonTrace.Caller<Method> getCallers(Method method)
              Retourne la liste des appelant pour la methode passee en parametre
     NuitonTrace.Statistic getStatistics(Method method)
              Retourne les statistiques d'appele pour la methode passee en parametre
    static String getStatisticsAndClear()
               
    static String getStatisticsCSVAndClear()
               
    static void printStatisticsAndClear()
               
    static void printStatisticsAndClear(PrintStream printer)
               
     void traceAfterExecute(org.aspectj.lang.JoinPoint jp)
               
     void traceAfterThrowingExecute(org.aspectj.lang.JoinPoint jp)
               
     void traceBeforeExecute(org.aspectj.lang.JoinPoint jp)
               
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    statistics

    protected Map<Method,NuitonTrace.Statistic> statistics
    array : [call's numbers, call do, min time, max time, total time, total time with child]


    callers

    protected Map<Method,NuitonTrace.Caller<Method>> callers

    callStack

    protected static final ThreadLocal<Stack<NuitonTrace.Call>> callStack
    array : [nest method call, start time, start time with child] On ne melange pas les stack entre les threads, sinon les resultats ne veulent plus rien dire car toutes les methodes des threads sont melangees

    Constructor Detail

    NuitonTrace

    public NuitonTrace()
    Method Detail

    getStatistics

    public NuitonTrace.Statistic getStatistics(Method method)
    Retourne les statistiques d'appele pour la methode passee en parametre

    Parameters:
    method -
    Returns:

    getCallers

    public NuitonTrace.Caller<Method> getCallers(Method method)
    Retourne la liste des appelant pour la methode passee en parametre

    Parameters:
    method -
    Returns:

    traceBeforeExecute

    public void traceBeforeExecute(org.aspectj.lang.JoinPoint jp)

    traceAfterThrowingExecute

    public void traceAfterThrowingExecute(org.aspectj.lang.JoinPoint jp)

    traceAfterExecute

    public void traceAfterExecute(org.aspectj.lang.JoinPoint jp)

    getStatisticsCSVAndClear

    public static String getStatisticsCSVAndClear()
    Returns:
    les statistiques in CSV format

    getStatisticsAndClear

    public static String getStatisticsAndClear()
    Returns:
    les statistiques

    printStatisticsAndClear

    public static void printStatisticsAndClear()

    printStatisticsAndClear

    public static void printStatisticsAndClear(PrintStream printer)


    Copyright © 2004-2011 CodeLutin. All Rights Reserved.