1 18 package org.objectweb.speedo.stress; 19 20 import org.objectweb.speedo.SpeedoTestHelper; 21 import org.objectweb.speedo.api.SpeedoProperties; 22 import org.objectweb.speedo.api.ExceptionHelper; 23 import org.objectweb.util.monolog.api.BasicLevel; 24 import org.objectweb.jorm.api.PMapper; 25 import org.objectweb.jorm.api.PMapCluster; 26 import org.objectweb.perseus.cache.api.CacheAttributeController; 27 28 import javax.jdo.PersistenceManager; 29 import javax.jdo.JDOException; 30 import java.util.Vector ; 31 import java.util.Properties ; 32 import java.util.ArrayList ; 33 import java.util.Iterator ; 34 import java.util.Arrays ; 35 import java.util.HashMap ; 36 import java.util.Set ; 37 38 42 public abstract class StressHelper extends SpeedoTestHelper { 43 44 public static Vector rollbackExceptions = new Vector (); 45 public static Vector errors = new Vector (); 46 public final static String STRESS_LOG_NAME = LOG_NAME + ".stress"; 47 48 protected String INTERACTIVE = getLoggerName() + ".interactive"; 49 protected String THREAD = getLoggerName() + ".thread"; 50 protected String TX = getLoggerName() + ".tx"; 51 protected String TIMEOUT = getLoggerName() + ".timeout"; 53 protected String NBPRINT = getLoggerName() + ".nbprint"; 54 protected boolean interactive; 55 protected boolean debug; 56 protected boolean hasRan = false; 57 protected static int nbPrint = 0; 58 protected static CacheAttributeController cac = null; 59 protected static int nbTest = 0; 60 61 public StressHelper(String s) { 62 super(s); 63 interactive = Boolean.getBoolean(INTERACTIVE); 64 logger.log(BasicLevel.DEBUG, "interactive="+interactive); 65 if (interactive) { 66 nbPrint = Integer.getInteger(NBPRINT, 0).intValue(); 67 logger.log(BasicLevel.DEBUG, "nbPrint="+nbPrint); 68 } 69 } 70 71 74 protected abstract String [] getClassNamesToInit(); 75 76 protected String getLogPrefix() { 77 return ""; 78 } 79 80 protected void cleanup() { 81 if (rollbackExceptions == null) { 82 rollbackExceptions = new Vector (); 83 } else { 84 rollbackExceptions.clear(); 85 } 86 if (errors == null) { 87 errors = new Vector (); 88 } else { 89 errors.clear(); 90 } 91 } 92 93 protected void initDataStructure(boolean clean) throws Exception { 94 String [] classNameToInit = getClassNamesToInit(); 95 PMapper mapper = getMapper(getPMF()); 96 PersistenceManager pm = getPMF().getPersistenceManager(); 97 for(int i=0; i<classNameToInit.length; i++) { 98 pm.getObjectIdClass(Class.forName(classNameToInit[i])); 99 if (clean) { 100 PMapCluster pmc = mapper.getPMapCluster(classNameToInit[i]); 101 assertNotNull("No PMapCluster for the class: " + classNameToInit[i], pmc); 102 pmc.deleteData(); 103 } 104 } 105 } 106 107 public void setUp() throws Exception { 108 logger.log(BasicLevel.DEBUG, "setUp."); 109 cleanup(); 110 initDataStructure(true); 111 debug = logger.isLoggable(BasicLevel.DEBUG); 112 logger.log(BasicLevel.DEBUG, "debug="+debug); 113 } 114 115 public void tearDown() { 116 logger.log(BasicLevel.DEBUG, "tearDown."); 117 if (hasRan) { 118 if (cac == null) { 119 synchronized(StressHelper.class) { 120 try { 121 cac = getCacheAttributeController(pmf); 122 } catch (Exception e) { 123 logger.log(BasicLevel.ERROR, 124 "Cache manager unreachable: " + pmf, e); 125 fail(e.getMessage()); 126 } 127 } 128 } 129 logger.log(BasicLevel.DEBUG, getLogPrefix() + "\tCache eviction... (size=" + cac.getCurrentSize() + ")"); 130 PersistenceManager pm = pmf.getPersistenceManager(); 131 pm.evictAll(); 132 pm.close(); 133 int cachesize = cac.getCurrentSize(); 134 if (cachesize > 0) { 135 logger.log(BasicLevel.WARN, getLogPrefix() 136 + "\tCache eviction finished, size=" + cachesize); 137 } 138 } 139 } 140 141 public Properties getPMFProperties() { 142 Properties p = super.getPMFProperties(); 143 p.setProperty(SpeedoProperties.MAPPING_STRUCTURE, 144 SpeedoProperties.MAPPING_STRUCTURE_DD); 145 return p; 146 } 147 148 151 public class TaskManager { 152 153 156 public Task[] tasks; 157 158 161 public int timeout; 162 163 169 public TaskManager(int[] nbThread, int[] nbTx, int timeout, Object ctx) { 170 tasks = new Task[nbThread.length]; 171 this.timeout = timeout; 172 for(int i=0; i<nbThread.length; i++) { 173 tasks[i] = newTask(i, nbTx[i], nbThread[i], this, ctx); 174 } 175 } 176 184 public Task newTask(int taskId, 185 int nbTx, 186 int nbThread, 187 TaskManager taskManager, 188 Object ctx) { 189 return new Task(taskId, nbTx, nbThread, taskManager); 190 } 191 } 192 193 194 198 public class Task { 199 202 public int taskId; 203 204 207 public Thread [] threads; 208 209 213 public boolean[] txToExecute; 214 215 218 public long[] txExecTime; 219 220 public TaskManager taskManager; 221 222 public Task(int taskId, int nbTx, int nbThread, TaskManager taskManager) { 223 this.taskManager = taskManager; 224 this.taskId = taskId; 225 txToExecute = new boolean[nbTx]; 226 txExecTime = new long[nbTx]; 227 threads = new Thread [nbThread]; 228 Arrays.fill(txToExecute, true); 229 Arrays.fill(txExecTime, (long) -1); 230 } 231 232 239 public int getTxId(int threadId) { 240 int txId = 0; 241 if (txToExecute.length == 0) { 242 return 0; 243 } 244 synchronized (txToExecute) { 245 for (txId = 0; txId < txToExecute.length; txId++) { 246 if (txToExecute[txId]) { 247 txToExecute[txId] = false; 248 return txId; 249 } 250 } 251 } 252 return -1; 253 } 254 } 255 256 259 public class ThreadId { 260 public Task task; 261 public int threadId; 262 263 public ThreadId(Task task, int threadId) { 264 this.task = task; 265 this.threadId = threadId; 266 } 267 268 public String toString() { 269 return "(task=" + task.taskId + ", thread=" + threadId + ")"; 270 } 271 } 272 273 276 protected TaskManager newTaskManager(int nbTx, int nbThread, int timeout, Object ctx) { 277 return newTaskManager(new int[]{nbTx}, new int[]{nbThread}, timeout, ctx); 278 } 279 280 283 protected TaskManager newTaskManager(int nbTx[], int nbThread[], int timeout, Object ctx) { 284 return new TaskManager(nbTx, nbThread, timeout, ctx); 285 } 286 287 288 protected void perform(final int nbThread, 289 final int nbTx, 290 final int threadTimeout, 291 final Object ctx) { 292 perform(new int[]{nbThread}, new int[]{nbTx}, threadTimeout, ctx); 293 } 294 295 300 protected void prepareTest(TaskManager tm, Object ctx) { 301 } 302 303 308 protected void prepareTask(Task task, Object ctx) { 309 } 310 311 protected void logStatistic(TaskManager tm, long exectime, Object ctx) { 312 String prefix = getLogPrefix(); 313 int nbAllTx = 0; 314 int nbCommittedTx = 0; 315 double averageTxTime = 0; 316 for(int taskId=0; taskId<tm.tasks.length; taskId++) { 317 final Task task = tm.tasks[taskId]; 318 nbAllTx += task.txExecTime.length; 319 for (int txId = 0; txId < task.txExecTime.length; txId++) { 320 if (task.txExecTime[txId] != -1) { 321 nbCommittedTx++; 322 averageTxTime += task.txExecTime[txId]; 323 } 324 } 325 } 326 averageTxTime /= nbAllTx; 327 displayMemory(); 328 logger.log(BasicLevel.INFO, prefix + "\tTotal execution time= " + exectime 329 + "ms, committedTx= " + nbCommittedTx +" (" 330 + ((double) nbCommittedTx * 100) / nbAllTx + "%)"); 331 logger.log(BasicLevel.INFO, prefix + "\tAverage execution time per transaction: " 332 + averageTxTime + " ms)"); 333 logger.log(BasicLevel.INFO, prefix + "\tTransaction throughput: " 334 + ((double) nbCommittedTx / (double) exectime) * 1000 + " tx/sec"); 335 if (errors.size() > 0) { 336 logger.log(BasicLevel.INFO, prefix + "\tThere are " + errors.size() 337 + "/" + nbAllTx + " errors during the run"); 338 } 339 } 340 341 350 protected void perform(final int nbThread[], 351 final int nbTx[], 352 final int timeout, 353 final Object ctx) { 354 final TaskManager tm = newTaskManager(nbThread, nbTx, timeout, ctx); 355 final String prefix = getLogPrefix(); 356 prepareTest(tm, ctx); 357 for(int taskId=0; taskId<nbThread.length; taskId++) { 359 final Task task = tm.tasks[taskId]; 360 logger.log(BasicLevel.INFO, prefix + "* TaskId=" + taskId 361 + ", thread=" + nbThread[taskId] 362 + ", tx=" + nbTx[taskId] 363 + ", timeout=" + timeout + "ms" 364 + ", context:" + ctx); 365 prepareTask(task, ctx); 366 for (int i = 0; i < nbThread[taskId]; i++) { 367 final int threadId = i; 368 task.threads[i] = new Thread (new Runnable () { 369 public void run() { 370 while (true) { 371 int txId = task.getTxId(threadId); 372 if (txId == -1) { 373 break; 375 } else if (txId == -2) { 376 continue; 377 } 378 hasRan = true; 379 PerformResult pr = new PerformResult(); 380 while (pr.again) { 381 perform(task, threadId, txId, ctx, pr); 382 if (pr.ok) { 383 if (task.txExecTime.length != 0) { 384 task.txExecTime[txId] = pr.execTime; 385 } 386 } 387 } 388 } 389 } 390 }); 391 } 392 } 393 long exectime = System.currentTimeMillis(); 395 int nbAllThread = 0; 396 for(int taskId=0; taskId<nbThread.length; taskId++) { 397 Task task = tm.tasks[taskId]; 398 nbAllThread += task.threads.length; 399 for (int threadId = 0; threadId < nbThread[taskId]; threadId++) { 400 logger.log(BasicLevel.DEBUG, prefix + "Start thread " + threadId); 401 task.threads[threadId].start(); 402 } 403 } 404 try { 405 ArrayList al = new ArrayList (nbAllThread); 407 for(int taskId=0; taskId<nbThread.length; taskId++) { 408 final Task task = tm.tasks[taskId]; 409 for (int threadId = 0; threadId < task.threads.length; threadId++) { 410 task.threads[threadId].join(task.taskManager.timeout); 411 if (task.threads[threadId].isAlive()) { 412 ThreadId tid = new ThreadId(task, threadId); 413 al.add(tid); 414 logger.log(BasicLevel.DEBUG, prefix + "Thread " + tid 415 + " is not finished after the delay, it could be blocked"); 416 } 417 } 418 } 419 if (al.size() > 0) { 420 for (Iterator it = al.iterator(); it.hasNext();) { 421 ThreadId tid = (ThreadId) it.next(); 422 if (!tid.task.threads[tid.threadId].isAlive()) { 423 logger.log(BasicLevel.DEBUG, prefix + "Thread " + tid 424 + " is late but ok."); 425 it.remove(); 426 } 427 } 428 if (al.size() > 0) { 429 fail("Thread " + al + " is blocked!"); 430 } 431 } 432 } catch (InterruptedException e) { 433 fail(e.getMessage()); 434 } finally { 435 exectime = System.currentTimeMillis() - exectime; 436 logStatistic(tm, exectime, ctx); 437 } 438 } 439 440 443 protected PersistenceManager getPM(Task task, int threadId, int txId) { 444 PersistenceManager pm = pmf.getPersistenceManager(); 445 if (debug) { 446 logger.log(BasicLevel.DEBUG, getLogPrefix() + "(Thread " + threadId 447 + ", tx " + txId + ", task " + task.taskId 448 + ") got a PersistenceManager"); 449 } 450 return pm; 451 } 452 453 456 protected void beginTx(PersistenceManager pm, Task task, int threadId, int txId) { 457 pm.currentTransaction().begin(); 458 if (debug) { 459 logger.log(BasicLevel.DEBUG, getLogPrefix() + "(Thread " + threadId 460 + ", tx " + txId + ", task " + task.taskId 461 + ") began a transaction."); 462 } 463 } 464 465 468 protected void commitTx(PersistenceManager pm, Task task, int threadId, int txId) { 469 pm.currentTransaction().commit(); 470 if (debug) { 471 logger.log(BasicLevel.DEBUG, getLogPrefix() + "(Thread " + threadId 472 + ", tx " + txId + ", task " + task.taskId 473 + ") committed a transaction."); 474 } 475 } 476 477 480 protected void rollbackOnException(PersistenceManager pm, 481 Exception e, 482 PerformResult res, 483 Task task, 484 int threadId, 485 int txId) { 486 Exception ie = ExceptionHelper.getNested(e); 487 rollbackExceptions.add(ie); 488 res.ok = false; 489 pm.currentTransaction().rollback(); 490 logger.log(BasicLevel.INFO, getLogPrefix() + "(Thread " + threadId 491 + ", tx " + txId + ", task " + task.taskId 492 + " has been rolledback: try again", ie); 493 } 494 495 498 protected void stopOnError(PersistenceManager pm, 499 Throwable t, 500 PerformResult res, 501 Task task, 502 int threadId, 503 int txId) { 504 if (t instanceof Exception ) { 505 t = ExceptionHelper.getNested((Exception ) t); 506 } 507 errors.add(t); 508 res.ok = false; 509 res.again = false; logger.log(BasicLevel.ERROR, getLogPrefix() + "(Thread " + threadId 511 + ", tx " + txId + ", task " + task.taskId 512 + " has a problem", t); 513 } 514 515 516 517 520 protected void closePM(PersistenceManager pm, 521 int threadId, 522 int txId, 523 Task task, 524 PerformResult res) { 525 try { 526 if (pm != null && !pm.isClosed()) { 527 try { 528 if (pm.currentTransaction().isActive()) { 529 pm.currentTransaction().rollback(); 530 } 531 } finally { 532 pm.close(); 533 } 534 } 535 } catch (JDOException e) { 536 logger.log(BasicLevel.ERROR, getLogPrefix() + "(Thread " + threadId 537 + ", tx " + txId 538 + ", task " + task.taskId + ") has been " 539 + (res.ok ? "committed" : "rolledback") 540 + " and the close occurs an error", e); 541 errors.add(e); 542 throw e; 543 } 544 } 545 546 555 protected abstract void perform(Task task, 556 int threadId, 557 int txId, 558 Object ctx, 559 PerformResult res); 560 561 private static synchronized void incNbTest() { 562 nbTest++; 563 } 564 565 private static boolean printStatistic() { 566 return ((nbPrint != 0) && (nbTest % nbPrint) == 0); 567 } 568 571 class PerformResult { 572 575 public boolean again; 576 577 580 public boolean ok; 581 582 585 public long execTime; 586 587 public PerformResult() { 588 again = true; 589 } 590 591 594 public void beginTest() { 595 execTime = System.currentTimeMillis(); 596 logger.log(BasicLevel.DEBUG, "beginTest nbTest=" + nbTest); 597 } 598 599 602 public void endTest() { 603 execTime = System.currentTimeMillis() - execTime; 604 again = false; 605 ok = true; 606 StressHelper.incNbTest(); 607 logger.log(BasicLevel.DEBUG, "endTest nbTest=" + nbTest); 608 if (StressHelper.printStatistic()) { 609 logger.log(BasicLevel.INFO, getLogPrefix() + "\tTest" +nbTest+ ": execution time=" + execTime + "ms"); 610 if (rollbackExceptions.size() > 0) { 611 logger.log(BasicLevel.INFO, getLogPrefix() + "\tThere are " + rollbackExceptions.size() + " rollbacks during the run"); 612 } 613 if (errors.size() > 0) { 614 logger.log(BasicLevel.INFO, getLogPrefix() + "\tThere are " + errors.size() + " errors during the run"); 615 } 616 } 617 } 618 } 619 620 623 protected void displayMemory() { 624 Runtime r = Runtime.getRuntime(); 625 long free = r.freeMemory(); 627 long total = r.totalMemory(); 629 long inuse = total - free; 631 logger.log(BasicLevel.INFO, getLogPrefix() + 632 "\tMemory Size: " + total + ", availlable memory:" + inuse); 633 } 634 635 636 protected final static int ID_Th1 = 0; 637 protected final static int ID_Th1Tx10Cr1 = 1 + ID_Th1; 638 protected final static int ID_Th1Tx100Cr1 = 2 + ID_Th1; 639 protected final static int ID_Th1Tx1000Cr1 = 3 + ID_Th1; 640 protected final static int ID_Th1Tx10000Cr1 = 4 + ID_Th1; 641 protected final static int ID_Th1Tx100000Cr1 = 5 + ID_Th1; 642 protected final static int ID_Th1Tx10Cr10 = 6 + ID_Th1; 643 protected final static int ID_Th1Tx100Cr10 = 7 + ID_Th1; 644 protected final static int ID_Th1Tx1000Cr10 = 8 + ID_Th1; 645 protected final static int ID_Th1Tx10000Cr10 = 9 + ID_Th1; 646 protected final static int ID_Th1Tx100000Cr10 = 10 + ID_Th1; 647 protected final static int ID_Th1Tx10Cr100 = 11 + ID_Th1; 648 protected final static int ID_Th1Tx100Cr100 = 12 + ID_Th1; 649 protected final static int ID_Th1Tx1000Cr100 = 13 + ID_Th1; 650 protected final static int ID_Th1Tx10000Cr100 = 14 + ID_Th1; 651 protected final static int ID_Th1Tx10Cr500 = 15 + ID_Th1; 652 protected final static int ID_Th1Tx100Cr500 = 16 + ID_Th1; 653 protected final static int ID_Th1Tx1000Cr500 = 17 + ID_Th1; 654 protected final static int ID_Th1Tx10Cr1000 = 18 + ID_Th1; 655 protected final static int ID_Th1Tx100Cr1000 = 19 + ID_Th1; 656 protected final static int ID_Th1Tx1000Cr1000 = 20 + ID_Th1; 657 protected final static int ID_Th1Tx10Cr2000 = 21 + ID_Th1; 658 protected final static int ID_Th1Tx100Cr2000 = 22 + ID_Th1; 659 protected final static int ID_Th1Tx1000Cr2000 = 23 + ID_Th1; 660 protected final static int ID_Th1Tx10Cr10000 = 24 + ID_Th1; 661 protected final static int ID_Th1Tx100Cr10000 = 25 + ID_Th1; 662 protected final static int ID_Th2 = 25; 663 protected final static int ID_Th2Tx10Cr1 = 1 + ID_Th2; 664 protected final static int ID_Th2Tx100Cr1 = 2 + ID_Th2; 665 protected final static int ID_Th2Tx1000Cr1 = 3 + ID_Th2; 666 protected final static int ID_Th2Tx10000Cr1 = 4 + ID_Th2; 667 protected final static int ID_Th2Tx100000Cr1 = 5 + ID_Th2; 668 protected final static int ID_Th2Tx10Cr10 = 6 + ID_Th2; 669 protected final static int ID_Th2Tx100Cr10 = 7 + ID_Th2; 670 protected final static int ID_Th2Tx1000Cr10 = 8 + ID_Th2; 671 protected final static int ID_Th2Tx10000Cr10 = 9 + ID_Th2; 672 protected final static int ID_Th2Tx100000Cr10 = 10 + ID_Th2; 673 protected final static int ID_Th2Tx10Cr100 = 11 + ID_Th2; 674 protected final static int ID_Th2Tx100Cr100 = 12 + ID_Th2; 675 protected final static int ID_Th2Tx1000Cr100 = 13 + ID_Th2; 676 protected final static int ID_Th2Tx10000Cr100 = 14 + ID_Th2; 677 protected final static int ID_Th2Tx10Cr500 = 15 + ID_Th2; 678 protected final static int ID_Th2Tx100Cr500 = 16 + ID_Th2; 679 protected final static int ID_Th2Tx1000Cr500 = 17 + ID_Th2; 680 protected final static int ID_Th2Tx10Cr1000 = 18 + ID_Th2; 681 protected final static int ID_Th2Tx100Cr1000 = 19 + ID_Th2; 682 protected final static int ID_Th2Tx1000Cr1000 = 20 + ID_Th2; 683 protected final static int ID_Th2Tx10Cr2000 = 21 + ID_Th2; 684 protected final static int ID_Th2Tx100Cr2000 = 22 + ID_Th2; 685 protected final static int ID_Th2Tx1000Cr2000 = 23 + ID_Th2; 686 protected final static int ID_Th2Tx10Cr10000 = 24 + ID_Th2; 687 protected final static int ID_Th2Tx100Cr10000 = 25 + ID_Th2; 688 protected final static int ID_Th3 = 50; 689 protected final static int ID_Th3Tx10Cr1 = 1 + ID_Th3; 690 protected final static int ID_Th3Tx100Cr1 = 2 + ID_Th3; 691 protected final static int ID_Th3Tx1000Cr1 = 3 + ID_Th3; 692 protected final static int ID_Th3Tx10000Cr1 = 4 + ID_Th3; 693 protected final static int ID_Th3Tx100000Cr1 = 5 + ID_Th3; 694 protected final static int ID_Th3Tx10Cr10 = 6 + ID_Th3; 695 protected final static int ID_Th3Tx100Cr10 = 7 + ID_Th3; 696 protected final static int ID_Th3Tx1000Cr10 = 8 + ID_Th3; 697 protected final static int ID_Th3Tx10000Cr10 = 9 + ID_Th3; 698 protected final static int ID_Th3Tx100000Cr10 = 10 + ID_Th3; 699 protected final static int ID_Th3Tx10Cr100 = 11 + ID_Th3; 700 protected final static int ID_Th3Tx100Cr100 = 12 + ID_Th3; 701 protected final static int ID_Th3Tx1000Cr100 = 13 + ID_Th3; 702 protected final static int ID_Th3Tx10000Cr100 = 14 + ID_Th3; 703 protected final static int ID_Th3Tx10Cr500 = 15 + ID_Th3; 704 protected final static int ID_Th3Tx100Cr500 = 16 + ID_Th3; 705 protected final static int ID_Th3Tx1000Cr500 = 17 + ID_Th3; 706 protected final static int ID_Th3Tx10Cr1000 = 18 + ID_Th3; 707 protected final static int ID_Th3Tx100Cr1000 = 19 + ID_Th3; 708 protected final static int ID_Th3Tx1000Cr1000 = 20 + ID_Th3; 709 protected final static int ID_Th3Tx10Cr2000 = 21 + ID_Th3; 710 protected final static int ID_Th3Tx100Cr2000 = 22 + ID_Th3; 711 protected final static int ID_Th3Tx1000Cr2000 = 23 + ID_Th3; 712 protected final static int ID_Th3Tx10Cr10000 = 24 + ID_Th3; 713 protected final static int ID_Th3Tx100Cr10000 = 25 + ID_Th3; 714 protected final static int ID_Th4 = 75; 715 protected final static int ID_Th4Tx10Cr1 = 1 + ID_Th4; 716 protected final static int ID_Th4Tx100Cr1 = 2 + ID_Th4; 717 protected final static int ID_Th4Tx1000Cr1 = 3 + ID_Th4; 718 protected final static int ID_Th4Tx10000Cr1 = 4 + ID_Th4; 719 protected final static int ID_Th4Tx100000Cr1 = 5 + ID_Th4; 720 protected final static int ID_Th4Tx10Cr10 = 6 + ID_Th4; 721 protected final static int ID_Th4Tx100Cr10 = 7 + ID_Th4; 722 protected final static int ID_Th4Tx1000Cr10 = 8 + ID_Th4; 723 protected final static int ID_Th4Tx10000Cr10 = 9 + ID_Th4; 724 protected final static int ID_Th4Tx100000Cr10 = 10 + ID_Th4; 725 protected final static int ID_Th4Tx10Cr100 = 11 + ID_Th4; 726 protected final static int ID_Th4Tx100Cr100 = 12 + ID_Th4; 727 protected final static int ID_Th4Tx1000Cr100 = 13 + ID_Th4; 728 protected final static int ID_Th4Tx10000Cr100 = 14 + ID_Th4; 729 protected final static int ID_Th4Tx10Cr500 = 15 + ID_Th4; 730 protected final static int ID_Th4Tx100Cr500 = 16 + ID_Th4; 731 protected final static int ID_Th4Tx1000Cr500 = 17 + ID_Th4; 732 protected final static int ID_Th4Tx10Cr1000 = 18 + ID_Th4; 733 protected final static int ID_Th4Tx100Cr1000 = 19 + ID_Th4; 734 protected final static int ID_Th4Tx1000Cr1000 = 20 + ID_Th4; 735 protected final static int ID_Th4Tx10Cr2000 = 21 + ID_Th4; 736 protected final static int ID_Th4Tx100Cr2000 = 22 + ID_Th4; 737 protected final static int ID_Th4Tx1000Cr2000 = 23 + ID_Th4; 738 protected final static int ID_Th4Tx10Cr10000 = 24 + ID_Th4; 739 protected final static int ID_Th4Tx100Cr10000 = 25 + ID_Th4; 740 protected final static int ID_Th10 = 100; 741 protected final static int ID_Th10Tx10Cr1 = 1 + ID_Th10; 742 protected final static int ID_Th10Tx100Cr1 = 2 + ID_Th10; 743 protected final static int ID_Th10Tx1000Cr1 = 3 + ID_Th10; 744 protected final static int ID_Th10Tx10000Cr1 = 4 + ID_Th10; 745 protected final static int ID_Th10Tx100000Cr1 = 5 + ID_Th10; 746 protected final static int ID_Th10Tx10Cr10 = 6 + ID_Th10; 747 protected final static int ID_Th10Tx100Cr10 = 7 + ID_Th10; 748 protected final static int ID_Th10Tx1000Cr10 = 8 + ID_Th10; 749 protected final static int ID_Th10Tx10000Cr10 = 9 + ID_Th10; 750 protected final static int ID_Th10Tx100000Cr10 = 10 + ID_Th10; 751 protected final static int ID_Th10Tx10Cr100 = 11 + ID_Th10; 752 protected final static int ID_Th10Tx100Cr100 = 12 + ID_Th10; 753 protected final static int ID_Th10Tx1000Cr100 = 13 + ID_Th10; 754 protected final static int ID_Th10Tx10000Cr100 = 14 + ID_Th10; 755 protected final static int ID_Th10Tx10Cr500 = 15 + ID_Th10; 756 protected final static int ID_Th10Tx100Cr500 = 16 + ID_Th10; 757 protected final static int ID_Th10Tx1000Cr500 = 17 + ID_Th10; 758 protected final static int ID_Th10Tx10Cr1000 = 18 + ID_Th10; 759 protected final static int ID_Th10Tx100Cr1000 = 19 + ID_Th10; 760 protected final static int ID_Th10Tx1000Cr1000 = 20 + ID_Th10; 761 protected final static int ID_Th10Tx10Cr2000 = 21 + ID_Th10; 762 protected final static int ID_Th10Tx100Cr2000 = 22 + ID_Th10; 763 protected final static int ID_Th10Tx1000Cr2000 = 23 + ID_Th10; 764 protected final static int ID_Th10Tx10Cr10000 = 24 + ID_Th10; 765 protected final static int ID_Th10Tx100Cr10000 = 25 + ID_Th10; 766 protected final static int[] TESTNBC = { 0, 767 10, 100, 1000, 10000, 100000, 100, 1000, 10000, 100000, 1000000, 1000, 10000, 100000, 1000000, 5000, 50000, 500000, 10000, 100000, 1000000, 20000, 200000, 2000000, 100000, 1000000, 10, 100, 1000, 10000, 100000, 100, 1000, 10000, 100000, 1000000, 1000, 10000, 100000, 1000000, 5000, 50000, 500000, 10000, 100000, 1000000, 20000, 200000, 2000000, 100000, 1000000, 10, 100, 1000, 10000, 100000, 100, 1000, 10000, 100000, 1000000, 1000, 10000, 100000, 1000000, 5000, 50000, 500000, 10000, 100000, 1000000, 20000, 200000, 2000000, 100000, 1000000, 10, 100, 1000, 10000, 100000, 100, 1000, 10000, 100000, 1000000, 1000, 10000, 100000, 1000000, 5000, 50000, 500000, 10000, 100000, 1000000, 20000, 200000, 2000000, 100000, 1000000, 10, 100, 1000, 10000, 100000, 100, 1000, 10000, 100000, 1000000, 1000, 10000, 100000, 1000000, 5000, 50000, 500000, 10000, 100000, 1000000, 20000, 200000, 2000000, 100000, 1000000, -1 }; 808 809 protected int getStartId(int testid) { 810 int res = 0; 811 while (testid > 0) { 812 testid--; 813 res += TESTNBC[testid]; 814 } 815 return res; 816 } 817 818 public class ObjectStatistic { 819 820 HashMap oid2Touch = new HashMap (); 821 long nbTouch = 0; 822 823 public synchronized void touch(Object oid) { 824 Integer i = (Integer ) oid2Touch.get(oid); 825 if (i == null) { 826 i = new Integer (1); 827 } else { 828 i = new Integer (i.intValue() + 1); 829 } 830 nbTouch++; 831 oid2Touch.put(oid, i); 832 } 833 834 public Set getAccessedOid() { 835 return oid2Touch.keySet(); 836 } 837 838 public long getNbAccess() { 839 return nbTouch; 840 } 841 } 842 } 843 | Popular Tags |