List of usage examples for java.lang System nanoTime
@HotSpotIntrinsicCandidate public static native long nanoTime();
From source file:gridool.util.GridUtils.java
@Nonnull public static String generateTaskId(@Nonnull final String jobId, @Nonnull final GridTask task) { final long time = System.nanoTime(); final int hashcode = System.identityHashCode(task); long tid = Thread.currentThread().getId(); return jobId + '#' + Long.toString(time) + '/' + Integer.toString(hashcode) + 'T' + Long.toString(tid); }
From source file:de.zib.sfs.WrappedFSDataInputStream.java
@Override public int read(byte[] b, int off, int len) throws IOException { long startTime = System.nanoTime(); int result = this.in.read(b, off, len); String datanodeHostname = getDatanodeHostNameString(); this.aggregator.aggregateReadDataOperationStatistics(OperationSource.SFS, OperationCategory.READ, startTime, System.nanoTime(), this.fd, result == -1 ? 0 : result, this.hostname.equals(datanodeHostname) || "localhost".equals(datanodeHostname)); return result; }
From source file:at.alladin.rmbt.controlServer.QoSResultResource.java
@Post("json") public String request(final String entity) { addAllowOrigin();/*from w w w .j a v a 2 s.com*/ JSONObject request = null; final ErrorList errorList = new ErrorList(); final JSONObject answer = new JSONObject(); String answerString; System.out.println(MessageFormat.format(labels.getString("NEW_QOS_TESTRESULT_DETAIL"), getIP())); if (entity != null && !entity.isEmpty()) // try parse the string to a JSON object try { request = new JSONObject(entity); String lang = request.optString("language"); // Load Language Files for Client final List<String> langs = Arrays .asList(settings.getString("RMBT_SUPPORTED_LANGUAGES").split(",\\s*")); if (langs.contains(lang)) { errorList.setLanguage(lang); labels = (PropertyResourceBundle) ResourceBundle.getBundle("at.alladin.rmbt.res.SystemMessages", new Locale(lang)); } else lang = settings.getString("RMBT_DEFAULT_LANGUAGE"); if (conn != null) { final String testUuid = request.optString("test_uuid"); long ts = System.nanoTime(); QoSUtil.evaluate(settings, conn, new TestUuid(testUuid, UuidType.TEST_UUID), answer, lang, errorList); long endTs = System.nanoTime() - ts; answer.put("evaluation", "Time needed to evaluate test result: " + ((float) endTs / 1000000f) + " ms"); } else { errorList.addError("ERROR_DB_CONNECTION"); } } catch (final JSONException e) { errorList.addError("ERROR_REQUEST_JSON"); e.printStackTrace(); } catch (SQLException e) { errorList.addError("ERROR_DB_CONNECTION"); e.printStackTrace(); } catch (HstoreParseException e) { errorList.addErrorString(e.getMessage()); e.printStackTrace(); } catch (IllegalArgumentException e) { errorList.addError("ERROR_REQUEST_JSON"); e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedOperationException e) { e.printStackTrace(); errorList.addError("ERROR_REQUEST_QOS_RESULT_DETAIL_NO_UUID"); } else errorList.addErrorString("Expected request is missing."); try { answer.putOpt("error", errorList.getList()); } catch (final JSONException e) { System.out.println("Error saving ErrorList: " + e.toString()); } answerString = answer.toString(); //System.out.println(answerString); return answerString; }
From source file:org.terracotta.offheapstore.paging.TableStealingFromStorageIT.java
@Test public void testStealingFromOwnStorage() { PageSource source = new UpfrontAllocatingPageSource(new HeapBufferSource(), MEGABYTES.toBytes(1), MEGABYTES.toBytes(1));/*from w w w. j ava2 s .co m*/ OffHeapHashMap<Integer, byte[]> selfStealer = new WriteLockedOffHeapClockCache<>(source, true, new SplitStorageEngine<>(new IntegerStorageEngine(), new OffHeapBufferHalfStorageEngine<>(source, KILOBYTES.toBytes(16), ByteArrayPortability.INSTANCE, false, true))); long seed = System.nanoTime(); System.err.println("Random Seed = " + seed); Random rndm = new Random(seed); int terminalKey = 0; for (int key = 0; true; key++) { int size = selfStealer.size(); byte[] payload = new byte[rndm.nextInt(KILOBYTES.toBytes(1))]; Arrays.fill(payload, (byte) key); selfStealer.put(key, payload); if (size >= selfStealer.size()) { terminalKey = key; break; } } System.err.println("Terminal Key = " + terminalKey); for (int key = terminalKey + 1; key < 10 * terminalKey; key++) { byte[] payload = new byte[rndm.nextInt(KILOBYTES.toBytes(1))]; Arrays.fill(payload, (byte) key); selfStealer.put(key, payload); selfStealer.remove(rndm.nextInt(key)); } long measuredSize = 0; for (Entry<Integer, byte[]> e : selfStealer.entrySet()) { int key = e.getKey(); byte[] payload = e.getValue(); for (byte b : payload) { assertThat(b, is((byte) key)); } assertThat(selfStealer, hasKey(e.getKey())); measuredSize++; } assertThat(selfStealer.size(), is((int) measuredSize)); assertThat(selfStealer.getUsedSlotCount(), is(measuredSize)); }
From source file:ezbake.discovery.stethoscope.server.StethoscopeServiceHandler.java
@Override public boolean checkin(String applicationName, String serviceName, Endpoint endpoint) { this.serviceCache.put(endpointToString(endpoint), new StethoscopeCacheEntry(applicationName, serviceName, System.nanoTime())); // Just make sure we access to make Guava happy this.serviceCache.getIfPresent(endpointToString(endpoint)); logger.info("{} for {}{} just checked in!", endpointToString(endpoint), applicationName, serviceName); return true;//from w ww . j a va2 s .c o m }
From source file:com.carrotgarden.maven.scr.CarrotOsgiScrGenerate.java
/** * {@inheritDoc}/*ww w .j a va 2s. c o m*/ */ @Override public void execute() throws MojoFailureException { try { contextMessageClear(pomFile()); logInfo("generate"); logInfo("incremental: " + isContextIncremental()); if (!isProperPackaging()) { logInfo("skip for packaging=" + project.getPackaging()); return; } final File folder = outputDirectorySCR(); if (!folder.exists()) { logDebug(""); if (folder.mkdirs()) { logDebug("folder created : " + folder); } else { logError("failed to create folder : " + folder); } } logDebug(""); logDebug("excludedServices"); for (final String service : excludedServices) { logDebug("\t service=" + service); } logDebug(""); logDebug("properPackaging"); for (final String packaging : properPackaging) { logDebug("\t packaging=" + packaging); } descriptorCounter = 0; allclassesCounter = 0; final long timeStart = System.nanoTime(); if (!isProcessMainClasses && !isProcessTestClasses) { logError("you have not selected neither main nor test classes"); } if (isProcessMainClasses) { processClassFolder(ClassesSelector.COMPILE); } if (isProcessTestClasses) { processClassFolder(ClassesSelector.TESTING); } if (isIncludeEmptyDescriptor) { includeEmptyDescriptor(); } if (isIncludeGeneratedDescritors) { includeDescriptorResource(); } final long timeFinish = System.nanoTime(); logDebug(""); final long timeDiff = timeFinish - timeStart; final long timeRate = descriptorCounter == 0 ? 0 : timeDiff / descriptorCounter; logDebug("combined classes count = " + allclassesCounter); logDebug("descriptor class count = " + descriptorCounter); logDebug("time, millis total = " + timeDiff / 1000 / 1000); logDebug("rate, millis per descr = " + timeRate / 1000 / 1000); } catch (final Throwable e) { final String message = "generate failure: " + e; logError(message); contextMessageError(pomFile(), message, e); throw new MojoFailureException("bada-boom", e); } }
From source file:com.netflix.genie.web.security.saml.SAMLUserDetailsServiceImpl.java
/** * {@inheritDoc}// w ww .ja va 2s . com */ @Override public Object loadUserBySAML(final SAMLCredential credential) throws UsernameNotFoundException { final long start = System.nanoTime(); try { if (credential == null) { throw new UsernameNotFoundException("No credential entered. Unable to get username."); } final String userAttributeName = this.samlProperties.getAttributes().getUser().getName(); final String userId = credential.getAttributeAsString(userAttributeName); if (StringUtils.isBlank(userId)) { throw new UsernameNotFoundException("No user id found using attribute: " + userAttributeName); } // User exists. Give them at least USER role final List<GrantedAuthority> authorities = Lists.newArrayList(USER); // See if we can get any other roles final String groupAttributeName = this.samlProperties.getAttributes().getGroups().getName(); final String adminGroup = this.samlProperties.getAttributes().getGroups().getAdmin(); final String[] groups = credential.getAttributeAsStringArray(groupAttributeName); if (groups == null) { log.warn("No groups found. User will only get ROLE_USER by default."); } else if (Arrays.asList(groups).contains(adminGroup)) { authorities.add(ADMIN); } // For debugging what's available in the credential from the IDP if (log.isDebugEnabled()) { log.debug("Attributes:"); credential.getAttributes().forEach(attribute -> { log.debug("Attribute: {}", attribute.getName()); log.debug("Values: {}", StringUtils.join(credential.getAttributeAsStringArray(attribute.getName()), ',')); }); } log.info("{} is logged in with authorities {}", userId, authorities); return new User(userId, "DUMMY", authorities); } finally { final long finished = System.nanoTime(); this.loadTimer.record(finished - start, TimeUnit.NANOSECONDS); } }
From source file:ch.algotrader.dao.HibernateInitializer.java
@Override public <T extends BaseEntityI, C extends Collection<T>> C initializeCollection(BaseEntityI entity, String context, C col) {// w ww. j ava2s . co m if (col instanceof AbstractPersistentCollection) { AbstractPersistentCollection persistentCol = (AbstractPersistentCollection) col; if (!persistentCol.wasInitialized()) { if (persistentCol.getSession() != null) { long before = System.nanoTime(); persistentCol.forceInitialization(); MetricsUtil.account(ClassUtils.getShortClassName(entity.getClass()) + context, (before)); } else { throw new IllegalStateException("no hibernate session available"); } } } return col; }
From source file:com.yahoo.ycsb.db.RedisClient.java
public static String decompressWithLog(String st) { // System.out.println("decompress"); // System.out.println(st.substring(0, 20)); long start_time = System.nanoTime(); String ret = decompress(st);/*from ww w .j a va 2 s .c om*/ try { long end_time = System.nanoTime(); long time = end_time - start_time; BufferedWriter bw = new BufferedWriter(new FileWriter("decompress_time.txt", true)); bw.write("" + time); bw.newLine(); bw.flush(); } catch (Exception e) { } // System.out.println("decompressed"); // System.out.println(ret.substring(0, 20)); return ret; }
From source file:com.diversityarrays.dal.db.bms.GenusStore.java
private void createGenusTable(Connection conn, Closure<String> progress) throws SQLException { progress.execute("Creating Genus TEMPORARY table..."); SqlUtil.executeUpdate(conn, CREATE_GENUS_TABLE); String insertGenusRecords = StringTemplate.buildString(INSERT_GENUS_RECORDS_TEMPLATE) .replace("fldno", fldNoForGenus).build(); progress.execute("Populating Genus TEMPORARY table..."); long startNanos = System.nanoTime(); int statusCode = SqlUtil.executeUpdate(conn, insertGenusRecords); long elapsedNanos = System.nanoTime() - startNanos; progress.execute("Population of Genus table took " + (elapsedNanos / 1_000_000.0) + " millis, statusCode=" + statusCode);/*from w ww . ja va 2s. co m*/ }