|
| 1 | +/******************************************************************************* |
| 2 | +* Copyright (c) 2017 IBM Corp. |
| 3 | +* |
| 4 | +* This program and the accompanying materials are made available under the |
| 5 | +* terms of the Eclipse Public License 2.0 which accompanies this distribution |
| 6 | +* and is available at http://eclipse.org/legal/epl-2.0 or the Apache License, |
| 7 | +* Version 2.0 which accompanies this distribution and is available at |
| 8 | +* https://www.apache.org/licenses/LICENSE-2.0. |
| 9 | +* |
| 10 | +* This Source Code may also be made available under the following Secondary |
| 11 | +* Licenses when the conditions for such availability set forth in the |
| 12 | +* Eclipse Public License, v. 2.0 are satisfied: GNU General Public License, |
| 13 | +* version 2 with the GNU Classpath Exception [1] and GNU General Public License, |
| 14 | +* version 2 with the OpenJDK Assembly Exception [2]. |
| 15 | +* |
| 16 | +* [1] https://www.gnu.org/software/classpath/license.html |
| 17 | +* [2] http://openjdk.java.net/legal/assembly-exception.html |
| 18 | +* |
| 19 | +* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 |
| 20 | +*******************************************************************************/ |
| 21 | +package net.openj9.test; |
| 22 | + |
| 23 | +import java.io.File; |
| 24 | +import java.io.IOException; |
| 25 | +import java.util.Random; |
| 26 | +import java.util.concurrent.Callable; |
| 27 | +import java.util.Calendar; |
| 28 | +import java.util.Date; |
| 29 | +import java.awt.image.BufferedImage; |
| 30 | +import java.text.DateFormat; |
| 31 | +import java.text.SimpleDateFormat; |
| 32 | +import javax.imageio.ImageIO; |
| 33 | +import java.lang.management.ManagementFactory; |
| 34 | + |
| 35 | +import net.openj9.test.LargeObj; |
| 36 | + |
| 37 | + |
| 38 | +public class CombinedLoad implements Callable<Long> |
| 39 | +{ |
| 40 | + private int workloadImageNumber; |
| 41 | + private long threadId; |
| 42 | + private long busyTime = 0; |
| 43 | + private long memoryLimitInBytes = 0L; |
| 44 | + private final int numObjs = 10000; |
| 45 | + private long numtrans = 0; |
| 46 | + |
| 47 | + public CombinedLoad(int workloadTypeNum, long mSec, long memLimitInBytes) { |
| 48 | + workloadImageNumber = workloadTypeNum; |
| 49 | + busyTime = mSec * 1000000L ; |
| 50 | + memoryLimitInBytes = memLimitInBytes; |
| 51 | + } |
| 52 | + |
| 53 | + public long getTrans() { |
| 54 | + return numtrans; |
| 55 | + } |
| 56 | + |
| 57 | + public void resetTrans() { |
| 58 | + numtrans = 0; |
| 59 | + } |
| 60 | + |
| 61 | + public long getThreadId() { |
| 62 | + return threadId; |
| 63 | + } |
| 64 | + |
| 65 | + public Long call() { |
| 66 | + Date dateobj; |
| 67 | + Calendar calobj; |
| 68 | + long startTime = 0; |
| 69 | + long currTime = 0; |
| 70 | + float diff = 0; |
| 71 | + LargeObj[] memoryFill = new LargeObj[numObjs]; |
| 72 | + DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss"); |
| 73 | + java.lang.management.MemoryMXBean membean = ManagementFactory.getMemoryMXBean(); |
| 74 | + long heapInBytes = 0L; |
| 75 | + |
| 76 | + threadId = Thread.currentThread().getId(); |
| 77 | + startTime = System.nanoTime(); |
| 78 | + System.out.println("Test Application: CPU: Thread: " + threadId + " busy looping start"); |
| 79 | + do { |
| 80 | + File iFile; |
| 81 | + BufferedImage image; |
| 82 | + |
| 83 | + if ( System.getProperty("isIdle").equals("true") ) { |
| 84 | + System.out.println("App is going IDLE.. Stop working.. zzzzzz"); |
| 85 | + break; |
| 86 | + } |
| 87 | + |
| 88 | + // This loop tries to wake up JIT by running for 30 secs |
| 89 | + long busyTime = 30000 * 1000000L; |
| 90 | + while ((System.nanoTime() - startTime) < busyTime) { |
| 91 | + Random rand = new Random(); |
| 92 | + double result = java.lang.Math.log(rand.nextDouble()); |
| 93 | + } |
| 94 | + |
| 95 | + for (int i = 0; i < 10000 ; i++) { |
| 96 | + |
| 97 | + dateobj = new Date(); |
| 98 | + calobj = Calendar.getInstance(); |
| 99 | + currTime = System.nanoTime(); |
| 100 | + diff = (float) ((float) (currTime - startTime) / (float) 1000000); |
| 101 | + for (int j = 0; j < numObjs; j++) { |
| 102 | + memoryFill[j] = new LargeObj(diff); |
| 103 | + } |
| 104 | + |
| 105 | + if (diff == 1.000000 || diff == 2.000000 || diff == 3.000000 || diff == 4.000000 || diff == 5.000000) { |
| 106 | + System.out.println("CurrTime: " + currTime + " startTime: " + startTime + " busyTime: " + busyTime + " diff: " + diff); |
| 107 | + } |
| 108 | + if (diff > 6) { |
| 109 | + break; |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + try { |
| 114 | + if( System.getProperty("isIdle").equals("true") ) { |
| 115 | + System.out.println("App is going IDLE.. Stop working.. zzzzzz"); |
| 116 | + break; |
| 117 | + } |
| 118 | + switch(workloadImageNumber) { |
| 119 | + case 0: |
| 120 | + iFile = new File("images/1KbImage.jpg"); |
| 121 | + break; |
| 122 | + case 1: |
| 123 | + iFile = new File("images/500KbImage.jpg"); |
| 124 | + break; |
| 125 | + case 2: |
| 126 | + iFile = new File("images/1MbImage.jpg"); |
| 127 | + break; |
| 128 | + case 3: |
| 129 | + iFile = new File("images/1point5MbImage.jpg"); |
| 130 | + break; |
| 131 | + case 4: |
| 132 | + iFile = new File("images/2MbImage.jpg"); |
| 133 | + break; |
| 134 | + case 5: |
| 135 | + iFile = new File("images/5MbImage.jpg"); |
| 136 | + break; |
| 137 | + case 6: |
| 138 | + iFile = new File("images/15point5MbImage.png"); |
| 139 | + break; |
| 140 | + default : |
| 141 | + iFile = new File("images/1MbImage.jpg"); |
| 142 | + } |
| 143 | + image = ImageIO.read(iFile); |
| 144 | + }catch (IOException e) { |
| 145 | + System.err.println("Error reading image file\n"); |
| 146 | + } |
| 147 | + |
| 148 | + iFile = null; |
| 149 | + image = null; |
| 150 | + currTime = System.nanoTime(); |
| 151 | + numtrans++; |
| 152 | + heapInBytes = membean.getHeapMemoryUsage().getUsed(); |
| 153 | + |
| 154 | + } while((currTime - startTime) < busyTime && heapInBytes <= memoryLimitInBytes); |
| 155 | + |
| 156 | + System.out.println("Test Application: Thread: " + threadId + " busy looping done; Num-trans: " + numtrans); |
| 157 | + return threadId; |
| 158 | + } |
| 159 | +} |
0 commit comments