Package org.objectweb.speedo.stress

Source Code of org.objectweb.speedo.stress.StressHelper$PerformResult

/**
* Copyright (C) 2001-2004 France Telecom R&D
*
* This library 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 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
package org.objectweb.speedo.stress;

import org.objectweb.speedo.SpeedoTestHelper;
import org.objectweb.speedo.api.SpeedoProperties;
import org.objectweb.speedo.api.ExceptionHelper;
import org.objectweb.util.monolog.api.BasicLevel;
import org.objectweb.jorm.api.PMapper;
import org.objectweb.jorm.api.PMapCluster;
import org.objectweb.perseus.cache.api.CacheAttributeController;

import javax.jdo.PersistenceManager;
import javax.jdo.JDOException;
import java.util.Vector;
import java.util.Properties;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Set;

/**
*
* @author S.Chassande-Barrioz
*/
public abstract class StressHelper extends SpeedoTestHelper {

  public static Vector rollbackExceptions = new Vector();
  public static Vector errors = new Vector();
  public final static String STRESS_LOG_NAME = LOG_NAME + ".stress";

  protected String INTERACTIVE = getLoggerName() + ".interactive";
  protected String THREAD = getLoggerName() + ".thread";
  protected String TX = getLoggerName() + ".tx";
  //protected String CREATION = getLoggerName() + ".creation";
  protected String TIMEOUT = getLoggerName() + ".timeout";
  protected String NBPRINT = getLoggerName() + ".nbprint";
  protected boolean interactive; 
  protected boolean debug;
  protected boolean hasRan = false;
  protected static int nbPrint = 0;
  protected static CacheAttributeController cac = null;
  protected static int nbTest = 0;

  public StressHelper(String s) {
    super(s);   
    interactive = Boolean.getBoolean(INTERACTIVE);
    logger.log(BasicLevel.DEBUG, "interactive="+interactive);
    if (interactive) {     
      nbPrint = Integer.getInteger(NBPRINT, 0).intValue();
      logger.log(BasicLevel.DEBUG, "nbPrint="+nbPrint);
    }
  }

  /**
   * @return the class name of to initialize
   */
  protected abstract String[] getClassNamesToInit();

  protected String getLogPrefix() {
    return "";
  }

  protected void cleanup() {
    if (rollbackExceptions == null) {
      rollbackExceptions = new Vector();
    } else {
      rollbackExceptions.clear();
    }
    if (errors == null) {
      errors = new Vector();
    } else {
      errors.clear();
    }
  }

  protected void initDataStructure(boolean clean) throws Exception {
    String[] classNameToInit = getClassNamesToInit();
    PMapper mapper = getMapper(getPMF());
    PersistenceManager pm = getPMF().getPersistenceManager();
    for(int i=0; i<classNameToInit.length; i++) {
      pm.getObjectIdClass(Class.forName(classNameToInit[i]));
      if (clean) {
        PMapCluster pmc = mapper.getPMapCluster(classNameToInit[i]);
        assertNotNull("No PMapCluster for the class: " + classNameToInit[i], pmc);
        pmc.deleteData();
      }
    }
  }

  public void setUp() throws Exception {
    logger.log(BasicLevel.DEBUG, "setUp.");
    cleanup();
    initDataStructure(true);
    debug = logger.isLoggable(BasicLevel.DEBUG);
    logger.log(BasicLevel.DEBUG, "debug="+debug);
  }

  public void tearDown() {
    logger.log(BasicLevel.DEBUG, "tearDown.");
    if (hasRan) {
      if (cac == null) {
        synchronized(StressHelper.class) {
          try {
            cac = getCacheAttributeController(pmf);
          } catch (Exception e) {
            logger.log(BasicLevel.ERROR,
                    "Cache manager unreachable: " + pmf, e);
            fail(e.getMessage());
          }
        }
      }
      logger.log(BasicLevel.DEBUG, getLogPrefix() + "\tCache eviction... (size=" + cac.getCurrentSize() + ")");
      PersistenceManager pm = pmf.getPersistenceManager();
      pm.evictAll();
      pm.close();
      int cachesize = cac.getCurrentSize();
      if (cachesize > 0) {
        logger.log(BasicLevel.WARN, getLogPrefix()
                + "\tCache eviction finished, size=" + cachesize);
      }
    }
  }

  public Properties getPMFProperties() {
    Properties p = super.getPMFProperties();
    p.setProperty(SpeedoProperties.MAPPING_STRUCTURE,
            SpeedoProperties.MAPPING_STRUCTURE_DD);
    return p;
  }

  /**
   * Manages a set of tasks
   */
  public class TaskManager {

    /**
     * The tasks list
     */
    public Task[] tasks;

    /**
     * The timeout of tread waiting
     */
    public int timeout;

    /**
     * @param nbThread the number of task for each task
     * @param nbTx the number of transaction for each task
     * @param timeout the thread timeoout
     * @param ctx the context of the test
     */
    public TaskManager(int[] nbThread, int[] nbTx, int timeout, Object ctx) {
      tasks = new Task[nbThread.length];
      this.timeout = timeout;
      for(int i=0; i<nbThread.length; i++) {
        tasks[i] = newTask(i, nbTx[i], nbThread[i], this, ctx);
      }
    }
    /**
     * @param taskId the task identifier
     * @param nbTx the number of transaction to run
     * @param nbThread the number of thread executing transactions
     * @param taskManager
     * @param ctx the context of the test.
     * @return a new Task instance
     */
    public Task newTask(int taskId,
                        int nbTx,
                        int nbThread,
                        TaskManager taskManager,
                        Object ctx) {
      return new Task(taskId,  nbTx, nbThread, taskManager);
    }
  }


  /**
   * A task of a test. A task uses threads to execute a transaction, one or
   * several times. All thread are in concurrency to execute transactions.
   */
  public class Task {
    /**
     * Task identifier
     */
    public int taskId;

    /**
     * The threads executing transactions of the task
     */
    public Thread[] threads;

    /**
     * indicates for each tansaction if it must be execute or not (already
     * done or in progress)
     */
    public boolean[] txToExecute;

    /**
     * The execution time of transactions
     */
    public long[] txExecTime;

    public TaskManager taskManager;

    public Task(int taskId, int nbTx, int nbThread, TaskManager taskManager) {
      this.taskManager = taskManager;
      this.taskId = taskId;
      txToExecute = new boolean[nbTx];
      txExecTime = new long[nbTx];
      threads = new Thread[nbThread];
      Arrays.fill(txToExecute, true);
      Arrays.fill(txExecTime, (long) -1);
    }

    /**
     * Finds (calculate) the next transaction id to execute
     * @param threadId is the thread identifier requiring a transaction to
     * execute
     * @return an transaction identifier (index in the array 'txToExecute'
     * and 'txExecTime'.
     */
    public int getTxId(int threadId) {
      int txId = 0;
      if (txToExecute.length == 0) {
        return 0;
      }
      synchronized (txToExecute) {
        for (txId = 0; txId < txToExecute.length; txId++) {
          if (txToExecute[txId]) {
            txToExecute[txId] = false;
            return txId;
          }
        }
      }
      return -1;
    }
  }

  /**
   * Represents a thread running a task
   */
  public class ThreadId {
    public Task task;
    public int threadId;

    public ThreadId(Task task, int threadId) {
      this.task = task;
      this.threadId = threadId;
    }

    public String toString() {
      return "(task=" + task.taskId + ", thread=" + threadId + ")";
    }
  }

  /**
   * Creates a task manager with several  task
   */
  protected TaskManager newTaskManager(int nbTx, int nbThread, int timeout, Object ctx) {
    return newTaskManager(new int[]{nbTx}, new int[]{nbThread}, timeout, ctx);
  }

  /**
   * Creates a task manager with a single task
   */
  protected TaskManager newTaskManager(int nbTx[], int nbThread[], int timeout, Object ctx) {
    return new TaskManager(nbTx, nbThread, timeout, ctx);
  }


  protected void perform(final int nbThread,
                       final int nbTx,
                       final int threadTimeout,
                       final Object ctx) {
    perform(new int[]{nbThread}, new int[]{nbTx}, threadTimeout, ctx);
  }

  /**
   * Called before the test execution (like setup() method)
   * @param tm the task manager running the test
   * @param ctx the context of the test
   */
  protected void prepareTest(TaskManager tm, Object ctx) {
  }

  /**
   * Called before a task execution (like setup() method)
   * @param task which is going to be executed
   * @param ctx the context of the test
   */
  protected void prepareTask(Task task, Object ctx) {
  }

  protected void logStatistic(TaskManager tm, long exectime, Object ctx) {
    String prefix = getLogPrefix();
    int nbAllTx = 0;
    int nbCommittedTx = 0;
    double averageTxTime = 0;
    for(int taskId=0; taskId<tm.tasks.length; taskId++) {
      final Task task = tm.tasks[taskId];
      nbAllTx += task.txExecTime.length;
      for (int txId = 0; txId < task.txExecTime.length; txId++) {
        if (task.txExecTime[txId] != -1) {
          nbCommittedTx++;
          averageTxTime += task.txExecTime[txId];
        }
      }
    }
    averageTxTime /= nbAllTx;
    displayMemory();
    logger.log(BasicLevel.INFO, prefix + "\tTotal execution time= " + exectime
        + "ms, committedTx= " + nbCommittedTx +" ("
            + ((double) nbCommittedTx * 100) / nbAllTx + "%)");
    logger.log(BasicLevel.INFO, prefix + "\tAverage execution time per transaction: "
        + averageTxTime + " ms)");
    logger.log(BasicLevel.INFO, prefix + "\tTransaction throughput: "
        + ((double) nbCommittedTx / (double) exectime) * 1000 + " tx/sec");
    if (errors.size() > 0) {
      logger.log(BasicLevel.INFO, prefix + "\tThere are " + errors.size()
        + "/" + nbAllTx + " errors during the run");
    }
  }

  /**
   *
   * Launch the threads to execute the transactions
   *
   * @param nbThread Number of threads per task
   * @param nbTx Number of transactions per task
   * @param timeout Time to wait for a thread to die (in milliseconds)
   * @param ctx is a context helping the transaction execution
   */
  protected void perform(final int nbThread[],
                       final int nbTx[],
                       final int timeout,
                       final Object ctx) {
    final TaskManager tm = newTaskManager(nbThread, nbTx, timeout, ctx);
    final String prefix = getLogPrefix();
    prepareTest(tm, ctx);
    //------------ Create thread for each tasks ------------//
    for(int taskId=0; taskId<nbThread.length; taskId++) {
      final Task task = tm.tasks[taskId];
      logger.log(BasicLevel.INFO, prefix + "* TaskId=" + taskId
          + ", thread=" + nbThread[taskId]
          + ", tx=" + nbTx[taskId]
          + ", timeout=" + timeout + "ms"
          + ", context:" + ctx);
      prepareTask(task, ctx);
      for (int i = 0; i < nbThread[taskId]; i++) {
        final int threadId = i;
        task.threads[i] = new Thread(new Runnable() {
          public void run() {
            while (true) {
              int txId = task.getTxId(threadId);
              if (txId == -1) {
                // All the transactions have been executed
                break;
              } else if (txId == -2) {
                continue;
              }
              hasRan = true;
              PerformResult pr = new PerformResult();
              while (pr.again) {
                perform(task, threadId, txId, ctx, pr);
                if (pr.ok) {
                  if (task.txExecTime.length != 0) {
                    task.txExecTime[txId] = pr.execTime;
                  }
                }
              }
            }
          }
        });
      }
    }
    //-------------- Launch all threads ------------//
    long exectime = System.currentTimeMillis();
    int nbAllThread = 0;
    for(int taskId=0; taskId<nbThread.length; taskId++) {
      Task task = tm.tasks[taskId];
      nbAllThread += task.threads.length;
      for (int threadId = 0; threadId < nbThread[taskId]; threadId++) {
        logger.log(BasicLevel.DEBUG, prefix + "Start thread " + threadId);
        task.threads[threadId].start();
      }
    }
    try {
      //------------ wait threads ------------//
      ArrayList al = new ArrayList(nbAllThread);
      for(int taskId=0; taskId<nbThread.length; taskId++) {
        final Task task = tm.tasks[taskId];
        for (int threadId = 0; threadId < task.threads.length; threadId++) {
          task.threads[threadId].join(task.taskManager.timeout);
          if (task.threads[threadId].isAlive()) {
            ThreadId tid = new ThreadId(task, threadId);
            al.add(tid);
            logger.log(BasicLevel.DEBUG, prefix + "Thread " + tid
                    + " is not finished after the delay, it could be blocked");
          }
        }
      }
      if (al.size() > 0) {
        for (Iterator it = al.iterator(); it.hasNext();) {
          ThreadId tid = (ThreadId) it.next();
          if (!tid.task.threads[tid.threadId].isAlive()) {
            logger.log(BasicLevel.DEBUG, prefix + "Thread " + tid
                    + " is late but ok.");
            it.remove();
          }
        }
        if (al.size() > 0) {
          fail("Thread " + al + " is blocked!");
        }
      }
    } catch (InterruptedException e) {
      fail(e.getMessage());
    } finally {
      exectime = System.currentTimeMillis() - exectime;     
      logStatistic(tm, exectime, ctx);     
    }
  }

  /**
   * Allocate a PersistenceManager
   */
  protected PersistenceManager getPM(Task task, int threadId, int txId) {
    PersistenceManager pm = pmf.getPersistenceManager();
    if (debug) {
      logger.log(BasicLevel.DEBUG, getLogPrefix() + "(Thread " + threadId
              + ", tx " + txId + ", task " + task.taskId
              + ") got a PersistenceManager");
    }
    return pm;
  }

  /**
   *Starts a JDO transaction
   */
  protected void beginTx(PersistenceManager pm, Task task, int threadId, int txId) {
    pm.currentTransaction().begin();
    if (debug) {
      logger.log(BasicLevel.DEBUG, getLogPrefix() + "(Thread " + threadId
              + ", tx " + txId + ", task " + task.taskId
              + ") began a transaction.");
    }
  }

  /**
   * Commits a JDO transaction
   */
  protected void commitTx(PersistenceManager pm, Task task, int threadId, int txId) {
    pm.currentTransaction().commit();
    if (debug) {
      logger.log(BasicLevel.DEBUG, getLogPrefix() + "(Thread " + threadId
              + ", tx " + txId + ", task " + task.taskId
              + ") committed a transaction.");
    }
  }

  /**
   * Rollbacks a JDO transaction due to an exception
   */
  protected void rollbackOnException(PersistenceManager pm,
                                     Exception e,
                                     PerformResult res,
                                     Task task,
                                     int threadId,
                                     int txId) {
    Exception ie = ExceptionHelper.getNested(e);
    rollbackExceptions.add(ie);
    res.ok = false;
    pm.currentTransaction().rollback();
    logger.log(BasicLevel.INFO, getLogPrefix() + "(Thread " + threadId
              + ", tx " + txId + ", task " + task.taskId
              + " has been rolledback: try again", ie);
  }

  /**
   * Stop the transactions execution due to an error.
   */
  protected void stopOnError(PersistenceManager pm,
                                     Throwable t,
                                     PerformResult res,
                                     Task task,
                                     int threadId,
                                     int txId) {
    if (t instanceof Exception) {
      t = ExceptionHelper.getNested((Exception) t);
    }
    errors.add(t);
    res.ok = false;
    res.again = false; // do no try to re execute the transaction
    logger.log(BasicLevel.ERROR, getLogPrefix() + "(Thread " + threadId
              + ", tx " + txId + ", task " + task.taskId
              + " has a problem", t);
  }



  /**
   * Closes a persistence manager
   */
  protected void closePM(PersistenceManager pm,
                         int threadId,
                         int txId,
                         Task task,
                         PerformResult res) {
    try {
      if (pm != null && !pm.isClosed()) {
        try {
          if (pm.currentTransaction().isActive()) {
            pm.currentTransaction().rollback();
          }
        } finally {
          pm.close();
        }
      }
    } catch (JDOException e) {
      logger.log(BasicLevel.ERROR, getLogPrefix() + "(Thread " + threadId
              + ", tx " + txId
              + ", task " + task.taskId + ") has been "
              + (res.ok ? "committed" : "rolledback")
              + " and the close occurs an error", e);
      errors.add(e);
      throw e;
    }
  }

  /**
   * executes a transaction
   * @param task task asking the transaction execution
   * @param threadId thread identifier running the transaction
   * @param txId transaction identifier
   * @param ctx context of the test
   * @param res result of the transaction execution. This object must be
   * filled/modified by the method.
   */
  protected abstract void perform(Task task,
                                  int threadId,
                                  int txId,
                                  Object ctx,
                                  PerformResult res);

  private static synchronized void incNbTest() {   
    nbTest++;     
  }
 
  private static boolean printStatistic() {
    return ((nbPrint != 0) && (nbTest % nbPrint) == 0);
  }
  /**
   * It is used for transactions executions.
   */
  class PerformResult {
    /**
     * Indicates if the transaction must be played again
     */
    public boolean again;

    /**
     * Indicates if the out of the transaction is ok
     */
    public boolean ok;

    /**
     * is the execution time of the transaction
     */
    public long execTime;

    public PerformResult() {
      again = true;
    }

    /**
     * Demarcates the real begin the transaction
     */
    public void beginTest() {
      execTime = System.currentTimeMillis();     
      logger.log(BasicLevel.DEBUG, "beginTest nbTest=" + nbTest);
    }

    /**
     * Demarcates the real and right end of the transaction
     */
    public void endTest() {
      execTime = System.currentTimeMillis() - execTime;
      again = false;
      ok = true;
      StressHelper.incNbTest();
      logger.log(BasicLevel.DEBUG, "endTest nbTest=" + nbTest);
      if (StressHelper.printStatistic()) {     
        logger.log(BasicLevel.INFO, getLogPrefix() + "\tTest" +nbTest+ ": execution time=" + execTime + "ms");
        if (rollbackExceptions.size() > 0) {
          logger.log(BasicLevel.INFO, getLogPrefix() + "\tThere are " + rollbackExceptions.size() + " rollbacks during the run");
        }
        if (errors.size() > 0) {
          logger.log(BasicLevel.INFO, getLogPrefix() + "\tThere are " + errors.size() + " errors during the run");
        }
      }     
    }
  }

  /**
   * Logs the memory informations
   */
  protected void displayMemory() {
    Runtime r = Runtime.getRuntime();
    // free memory
    long free = r.freeMemory();
    // Allocated and no allocated memory
    long total = r.totalMemory();
    // inused memory
    long inuse = total - free;
    logger.log(BasicLevel.INFO, getLogPrefix() +
        "\tMemory Size: " + total + ", availlable memory:" + inuse);
  }


  protected final static int ID_Th1 = 0;
  protected final static int ID_Th1Tx10Cr1 = 1 + ID_Th1;
  protected final static int ID_Th1Tx100Cr1 = 2 + ID_Th1;
  protected final static int ID_Th1Tx1000Cr1 = 3 + ID_Th1;
  protected final static int ID_Th1Tx10000Cr1 = 4 + ID_Th1;
  protected final static int ID_Th1Tx100000Cr1 = 5 + ID_Th1;
  protected final static int ID_Th1Tx10Cr10 = 6 + ID_Th1;
  protected final static int ID_Th1Tx100Cr10 = 7 + ID_Th1;
  protected final static int ID_Th1Tx1000Cr10 = 8 + ID_Th1;
  protected final static int ID_Th1Tx10000Cr10 = 9 + ID_Th1;
  protected final static int ID_Th1Tx100000Cr10 = 10 + ID_Th1;
  protected final static int ID_Th1Tx10Cr100 = 11 + ID_Th1;
  protected final static int ID_Th1Tx100Cr100 = 12 + ID_Th1;
  protected final static int ID_Th1Tx1000Cr100 = 13 + ID_Th1;
  protected final static int ID_Th1Tx10000Cr100 = 14 + ID_Th1;
  protected final static int ID_Th1Tx10Cr500 = 15 + ID_Th1;
  protected final static int ID_Th1Tx100Cr500 = 16 + ID_Th1;
  protected final static int ID_Th1Tx1000Cr500 = 17 + ID_Th1;
  protected final static int ID_Th1Tx10Cr1000 = 18 + ID_Th1;
  protected final static int ID_Th1Tx100Cr1000 = 19 + ID_Th1;
  protected final static int ID_Th1Tx1000Cr1000 = 20 + ID_Th1;
  protected final static int ID_Th1Tx10Cr2000 = 21 + ID_Th1;
  protected final static int ID_Th1Tx100Cr2000 = 22 + ID_Th1;
  protected final static int ID_Th1Tx1000Cr2000 = 23 + ID_Th1;
  protected final static int ID_Th1Tx10Cr10000 = 24 + ID_Th1;
  protected final static int ID_Th1Tx100Cr10000 = 25 + ID_Th1;
  protected final static int ID_Th2 = 25;
  protected final static int ID_Th2Tx10Cr1 = 1 + ID_Th2;
  protected final static int ID_Th2Tx100Cr1 = 2 + ID_Th2;
  protected final static int ID_Th2Tx1000Cr1 = 3 + ID_Th2;
  protected final static int ID_Th2Tx10000Cr1 = 4 + ID_Th2;
  protected final static int ID_Th2Tx100000Cr1 = 5 + ID_Th2;
  protected final static int ID_Th2Tx10Cr10 = 6 + ID_Th2;
  protected final static int ID_Th2Tx100Cr10 = 7 + ID_Th2;
  protected final static int ID_Th2Tx1000Cr10 = 8 + ID_Th2;
  protected final static int ID_Th2Tx10000Cr10 = 9 + ID_Th2;
  protected final static int ID_Th2Tx100000Cr10 = 10 + ID_Th2;
  protected final static int ID_Th2Tx10Cr100 = 11 + ID_Th2;
  protected final static int ID_Th2Tx100Cr100 = 12 + ID_Th2;
  protected final static int ID_Th2Tx1000Cr100 = 13 + ID_Th2;
  protected final static int ID_Th2Tx10000Cr100 = 14 + ID_Th2;
  protected final static int ID_Th2Tx10Cr500 = 15 + ID_Th2;
  protected final static int ID_Th2Tx100Cr500 = 16 + ID_Th2;
  protected final static int ID_Th2Tx1000Cr500 = 17 + ID_Th2;
  protected final static int ID_Th2Tx10Cr1000 = 18 + ID_Th2;
  protected final static int ID_Th2Tx100Cr1000 = 19 + ID_Th2;
  protected final static int ID_Th2Tx1000Cr1000 = 20 + ID_Th2;
  protected final static int ID_Th2Tx10Cr2000 = 21 + ID_Th2;
  protected final static int ID_Th2Tx100Cr2000 = 22 + ID_Th2;
  protected final static int ID_Th2Tx1000Cr2000 = 23 + ID_Th2;
  protected final static int ID_Th2Tx10Cr10000 = 24 + ID_Th2;
  protected final static int ID_Th2Tx100Cr10000 = 25 + ID_Th2;
  protected final static int ID_Th3 = 50;
  protected final static int ID_Th3Tx10Cr1 = 1 + ID_Th3;
  protected final static int ID_Th3Tx100Cr1 = 2 + ID_Th3;
  protected final static int ID_Th3Tx1000Cr1 = 3 + ID_Th3;
  protected final static int ID_Th3Tx10000Cr1 = 4 + ID_Th3;
  protected final static int ID_Th3Tx100000Cr1 = 5 + ID_Th3;
  protected final static int ID_Th3Tx10Cr10 = 6 + ID_Th3;
  protected final static int ID_Th3Tx100Cr10 = 7 + ID_Th3;
  protected final static int ID_Th3Tx1000Cr10 = 8 + ID_Th3;
  protected final static int ID_Th3Tx10000Cr10 = 9 + ID_Th3;
  protected final static int ID_Th3Tx100000Cr10 = 10 + ID_Th3;
  protected final static int ID_Th3Tx10Cr100 = 11 + ID_Th3;
  protected final static int ID_Th3Tx100Cr100 = 12 + ID_Th3;
  protected final static int ID_Th3Tx1000Cr100 = 13 + ID_Th3;
  protected final static int ID_Th3Tx10000Cr100 = 14 + ID_Th3;
  protected final static int ID_Th3Tx10Cr500 = 15 + ID_Th3;
  protected final static int ID_Th3Tx100Cr500 = 16 + ID_Th3;
  protected final static int ID_Th3Tx1000Cr500 = 17 + ID_Th3;
  protected final static int ID_Th3Tx10Cr1000 = 18 + ID_Th3;
  protected final static int ID_Th3Tx100Cr1000 = 19 + ID_Th3;
  protected final static int ID_Th3Tx1000Cr1000 = 20 + ID_Th3;
  protected final static int ID_Th3Tx10Cr2000 = 21 + ID_Th3;
  protected final static int ID_Th3Tx100Cr2000 = 22 + ID_Th3;
  protected final static int ID_Th3Tx1000Cr2000 = 23 + ID_Th3;
  protected final static int ID_Th3Tx10Cr10000 = 24 + ID_Th3;
  protected final static int ID_Th3Tx100Cr10000 = 25 + ID_Th3;
  protected final static int ID_Th4 = 75;
  protected final static int ID_Th4Tx10Cr1 = 1 + ID_Th4;
  protected final static int ID_Th4Tx100Cr1 = 2 + ID_Th4;
  protected final static int ID_Th4Tx1000Cr1 = 3 + ID_Th4;
  protected final static int ID_Th4Tx10000Cr1 = 4 + ID_Th4;
  protected final static int ID_Th4Tx100000Cr1 = 5 + ID_Th4;
  protected final static int ID_Th4Tx10Cr10 = 6 + ID_Th4;
  protected final static int ID_Th4Tx100Cr10 = 7 + ID_Th4;
  protected final static int ID_Th4Tx1000Cr10 = 8 + ID_Th4;
  protected final static int ID_Th4Tx10000Cr10 = 9 + ID_Th4;
  protected final static int ID_Th4Tx100000Cr10 = 10 + ID_Th4;
  protected final static int ID_Th4Tx10Cr100 = 11 + ID_Th4;
  protected final static int ID_Th4Tx100Cr100 = 12 + ID_Th4;
  protected final static int ID_Th4Tx1000Cr100 = 13 + ID_Th4;
  protected final static int ID_Th4Tx10000Cr100 = 14 + ID_Th4;
  protected final static int ID_Th4Tx10Cr500 = 15 + ID_Th4;
  protected final static int ID_Th4Tx100Cr500 = 16 + ID_Th4;
  protected final static int ID_Th4Tx1000Cr500 = 17 + ID_Th4;
  protected final static int ID_Th4Tx10Cr1000 = 18 + ID_Th4;
  protected final static int ID_Th4Tx100Cr1000 = 19 + ID_Th4;
  protected final static int ID_Th4Tx1000Cr1000 = 20 + ID_Th4;
  protected final static int ID_Th4Tx10Cr2000 = 21 + ID_Th4;
  protected final static int ID_Th4Tx100Cr2000 = 22 + ID_Th4;
  protected final static int ID_Th4Tx1000Cr2000 = 23 + ID_Th4;
  protected final static int ID_Th4Tx10Cr10000 = 24 + ID_Th4;
  protected final static int ID_Th4Tx100Cr10000 = 25 + ID_Th4;
  protected final static int ID_Th10 = 100;
  protected final static int ID_Th10Tx10Cr1 = 1 + ID_Th10;
  protected final static int ID_Th10Tx100Cr1 = 2 + ID_Th10;
  protected final static int ID_Th10Tx1000Cr1 = 3 + ID_Th10;
  protected final static int ID_Th10Tx10000Cr1 = 4 + ID_Th10;
  protected final static int ID_Th10Tx100000Cr1 = 5 + ID_Th10;
  protected final static int ID_Th10Tx10Cr10 = 6 + ID_Th10;
  protected final static int ID_Th10Tx100Cr10 = 7 + ID_Th10;
  protected final static int ID_Th10Tx1000Cr10 = 8 + ID_Th10;
  protected final static int ID_Th10Tx10000Cr10 = 9 + ID_Th10;
  protected final static int ID_Th10Tx100000Cr10 = 10 + ID_Th10;
  protected final static int ID_Th10Tx10Cr100 = 11 + ID_Th10;
  protected final static int ID_Th10Tx100Cr100 = 12 + ID_Th10;
  protected final static int ID_Th10Tx1000Cr100 = 13 + ID_Th10;
  protected final static int ID_Th10Tx10000Cr100 = 14 + ID_Th10;
  protected final static int ID_Th10Tx10Cr500 = 15 + ID_Th10;
  protected final static int ID_Th10Tx100Cr500 = 16 + ID_Th10;
  protected final static int ID_Th10Tx1000Cr500 = 17 + ID_Th10;
  protected final static int ID_Th10Tx10Cr1000 = 18 + ID_Th10;
  protected final static int ID_Th10Tx100Cr1000 = 19 + ID_Th10;
  protected final static int ID_Th10Tx1000Cr1000 = 20 + ID_Th10;
  protected final static int ID_Th10Tx10Cr2000 = 21 + ID_Th10;
  protected final static int ID_Th10Tx100Cr2000 = 22 + ID_Th10;
  protected final static int ID_Th10Tx1000Cr2000 = 23 + ID_Th10;
  protected final static int ID_Th10Tx10Cr10000 = 24 + ID_Th10;
  protected final static int ID_Th10Tx100Cr10000 = 25 + ID_Th10;
  protected final static int[] TESTNBC = { 0,
      // ID_Th1
      10, 100, 1000, 10000, 100000, // CR 1
      100, 1000, 10000, 100000, 1000000, // CR 10
      1000, 10000, 100000, 1000000, // CR 100
      5000, 50000, 500000, // CR 500
      10000, 100000, 1000000, // CR 1.000
      20000, 200000, 2000000, // CR 2.000
      100000, 1000000, // CR 10.000
      // ID_Th2
      10, 100, 1000, 10000, 100000, // CR 1
      100, 1000, 10000, 100000, 1000000, // CR 10
      1000, 10000, 100000, 1000000, // CR 100
      5000, 50000, 500000, // CR 500
      10000, 100000, 1000000, // CR 1.000
      20000, 200000, 2000000, // CR 2.000
      100000, 1000000, // CR 10.000
      // ID_Th3
      10, 100, 1000, 10000, 100000, // CR 1
      100, 1000, 10000, 100000, 1000000, // CR 10
      1000, 10000, 100000, 1000000, // CR 100
      5000, 50000, 500000, // CR 500
      10000, 100000, 1000000, // CR 1.000
      20000, 200000, 2000000, // CR 2.000
      100000, 1000000, // CR 10.000
      // ID_Th4
      10, 100, 1000, 10000, 100000, // CR 1
      100, 1000, 10000, 100000, 1000000, // CR 10
      1000, 10000, 100000, 1000000, // CR 100
      5000, 50000, 500000, // CR 500
      10000, 100000, 1000000, // CR 1.000
      20000, 200000, 2000000, // CR 2.000
      100000, 1000000, // CR 10.000
      // ID_Th10
      10, 100, 1000, 10000, 100000, // CR 1
      100, 1000, 10000, 100000, 1000000, // CR 10
      1000, 10000, 100000, 1000000, // CR 100
      5000, 50000, 500000, // CR 500
      10000, 100000, 1000000, // CR 1.000
      20000, 200000, 2000000, // CR 2.000
      100000, 1000000, // CR 10.000
      -1 };

  protected int getStartId(int testid) {
    int res = 0;
    while (testid > 0) {
      testid--;
      res += TESTNBC[testid];
    }
    return res;
  }

  public class ObjectStatistic {

    HashMap oid2Touch = new HashMap();
    long nbTouch = 0;

    public synchronized void touch(Object oid) {
      Integer i = (Integer) oid2Touch.get(oid);
      if (i == null) {
        i = new Integer(1);
      } else {
        i = new Integer(i.intValue() + 1);
      }
      nbTouch++;
      oid2Touch.put(oid, i);
    }

    public Set getAccessedOid() {
      return oid2Touch.keySet();
    }

    public long getNbAccess() {
      return nbTouch;
    }
  }
}
TOP

Related Classes of org.objectweb.speedo.stress.StressHelper$PerformResult

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.