List of usage examples for java.lang System nanoTime
@HotSpotIntrinsicCandidate public static native long nanoTime();
From source file:com.linkedin.pinot.controller.utils.SegmentMetadataMockUtils.java
public static SegmentMetadata mockSegmentMetadata(String tableName, String segmentName) { String uniqueNumericString = Long.toString(System.nanoTime()); return mockSegmentMetadata(tableName, segmentName, 0, uniqueNumericString); }
From source file:io.kahu.hawaii.util.call.statistics.RequestStatistic.java
public void startBackendRequest() { this.startCallNano = System.nanoTime(); }
From source file:Main.java
@Override public String call() throws Exception { while (timeToLive <= System.nanoTime()) { // simulate work here Thread.sleep(500);/*from w w w. ja v a2s. com*/ } final long end = System.nanoTime(); return String.format("Finished Elapsed Time = %d, scheduled for %d", TimeUnit.NANOSECONDS.toMillis(timeToLive - end), this.duration); }
From source file:tern.server.nodejs.NodejsTernHelper.java
public static JsonObject makeRequest(String baseURL, TernDoc doc, boolean silent, List<IInterceptor> interceptors, ITernServer server) throws IOException, TernException { TernQuery query = doc.getQuery();/*from w ww . j a v a 2 s . c o m*/ String methodName = query != null ? query.getLabel() : ""; long startTime = 0; if (interceptors != null) { startTime = System.nanoTime(); for (IInterceptor interceptor : interceptors) { interceptor.handleRequest(doc, server, methodName); } } HttpClient httpClient = new DefaultHttpClient(); try { // Post JSON Tern doc HttpPost httpPost = createHttpPost(baseURL, doc); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity entity = httpResponse.getEntity(); InputStream in = entity.getContent(); // Check the status StatusLine statusLine = httpResponse.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode != HttpStatus.SC_OK) { // node.js server throws error String message = IOUtils.toString(in); if (StringUtils.isEmpty(message)) { throw new TernException(statusLine.toString()); } throw TernExceptionFactory.create(message); } try { JsonObject response = (JsonObject) Json.parse(new InputStreamReader(in, UTF_8)); if (interceptors != null) { for (IInterceptor interceptor : interceptors) { interceptor.handleResponse(response, server, methodName, getElapsedTimeInMs(startTime)); } } return response; } catch (ParseException e) { throw new IOException(e); } } catch (Exception e) { if (interceptors != null) { for (IInterceptor interceptor : interceptors) { interceptor.handleError(e, server, methodName, getElapsedTimeInMs(startTime)); } } if (e instanceof IOException) { throw (IOException) e; } if (e instanceof TernException) { throw (TernException) e; } throw new TernException(e); } finally { httpClient.getConnectionManager().shutdown(); } }
From source file:com.amazonaws.metrics.ServiceLatencyProvider.java
/** * Ends the timing. Must not be called more than once. *//* w ww . jav a2s . c o m*/ public ServiceLatencyProvider endTiming() { if (endNano != startNano) { throw new IllegalStateException(); } endNano = System.nanoTime(); return this; }
From source file:com.heliosmi.portal.aspect.LoggingAspect.java
@Around("allBeans()") public Object profiler(ProceedingJoinPoint pjp) throws Throwable { long start = System.nanoTime(); String classMethodName = pjp.getTarget().getClass().getSimpleName() + "." + pjp.getSignature().getName(); log.info(classMethodName + " - called with param(s) " + ToStringBuilder.reflectionToString(pjp.getArgs())); Object returnValue = null;// ww w.j a v a2s. c o m try { returnValue = pjp.proceed(); } catch (Exception exception) { log.error(ToStringBuilder.reflectionToString(ExceptionUtils.getRootCause(exception))); log.error(ExceptionUtils.getStackTrace(exception)); throw exception; } long end = System.nanoTime(); log.info(classMethodName + " - finished. Took " + (end - start) + " milliseconds. "); return returnValue; }
From source file:com.norconex.collector.http.delay.impl.CrawlerDelay.java
public void delay(long expectedDelayNanos, String url) { if (expectedDelayNanos <= 0) { return;/*from w ww . j a v a 2 s.c om*/ } try { synchronized (lastHitEpochNanos) { while (sleeping) { Sleeper.sleepNanos(Math.min(TINY_SLEEP_MS, expectedDelayNanos)); } sleeping = true; } delay(expectedDelayNanos, lastHitEpochNanos.longValue()); lastHitEpochNanos.setValue(System.nanoTime()); } finally { sleeping = false; } }
From source file:io.kahu.hawaii.util.call.statistics.RequestStatistic.java
public void endBackendRequest() { this.endCallNano = System.nanoTime(); }
From source file:org.elasticsearch.logstash.Server.java
public void start() throws InterruptedException { long start = System.nanoTime(); AtomicInteger counter = new AtomicInteger(1); for (int i = 0; i < messageCount; i++) { /* wait for input -- e.g. wait on a NETTY pipeline input */ // JokeResource jokeResource = restTemplate.getForObject("http://api.icndb.com/jokes/random", JokeResource.class); final String message = String.format("message: %d", counter.getAndIncrement()); inputReactor.notify(Pipeline.Stage.input, Event.wrap(message)); }//w w w . j a v a 2s . c o m latch.await(); long elapsed = System.nanoTime() - start; System.out.println("Elapsed time: " + elapsed + "ns"); System.out.println("Average pipeline process time per message: " + elapsed / messageCount + "ns"); }
From source file:com.temenos.interaction.loader.detector.DirectoryChangeActionNotifierTest.java
public static File createTempDirectory() throws IOException { final File temp; File tempDir = new File(System.getProperty("java.io.tmpdir")); temp = new File(tempDir, "test" + System.nanoTime()); if (!(temp.mkdirs())) { throw new IOException("Could not create temporary test dir"); }/*from w ww. java 2 s.c o m*/ return (temp); }