1 18 19 package org.apache.jmeter.engine; 20 21 26 public class LagDetector extends Thread 27 { 28 private long incr = MAX_SLEEP / DIV; 29 private long totalLag; 30 private int count; 31 private boolean running; 32 public final static long MAX_SLEEP = 500; 33 34 private final static long DIV = 3; 35 36 39 public LagDetector() 40 { 41 } 42 43 48 public float getAveLag() 49 { 50 return (float) ((float) totalLag / (float) count); 51 } 52 53 58 public float getLagRatio() 59 { 60 return ((float) totalLag / (float) count) / incr; 61 } 62 63 public void stopRunning() 64 { 65 running = false; 66 } 67 68 71 public void run() 72 { 73 running = true; 74 long time; 75 totalLag = 0; 76 count = 0; 77 while (running) 78 { 79 time = System.currentTimeMillis(); 80 try 81 { 82 Thread.sleep(incr); 83 } 84 catch (Exception e) 85 { 86 } 87 time = System.currentTimeMillis() - time; 88 totalLag += time - incr; 89 count++; 90 } 91 } 92 } 93 | Popular Tags |