public Value(String payload) { this.payload = payload; if (!EMPTY_PAYLOAD.equals(payload)) { Stopwatch tracer = compressPayloadTimer.start(); try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); GZIPOutputStream out = new GZIPOutputStream(bos); byte[] rawBytes = payload.getBytes(); out.write(rawBytes); // Finish creation of gzip file out.finish(); out.close(); bos.close(); gzipped = bos.toByteArray(); } catch (IOException e) { gzipped = null; } finally { if (tracer != null) { tracer.stop(); } } } else { gzipped = null; } }
public long incr(String key, long by, long def, int exp) { final Stopwatch operationDuration = getTimer(INCR_OPERATION_STRING).start(); long val = 0; try { val = mutate(Mutator.incr, key, by, def, exp); } finally { operationDuration.stop(); if (log.isDebugEnabled()) log.debug("Increment Key : " + key + "; by : " + by + "; default : " + def + "; exp : " + exp + "; val : " + val + "; Elapsed Time - " + operationDuration.getDuration(TimeUnit.MILLISECONDS)); } return val; }
private static Stopwatch start(Timer sm) { Stopwatch sw = new BasicStopwatch() { @Override public void stop() { super.stop(); long duration = getDuration(TimeUnit.MILLISECONDS); sm.record(duration, TimeUnit.MILLISECONDS); } }; sw.start(); return sw; }
@Override public void stopAndLog() { DynamicTimer.record(config, stopwatch.getDuration()); }
@Override public void stopAndLog() { DynamicTimer.record(config, stopwatch.getDuration()); }
@Override protected BasicPoolEntry getEntryBlocking(HttpRoute route, Object state, long timeout, TimeUnit tunit, WaitingThreadAborter aborter) throws ConnectionPoolTimeoutException, InterruptedException { Stopwatch stopWatch = requestTimer.start(); try { return super.getEntryBlocking(route, state, timeout, tunit, aborter); } finally { stopWatch.stop(); } }
public long decr(String key, long by, long def, int exp) { final Stopwatch operationDuration = getTimer(DECR_OPERATION_STRING).start(); long val = 0; try { val = super.decr(key, by, def, exp); } finally { operationDuration.stop(); if (log.isDebugEnabled()) log.debug("decrement Key : " + key + "; by : " + by + "; default : " + def + "; exp : " + exp + "; val : " + val + "; Elapsed Time - " + (operationDuration.getDuration(TimeUnit.MILLISECONDS))); } return val; }
/** * {@inheritDoc} */ @Override public Stopwatch start() { Stopwatch s = new TimedStopwatch(this); s.start(); return s; }
@Override public void receivedStatus(OperationStatus val) { if (val.getStatusCode().equals(StatusCode.SUCCESS)) { if (log.isDebugEnabled()) log.debug("AddOrAppend Key (Append Operation): " + key + "; Status : " + val.getStatusCode().name() + "; Message : " + val.getMessage() + "; Elapsed Time - " + (operationDuration.getDuration(TimeUnit.MILLISECONDS))); getCounter(AOA_APPEND_OPERATION_SUCCESS_STRING).increment(); rv.set(Boolean.TRUE, val); appendSuccess = true; } else { getCounter("AoA-AppendOperation-"+ val.getStatusCode().name()).increment(); } }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // if the method is one of the CompositeMonitor interface final Class<?> declaringClass = method.getDeclaringClass(); if (declaringClass.isAssignableFrom(CompositeMonitor.class)) { return method.invoke(this, args); } final String methodName = method.getName(); final Timer timer = timers.get(methodName); final Stopwatch stopwatch = timer.start(); try { return method.invoke(concrete, args); } finally { stopwatch.stop(); } } }
@Test public void testGetValue() throws Exception { Stopwatch s = DynamicTimer.start("test1", tagList); Timer c = getByName("test1"); s.stop(); // we don't call s.stop(), so we only have one recorded value assert c != null; assertEquals(c.getValue().longValue(), s.getDuration(TimeUnit.MILLISECONDS)); c.record(13, TimeUnit.MILLISECONDS); long expected = (13 + s.getDuration(TimeUnit.MILLISECONDS)) / 2; assertEquals(c.getValue().longValue(), expected); }
/** * {@inheritDoc} */ @Override public Stopwatch start() { Stopwatch s = new TimedStopwatch(this); s.start(); return s; }
@Override public void stopAndLog() { DynamicTimer.record(config, stopwatch.getDuration()); }
/** * Queries AWS to see if the load balancer flag is suspended. * * @param asgAccountid the accountId this asg resides in, if applicable (null will use the default accountId) * @param asgName the name of the asg * @return true, if the load balancer flag is not suspended, false otherwise. */ private Boolean isASGEnabledinAWS(String asgAccountid, String asgName) { try { Stopwatch t = this.loadASGInfoTimer.start(); boolean returnValue = !isAddToLoadBalancerSuspended(asgAccountid, asgName); t.stop(); return returnValue; } catch (Throwable e) { logger.error("Could not get ASG information from AWS: ", e); } return Boolean.TRUE; }
@Override @SuppressWarnings("synthetic-access") public void receivedStatus(OperationStatus status) { operationDuration.stop(); if (log.isDebugEnabled()) log.debug("GetBulk Keys : " + keys + "; Status : " + status.getStatusCode().name() + "; Message : " + status.getMessage() + "; Elapsed Time - " + operationDuration.getDuration(TimeUnit.MILLISECONDS)); if (status.getStatusCode().equals(StatusCode.SUCCESS)) { getCounter(BULK_OPERATION_STRING + "-SUCCESS").increment(); } else { getCounter(BULK_OPERATION_STRING + "-" + status.getStatusCode().name()).increment();//First lets get some data and then we can add Host info } rv.setStatus(status); }
/** * {@inheritDoc} */ @Override public Stopwatch start() { Stopwatch s = new TimedStopwatch(this); s.start(); return s; }
@Override public void stopAndLog() { DynamicTimer.record(config, stopwatch.getDuration()); }
@Override protected BasicPoolEntry createEntry(RouteSpecificPool rospl, ClientConnectionOperator op) { createEntryCounter.increment(); Stopwatch stopWatch = creationTimer.start(); try { return super.createEntry(rospl, op); } finally { stopWatch.stop(); } }
@Test public void testByStrings() throws Exception { Stopwatch s = DynamicTimer.start("byName"); Stopwatch s2 = DynamicTimer.start("byName2", "key", "value"); Thread.sleep(100L); s.stop(); s2.stop(); Timer c1 = getByName("byName"); assert c1 != null; assertEquals(c1.getValue().longValue(), s.getDuration(TimeUnit.MILLISECONDS)); Timer c2 = getByName("byName2"); assert c2 != null; assertEquals(c2.getValue().longValue(), s2.getDuration(TimeUnit.MILLISECONDS)); } }
/** * Returns a stopwatch that has been started and will automatically * record its result to this timer when stopped. Every time this method is called * the number of active tasks for the timer will be incremented. * The number will be decremented when the stopwatch is stopped. */ public Stopwatch start() { Stopwatch s = new DurationStopwatch(); s.start(); return s; }