Sunday, August 18, 2013

PerfSpy 6 -- PerfSpy-Config.xml

This is the file that is used by PerfSpy, and you can tweak this file to get the information you need:

Snippet 1:
<!-- you can skip capturing certain methods -->
        <!-- <skip>com.yourcompany.zoo.animal.Dolphin.backflip</skip> -->
       
        1)<entry target="com.yourcompany.zoo.animal.Dolphin">  
                <!-- you can skip capturing certain methods -->
                <!--  <skip>com.yourcompany.zoo.animal.Dolphin.backflip</skip> -->
                2)<detailOps parts="all" all="true">   
  <!-- <detailOp parts="param,return">-->
                  <!--<detailOp>com.yourcompany.zoo.animal.People.Trainer.award</detailOp>-->                        
                 </detailOps> 
                3)<connection provider="com.perfspy.monitor.dao.SimpleConnectionProvider">
                        <url>jdbc:oracle:thin:@127.0.0.1:1521:ORCL</url>               
                        <user>PerfSpyDemo</user>
                        <password>PerfSpyDemo</password>
                </connection>
        </entry>
1): <entry target="com.yourcompany.zoo.animal.Dolphin"
Recall PerfSpyDemoAsepct defines cflowOps as:
@Pointcut("cflow(execution(*  com.yourcompany.zoo.animal.Animal.playTricks(..)  ) )")
        public void cflowOps() {
        }
cflowOps captures Animal.playTricks, so it can spy on both Dolphin and Panda. Panda is cute, but everyone knows what it does: eat, sleep and refuse to have babies, so it is not very interesting.  Dolphin, on the other hand, will be really interesting to see. So you can specify the target to be “com.yourcompany.zoo.animal.Dolphin”.

This flexibility is very useful, in a real application, a lot of common functions are taken care of by frameworks. For example, my legacy application uses Struts1, I define cflowOps() to capture org.apache.struts.action.Action.execute(), and in PerfSpy-Config.xml, I configure which specific action I’d like to capture at will. And I can go further and map between a page and a Struts action, and spy on a page through configuration.

2): <detailOps parts="all" all="true"/>
Specify how much information you’d like to capture. It is not always the more, the better. For one thing, the more you capture, the more performance overhead PerSpy imposes. But for this demo application, we can indulge our innate greedy nature, and capture every input parameter and return value (parts="all") of all methods (all="true"). PerfSpy serializes objects into JSon format.

3):     <connection provider="com.perfspy.monitor.dao.SimpleConnectionProvider">
Defines where PerfSpy stores the captured information. PerfSpy uses Oracle, for one simple reason: Oracle has “connect by” feature, which is very convenient for querying hierarchical data. Method invocation is such a hierarchical structure.

Snippet 2:
<analysis>
                <analyzer>com.perfspy.monitor.analyze.SlowAnalyzer</analyzer>
                <analyzer>com.perfspy.monitor.analyze.DuplicationAnalyzer</analyzer>
                <slow>2</slow> <!--in seconds -->
        </analysis>
By default, PerfSpy has 2 code analyzers: SlowAnalyzer (analyze if a method innovation takes too long – exceeding 2 seconds, e.g.), DuplicationAnalyzer (analyze if a method is repeatedly invoked).

Snippet 3:
          <logToDb>
                <queuesize simple="10" detail="3"/>
                <batchsize simple="4" detail="2"/>
        </logToDb> 
This defines how PerfSpy logs information to the database. While PerfSpy is busy spying on every method, it doesn’t log information immediately to the database. PerfSpy weaves around the application flow, once it gets the information it requires, in order not to impede the application flow, it dispatches writing-to-database tasks to a queue, and writing-to-database is done in a separate thread:

queuesize specifies the size limit of the queue. If detailed logging is configured, the task becomes heavier and you should keep fewer tasks in the queue to save memory. detail refers to the queue size when detailed logging is configured.  simple refers to the queue size when detailed logging is not configured.

batchsize specifies how many tasks to be written before committing to the database . If detailed logging is configured, the task becomes heavier and you should commit more often to save memory.

Snippet 4:
<perfspyio>    
<Types>
        1)      <include within="com.yourcompany.zoo"/>                
        </Types>
               
        2) <collection limit="5"/>     
</perfspyio>
1): <include within="com.yourcompany.zoo"/>            
Serialize objects that belong to classes inside package  com.yourcompany.zoo. JDK classes (inside java packages) will be written as well.               

2): <collection limit="5">
If an object is an array, of java.util.Collection type, or of java.util.Map type, specifies how many elements to write. The more you want to capture, the more performance overhead.



No comments:

Post a Comment