List of usage examples for java.lang.management ThreadMXBean getCurrentThreadCpuTime
public long getCurrentThreadCpuTime();
From source file:jtabwb.launcher.Launcher.java
private void searchProof(ProofSearchData proofSearchData) { // BUILD THE ENGINE //currentConfiguration.engineExecutionMode = ExecutionMode.ENGINE_VERBOSE; Engine engine = new Engine(proofSearchData.selectedProver, proofSearchData.goal, currentConfiguration.engineExecutionMode); if (!currentConfiguration.testsetmode) LOG.info(MSG.LAUNCHER.INFO.PROVING_BEGIN); // start the proof search ThreadMXBean bean = ManagementFactory.getThreadMXBean(); proofSearchData.execution_start_time = getCurrentTimeMilleseconds(); long cpuTime = bean.getCurrentThreadCpuTime(); engine.searchProof();//from ww w .jav a 2 s. c om // end of proof search, set info values cpuTime = bean.getCurrentThreadCpuTime() - cpuTime; proofSearchData.execution_end_time = getCurrentTimeMilleseconds(); // set the data of the last proof search IterationInfo lastIterationInfo = engine.getLastIterationInfo(); proofSearchData.proofSearchResult = engine.getResult(); proofSearchData.testStatus = TestStatus.getTestStatus(proofSearchData); proofSearchData.iterationCounter = lastIterationInfo.getNumberOfIterations(); proofSearchData.max_stack_size = lastIterationInfo.getMaxStackSize(); proofSearchData.proofSearchResult = engine.getResult(); proofSearchData.numberOfRestoredBacktrackPoints = lastIterationInfo.getNumberOfRestoredBacktrackPoints(); proofSearchData.numberOfGeneratedNodes = lastIterationInfo.getNumberOfGeneratedNodes(); proofSearchData.numberOfRestoredBranchPoints = lastIterationInfo.getNumberOfRestoredBranchPoints(); // generates data and data files according with defined options if (currentConfiguration.engineExecutionMode == ExecutionMode.ENGINE_TRACE) proofSearchData.trace = engine.getTrace(); if (currentConfiguration.testsetmode) testset_printSingleTestInfo(proofSearchData); else { print_postProofSearchDetails(proofSearchData); if (currentConfiguration.generateLogFile) log_generateFile(proofSearchData); if (currentConfiguration.generateLogTimeFile) timeLog_generateFile(proofSearchData); if (currentConfiguration.generateLatexOfProof) latexProof_generateFile(proofSearchData); if (currentConfiguration.generateLatexOfCtrees) latexCtrees_generateFile(proofSearchData); if (currentConfiguration.saveTrace) trace_generateFile(proofSearchData); if (currentConfiguration.generatef3TimeStr) timing_f3time_generateString(proofSearchData); if (currentConfiguration.generateJTabWbTimeStr) timing_jtabwb_generatesString(proofSearchData); } }
From source file:org.renjin.primitives.System.java
/** * Returns object of class "proc_time" which is a numeric vector of * length 5, containing the user, system, and total elapsed times for * the currently running R process, and the cumulative sum of user * and system times of any child processes spawned by it on which it * has waited. //from w ww . j a v a 2 s . c om * * _The user time is the CPU time charged for the execution of user * instructions of the calling process. The system time is the CPU * time charged for execution by the system on behalf of the calling * process._ */ @Builtin("proc.time") public static DoubleVector procTime() { DoubleArrayVector.Builder result = new DoubleArrayVector.Builder(); StringVector.Builder names = new StringVector.Builder(); long totalCPUTime; long userCPUTime; long elapsedTime; // There doesn't seem to be any platform-independent way of accessing // CPU use for the whole JVM process, so we'll have to make do // with the timings for the thread we're running on. // // Additionally, the MX Beans may not be available in all environments, // so we need to fallback to app try { ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); totalCPUTime = threadMXBean.getCurrentThreadCpuTime(); userCPUTime = threadMXBean.getCurrentThreadUserTime(); RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); elapsedTime = runtimeMXBean.getUptime(); } catch (Error e) { // ThreadMXBean is not available in all environments // Specifically, AppEngine will throw variously SecurityErrors or // ClassNotFoundErrors if we try to access these classes userCPUTime = totalCPUTime = java.lang.System.nanoTime(); elapsedTime = new Date().getTime(); } // user.self names.add("user.self"); result.add(userCPUTime / NANOSECONDS_PER_SECOND); // sys.self names.add("sys.self"); result.add((totalCPUTime - userCPUTime) / NANOSECONDS_PER_SECOND); // elapsed // (wall clock time) names.add("elapsed"); result.add(elapsedTime / MILLISECONDS_PER_SECOND); // AFAIK, we don't have any platform independent way of accessing // this info. // user.child names.add("user.child"); result.add(0); // sys.child names.add("sys.child"); result.add(0); result.setAttribute(Symbols.NAMES, names.build()); result.setAttribute(Symbols.CLASS, StringVector.valueOf("proc_time")); return result.build(); }
From source file:org.talend.dataquality.statistics.datetime.PerformanceTest.java
@Test @Ignore//from ww w . j a v a2 s. c o m public void testIsDate() throws IOException { final InputStream stream = SystemDateTimePatternManager.class.getResourceAsStream("DateSampleTable.txt"); final List<String> lines = IOUtils.readLines(stream); SystemDateTimePatternManager.isDate("12/02/99");// init DateTimeFormatters final ThreadMXBean mxBean = ManagementFactory.getThreadMXBean(); final long cpuBefore = mxBean.getCurrentThreadCpuTime(); int count = 0; loop: for (int n = 0; n < REPLICATE; n++) { for (int i = 1; i < lines.size(); i++) { final String line = lines.get(i); if (!"".equals(line.trim())) { final String[] sampleLine = line.trim().split("\t"); final String sample = sampleLine[0]; CustomDateTimePatternManager.isDate(sample, Collections.emptyList()); count++; if (count > 100000) { break loop; } } } } final long cpuAfter = mxBean.getCurrentThreadCpuTime(); final long difference = cpuAfter - cpuBefore; assertTrue("The method isDate() is slower than expected. Actual CPU time spent: " + difference, difference < 20e8); }
From source file:org.talend.dataquality.statistics.datetime.PerformanceTest.java
@Test @Ignore/* ww w. j a v a 2 s . c o m*/ public void testGetPatterns() throws IOException { final InputStream stream = SystemDateTimePatternManager.class.getResourceAsStream("DateSampleTable.txt"); final List<String> lines = IOUtils.readLines(stream); SystemDateTimePatternManager.datePatternReplace("12/02/99");// init DateTimeFormatters final ThreadMXBean mxBean = ManagementFactory.getThreadMXBean(); final long cpuBefore = mxBean.getCurrentThreadCpuTime(); int count = 0; loop: for (int n = 0; n < REPLICATE; n++) { for (int i = 1; i < lines.size(); i++) { final String line = lines.get(i); if (!"".equals(line.trim())) { final String[] sampleLine = line.trim().split("\t"); final String sample = sampleLine[0]; SystemDateTimePatternManager.datePatternReplace(sample); count++; if (count > 100000) { break loop; } } } } final long cpuAfter = mxBean.getCurrentThreadCpuTime(); final long difference = cpuAfter - cpuBefore; assertTrue("The method getPatterns() is slower than expected. Actual CPU time spent: " + difference, difference < 25e8); }