List of usage examples for org.apache.commons.lang.time StopWatch getTime
public long getTime()
Get the time on the stopwatch.
This is either the time between the start and the moment this method is called, or the amount of time between start and stop.
From source file:org.opentestsystem.delivery.testreg.rest.StudentPackageController.java
@ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/studentpackage", method = RequestMethod.GET, produces = MediaType.APPLICATION_XML_VALUE) @Secured({ "ROLE_Entity Read" }) @ResponseBody/*from w w w. j a v a 2 s .co m*/ public void extractStudentPackage(@RequestParam(value = "ssid", required = false) final String studentId, @RequestParam(value = "externalId", required = false) final String externalSsid, @RequestParam("stateabbreviation") final String stateAbbreviation, final HttpServletResponse response) throws IOException { StopWatch sw = new StopWatch(); sw.start(); Student student = null; if (hasText(studentId) && hasText(externalSsid)) { response.setStatus(HttpServletResponse.SC_CONFLICT); } else if (hasText(studentId)) { student = studentService.findByStudentIdAndStateAbbreviation(studentId, stateAbbreviation); } else if (hasText(externalSsid)) { student = studentService.findByExternalSsidAndStateAbbreviation(externalSsid, stateAbbreviation); } if (student != null) { String studentPackage = studentPackageService.exportStudentPackage(student); response.setContentType(MediaType.APPLICATION_XML_VALUE); ServletOutputStream out = response.getOutputStream(); IOUtils.copy(new ByteArrayInputStream(studentPackage.getBytes()), out); out.flush(); } else { response.setStatus(HttpServletResponse.SC_NO_CONTENT); } sw.stop(); this.metricClient.sendPerformanceMetricToMna("StudentPackage for " + externalSsid + " (ms) ", sw.getTime()); }
From source file:org.pdfsam.guiclient.gui.frames.JMainFrame.java
public JMainFrame() { StopWatch stopWatch = new StopWatch(); stopWatch.start();/*w ww . j a v a2s .c o m*/ log.info("Starting " + GuiClient.getApplicationName() + " Ver. " + GuiClient.getVersion()); runSplash(); ToolTipManager.sharedInstance().setDismissDelay(300000); initialize(); closeSplash(); stopWatch.stop(); log.info(GuiClient.getApplicationName() + " Ver. " + GuiClient.getVersion() + " " + GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "started in ") + DurationFormatUtils.formatDurationWords(stopWatch.getTime(), true, true)); }
From source file:org.pentaho.platform.web.http.api.resources.WorkerNodeActionInvokerAuditor.java
@Override public IActionInvokeStatus invokeAction(IAction action, String user, Map<String, Serializable> params) throws Exception { StopWatch stopWatch = new StopWatch(); stopWatch.start();/* w w w . j ava2 s. c om*/ Map<String, Serializable> auditParams = new HashMap<>(params); // the prams list key change after invokeAction. Need to preserve. makeAuditRecord(0, MessageTypes.INSTANCE_START, auditParams, action.getClass().getName()); try { return actionInvoker.invokeAction(action, user, params); } finally { makeAuditRecord(stopWatch.getTime() / 1000, MessageTypes.INSTANCE_END, auditParams, action.getClass().getName()); } }
From source file:org.sonatype.nexus.integrationtests.nexus748.Nexus748MultipleStart.java
@Test public void multipleStartTest() throws Exception { StopWatch stopWatch = new StopWatch(); NexusClient client = (NexusClient) getITPlexusContainer().lookup(NexusClient.ROLE); TestContext context = TestContainer.getInstance().getTestContext(); client.connect(AbstractNexusIntegrationTest.nexusBaseUrl, context.getAdminUsername(), context.getAdminPassword()); // enable security getNexusConfigUtil().enableSecurity(true); List<Long> startTimes = new ArrayList<Long>(); for (int ii = 0; ii < 10; ii++) { // start the timer stopWatch.reset();/* w w w.j a v a 2 s . co m*/ stopWatch.start(); // start getNexusStatusUtil().start(getTestId()); Assert.assertTrue(client.isNexusStarted(true)); // get the time stopWatch.stop(); // stop getNexusStatusUtil().stop(); startTimes.add(stopWatch.getTime()); } logger.info("\n\n**************\n Start times: \n**************"); logger.info("Iter\tTime"); for (int ii = 0; ii < startTimes.size(); ii++) { Long startTime = startTimes.get(ii); logger.info(" " + (ii + 1) + "\t " + (startTime / 1000.0) + "sec."); } }
From source file:org.springframework.integration.activiti.namespace.gateway.GatewayNamespaceTest.java
@Deployment(resources = "processes/si_gateway_example.bpmn20.xml") public void testAsync() throws Throwable { // get the process engine processEngine.getRepositoryService().createDeployment() .addClasspathResource("processes/si_gateway_example.bpmn20.xml").deploy(); // launch a process Map<String, Object> vars = new HashMap<String, Object>(); vars.put("customerId", 232); vars.put("orderNo", 223); vars.put("sku", "242421gfwe"); log.debug("about to start the business process"); StopWatch sw = new StopWatch(); sw.start();/*from w ww .j a v a2 s .co m*/ processEngine.getRuntimeService().startProcessInstanceByKey("sigatewayProcess", vars); sw.stop(); log.debug("total time to run the process:" + sw.getTime()); Thread.sleep(1000 * 5); }
From source file:org.trend.hgraph.mapreduce.pagerank.CalculateInitPageRankMapper.java
static void dispatchPageRank(List<String> outgoingRowKeys, double pageRank, Configuration conf, HTable edgeTable, Counter dispatchPrTimeConsumeCounter, Counter outgoingEdgeCounter, ContextWriterStrategy strategy) throws IOException, InterruptedException { int outgoingEdgeCount = outgoingRowKeys.size(); outgoingEdgeCounter.increment(outgoingEdgeCount); double pageRankForEachOutgoing = pageRank / (double) outgoingEdgeCount; StopWatch sw = null; String outgoingRowKey = null; try {//ww w .j ava 2 s . c om sw = new StopWatch(); sw.start(); for (int a = 0; a < outgoingRowKeys.size(); a++) { outgoingRowKey = outgoingRowKeys.get(a); strategy.write(outgoingRowKey, pageRankForEachOutgoing); } sw.stop(); dispatchPrTimeConsumeCounter.increment(sw.getTime()); } catch (IOException e) { System.err.println("failed while writing outgoingRowKey:" + outgoingRowKey); e.printStackTrace(System.err); throw e; } catch (InterruptedException e) { System.err.println("failed while writing outgoingRowKey:" + outgoingRowKey); e.printStackTrace(System.err); throw e; } }
From source file:org.trend.hgraph.mapreduce.pagerank.CalculateInitPageRankMapper.java
static List<String> getOutgoingRowKeys(Configuration conf, HTable vertexTable, HTable edgeTable, String rowKey, Counter counter) throws IOException { ResultScanner rs = null;/*from ww w . j av a 2s . c o m*/ String key = null; LinkedList<String> rowKeys = new LinkedList<String>(); StopWatch sw = null; // Put put = null; try { Scan scan = getRowKeyOnlyScan(rowKey); sw = new StopWatch(); sw.start(); rs = edgeTable.getScanner(scan); for (Result r : rs) { key = getOutgoingRowKey(r); // collect outgoing rowkeys rowKeys.add(key); } sw.stop(); counter.increment(sw.getTime()); } catch (IOException e) { System.err.println("access htable:" + Bytes.toString(edgeTable.getTableName()) + " failed"); e.printStackTrace(System.err); throw e; } finally { rs.close(); } return rowKeys; }
From source file:org.trend.hgraph.mapreduce.pagerank.CalculatePageRankReducer.java
@Override protected void reduce(Text key, Iterable<DoubleWritable> incomingPageRanks, Context context) throws IOException, InterruptedException { String rowkey = Bytes.toString(key.getBytes()).trim(); double incomingPageRankSum = 0.0D; StopWatch sw = new StopWatch(); sw.start();/* ww w. j av a 2 s . c o m*/ for (DoubleWritable incomingPageRank : incomingPageRanks) { incomingPageRankSum = incomingPageRankSum + incomingPageRank.get(); } // calculate new pageRank here double newPageRank = (dampingFactor * incomingPageRankSum) + ((1.0D - dampingFactor) / verticesTotalCnt); sw.stop(); context.getCounter(Counters.CAL_NEW_PR_TIME_CONSUMED).increment(sw.getTime()); sw.reset(); sw.start(); double oldPageRank = Utils.getPageRank(vertexTable, rowkey, Constants.PAGE_RANK_CQ_TMP_NAME); if (!pageRankEquals(oldPageRank, newPageRank, pageRankCompareScale)) { // collect pageRank changing count with counter context.getCounter(Counters.CHANGED_PAGE_RANK_COUNT).increment(1); } sw.stop(); context.getCounter(Counters.CMP_OLD_NEW_PR_TIME_CONSUMED).increment(sw.getTime()); context.write(key, new DoubleWritable(newPageRank)); }
From source file:org.trend.hgraph.util.test.GenerateTestData.java
private void doGenerateTestData() throws IOException { HTable vertexTable = null;/*from w w w. j a v a 2s . c o m*/ HTable edgeTable = null; Put put = null; long vIdx = 0; byte[] parentVertexKey = null; StopWatch timer = new StopWatch(); timer.start(); try { vertexTable = new HTable(this.getConf(), this.vertexTable); vertexTable.setAutoFlush(false); edgeTable = new HTable(this.getConf(), this.edgeTable); edgeTable.setAutoFlush(false); Queue<byte[]> parentVertexKeysQueue = new ArrayDeque<byte[]>(); int tmpEdgeCountPerVertex = 0; int edgeAcctCount = 0; Properties.Pair<Integer, Integer> pair = null; for (int rowCount = 0; rowCount < this.vertexCount; rowCount++) { put = generateVertexPut(); vertexTable.put(put); parentVertexKeysQueue.offer(put.getRow()); if (rowCount > 0) { vIdx = rowCount % tmpEdgeCountPerVertex; if (vIdx == 0) { parentVertexKey = parentVertexKeysQueue.poll(); edgeAcctCount++; if (this.isDistributionMode && !this.isFirstVertices[pair.key] && edgeAcctCount == tmpEdgeCountPerVertex) { this.addFirstVertex(Bytes.toString(parentVertexKey)); this.isFirstVertices[pair.key] = true; } pair = this.determineEdgeCountPerVertex(rowCount); tmpEdgeCountPerVertex = pair.value; edgeAcctCount = 0; } else if (vIdx > 0) { edgeAcctCount++; parentVertexKey = parentVertexKeysQueue.peek(); } else { throw new RuntimeException("vIdex:" + vIdx + " shall always not small than 0"); } put = generateEdgePut(rowCount, parentVertexKey, put.getRow()); edgeTable.put(put); } else { pair = this.determineEdgeCountPerVertex(rowCount); tmpEdgeCountPerVertex = pair.value; if (!this.isDistributionMode) this.addFirstVertex(Bytes.toString(put.getRow())); } } vertexTable.flushCommits(); edgeTable.flushCommits(); } catch (IOException e) { LOG.error("doGenerateTestData failed", e); throw e; } finally { if (null != vertexTable) vertexTable.close(); if (null != edgeTable) edgeTable.close(); timer.stop(); LOG.info("Time elapsed:" + timer.toString() + ", " + timer.getTime() + " for pushing " + this.vertexCount + " vertices test data to HBase"); LOG.info("first vertices id:" + this.firstVertices); } }
From source file:org.trend.hgraph.util.test.GetGeneratedGraphData.java
private long doDFSGetGeneratedGraphData(Configuration conf, int levelToTraverse, int curLevel, AbstractElement parentElement, LoopRowKeysStrategy rowKeysStrategy) throws Exception { if (curLevel > levelToTraverse) { LOG.info("reach last level:" + curLevel); return 0; }//from w ww . j av a 2 s . c o m String rowKey = null; Vertex vertex = null; int level = 1; long totalVertexCount = 0; long perRowKeyVertexCount = 0; if (null == parentElement) { level = 1; StopWatch timerAll = new StopWatch(); StopWatch timerRowKey = null; Graph graph = null; timerAll.start(); try { graph = HBaseGraphFactory.open(conf); while (rowKeysStrategy.hasNext()) { rowKey = rowKeysStrategy.next(); LOG.info("***HEAD:Start to process rowKey:" + rowKey + "***"); LOG.info("***HEAD:level:" + level + "***"); timerRowKey = new StopWatch(); timerRowKey.start(); vertex = graph.getVertex(rowKey); LOG.info("processing vertex:" + vertex.getId()); vertex.getPropertyKeys(); perRowKeyVertexCount = doDFSGetGeneratedGraphData(conf, levelToTraverse, level + 1, (AbstractElement) vertex, rowKeysStrategy); timerRowKey.stop(); perRowKeyVertexCount++; totalVertexCount += perRowKeyVertexCount; LOG.info("Time elapsed:" + timerRowKey.toString() + ", " + timerRowKey.getTime() + " for processing rowKey:" + rowKey + " for " + perRowKeyVertexCount + " of vertices"); LOG.info("***TAIL:level:" + level + "***"); LOG.info("***TAIL:Stop to process rowKey:" + rowKey + "***"); } timerAll.stop(); LOG.info("Time elapsed:" + timerAll.toString() + ", " + timerAll.getTime() + " for getting " + totalVertexCount + " of vertices"); } catch (Exception e) { LOG.error("Processing vertex failed for rowKey:" + rowKey, e); throw e; } finally { try { rowKeysStrategy.close(); } catch (Exception e) { LOG.error("Close rowKeysStrategy faiiled", e); throw e; } graph.shutdown(); } } else { org.trend.hgraph.Vertex parentVertex = (org.trend.hgraph.Vertex) parentElement; LOG.info("***HEAD:level:" + curLevel + "***"); for (Edge edge : parentVertex.getEdges()) { LOG.info("processing edge:" + edge.getId()); edge.getPropertyKeys(); vertex = edge.getVertex(Direction.OUT); LOG.info("processing vertex:" + vertex.getId()); totalVertexCount++; vertex.getPropertyKeys(); totalVertexCount += doDFSGetGeneratedGraphData(conf, levelToTraverse, curLevel + 1, (AbstractElement) vertex, rowKeysStrategy); } LOG.info("***TAIL:level:" + curLevel + "***"); } return totalVertexCount; }