1 9 10 package org.objectweb.cjdbc.scenario.standalone.jvm; 11 12 import java.io.FileOutputStream ; 13 import java.io.PrintStream ; 14 15 import junit.framework.TestCase; 16 17 public class HeapTest extends TestCase 18 { 19 20 static final int NUM_ITERATIONS = 500; 21 static final int NUM_NODES_TO_ALLOC = 3000; 22 static final int NUM_DATA_POINTS = 50000; 23 static final int MAX_NUMBER_THREAD = 5; 24 static final int TOTAL_CYCLES = 2; 25 26 public void testJVM() 27 { 28 main(new String []{"" + MAX_NUMBER_THREAD, "" + TOTAL_CYCLES}); 29 } 30 31 public static void main(String [] args) 32 { 33 34 int k_numIterations = NUM_ITERATIONS; 35 int k_numNodesToAlloc = NUM_NODES_TO_ALLOC; 36 int k_numDataPoints = NUM_DATA_POINTS; 37 38 int maxNumThreads = 0; 39 int numThreads = 0; 40 int totalCycles = 0; 41 int heapCycles = 0; 42 int cpuCycles = 0; 43 int i = 0; 44 45 try 46 { 47 48 if (args.length < 2) 49 usage(); 50 PrintStream logFile = null; 51 try 52 { 53 logFile = new PrintStream (new FileOutputStream (args[2])); 54 } 55 catch (Exception e) 56 { 57 System.out 58 .println("Unable to open log file. Printing to System.out..."); 59 logFile = System.out; 60 } 61 62 try 63 { 64 maxNumThreads = Integer.parseInt(args[0]); 65 totalCycles = Integer.parseInt(args[1]); 66 } 67 catch (Exception e) 68 { 69 } 70 71 if (maxNumThreads == 0 || totalCycles == 0) 72 usage(); 73 else 74 { 75 logFile.println("\nMax # threads = " + maxNumThreads + "\n" 76 + "Total (heap + CPU) cycles = " + totalCycles + "\n\n"); 77 } 78 79 HeapThread[] threads = new HeapThread[maxNumThreads]; 80 logFile.print("# Threads"); 81 for (cpuCycles = 0, heapCycles = totalCycles; cpuCycles <= totalCycles; cpuCycles++, heapCycles--) 82 { 83 logFile.print("\t" + heapCycles + " Heap, " + cpuCycles + " CPU"); 84 } 85 logFile.flush(); 86 87 for (numThreads = 1; numThreads <= maxNumThreads; numThreads++) 88 { 89 logFile.print("\n\n" + numThreads); 90 for (cpuCycles = 0, heapCycles = totalCycles; cpuCycles <= totalCycles; cpuCycles++, heapCycles--) 91 { 92 93 Barrier goFlag = new Barrier(numThreads); 94 for (i = 0; i < numThreads; i++) 95 { 96 threads[i] = new HeapThread(i, numThreads, 97 new int[k_numDataPoints], k_numDataPoints, k_numIterations, 98 k_numNodesToAlloc, heapCycles, cpuCycles, goFlag); 99 } 100 101 long elapsedTime = System.currentTimeMillis(); 102 for (i = 0; i < numThreads; i++) 103 { 104 threads[i].start(); 105 } 106 107 for (i = 0; i < numThreads; i++) 108 { 109 threads[i].join(); 110 } 111 elapsedTime = System.currentTimeMillis() - elapsedTime; 112 logFile.print("\t" + elapsedTime); 113 } 114 } 115 logFile.flush(); 116 } 117 catch (Exception e) 118 { 119 System.out.println("Caught exception!!"); 120 e.printStackTrace(); 121 } 122 123 } 124 125 public static void usage() 126 { 127 System.out 128 .println("java HeapTest <numThreads> <num of (CPU + Heap) cycles>"); 129 System.exit(1); 130 } 131 } 132 133 | Popular Tags |