Package measurements.suites

Source Code of measurements.suites.AllLocationsMeasurement$TrapMethodAspect2

// $Id: AllLocationsMeasurement.java,v 1.3 2008/11/18 10:41:01 anicoara Exp $
// =====================================================================

package measurements.suites;

import junit.framework.Assert;
import junit.framework.Test;
import ch.ethz.inf.util.junit.PerformanceTest;
import ch.ethz.inf.util.junit.PerformanceTestSuite;
import ch.ethz.prose.*;
import ch.ethz.prose.crosscut.Crosscut;
import ch.ethz.prose.crosscut.MethodCut;
import ch.ethz.prose.filter.*;

/**
* JUnit performs a suite of measurements for local interceptions
* of a method using <em>AllLocationsCrosscut</em>.
*
* The test can be used both in native and in runes mode.
* In both native and runes mode, the test
* <code>testLocalCall</code> calls a number of <code>RUNS</code>
* time a void method.
*
* If RUNES in enabled, the following measurements are meaningfull
* <ul>
* <li> <code>testLocalCallsNormal</code>: measure how much it takes
* to call RUNS times a trapped function while extracting argument values
* <li> <code>testLocalCallsFast</code>: measure how much it takes
* to call RUNS times a trapped function without retrieving the actual
* arguments from the stack.
* </ul>
*
* @version  $Revision: 1.3 $
* @author  Andrei Popovici
*/
public class AllLocationsMeasurement extends PerformanceTest {

  // fixture
  public void theMethodToCall() {
    int a;
    a=1;
  };

  public static class TrapMethodAspect1 extends DefaultAspect {
    public static class TrapMethodCrossc1 extends MethodCut {
      public void METHOD_ARGS() {}

      protected PointCutter pointCutter() {
        PointCutter x = Executions.before().AND(Within.method("theMethodToCall"));
        return x.AND(Within.type("AllLocationsMeasurement"));
      }
    }
    public Crosscut c1 = new TrapMethodCrossc1();
  }

  public static class TrapMethodAspect2 extends DefaultAspect {
    public static class TrapMethodCrossc2 extends MethodCut {

      public void METHOD_ARGS() {}
      protected PointCutter pointCutter() {
        PointCutter x = Executions.before().AND(Within.method("theMethodToCall"));
        return x.AND(Within.type("AllLocationsMeasurement"));
      }
      public void joinPointAction(ch.ethz.jvmai.MethodEntryJoinPoint x) {}
    }
    public Crosscut c2 = new TrapMethodCrossc2();
  }

  Aspect x1;
  Aspect x2;
  final boolean useProse;

  /**
   * Construct test with given name.
   * @param name test name
   */
  public AllLocationsMeasurement(String name) {
    super(name);

    String proseParam = System.getProperty("useprose");
    if(proseParam==null)
      useProse = isDebuggerEnabled();
    else
      useProse = proseParam.toUpperCase().equals("TRUE");

    if (useProse)
      RANGE = new int[]{1000000};
    else
      RANGE = new int[]{1000000};

  }

  /**
   * Set up fixture.
   */
  protected void setUp() {
    if (!useProse) return;

    x1 = new TrapMethodAspect1();
    x2 = new TrapMethodAspect2();
    try {
      ProseSystem.startup();
    }
    catch (Exception e) {
      Assert.fail("ProseSystem.startup() failed");
    }
  }

  protected void tearDown() {
    if (!useProse) return;

    try {
      ProseSystem.teardown();
    }
    catch (Exception e) {
      Assert.fail("ProseSystem.teardown() failed");
    }
  }

  public void testLocalCallsNormal() {
    if (useProse)
      ProseSystem.getAspectManager().insert(x1);

    startChronometer();
    for (int i=0; i < RUNS; i ++)
      this.theMethodToCall();
    stopChronometer();

    if (useProse)
      ProseSystem.getAspectManager().withdraw(x1);
  }

  public void testLocalCallsFast() {
    if (useProse)
      ProseSystem.getAspectManager().insert(x2);

    startChronometer();
    for (int i=0; i < RUNS; i++)
      this.theMethodToCall();
    stopChronometer();

    if (useProse)
      ProseSystem.getAspectManager().withdraw(x2);
  }

  /**
   * Test suite.
   * @return test instance
   */
  public static Test suite() {
    return new PerformanceTestSuite(AllLocationsMeasurement.class);
  }

}
TOP

Related Classes of measurements.suites.AllLocationsMeasurement$TrapMethodAspect2

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.