List of usage examples for org.apache.commons.lang.time StopWatch StopWatch
public StopWatch()
Constructor.
From source file:de.unisb.cs.st.javalanche.mutation.util.DBPerformanceTest.java
private static void testWrite() { StopWatch stopWatch = new StopWatch(); stopWatch.start();/*ww w .j a v a 2 s . c o m*/ try { File file = new File("test.txt"); file.deleteOnExit(); FileWriter fw = new FileWriter(file); BufferedWriter w = new BufferedWriter(fw); for (int i = 0; i < 50 * 1024 * 1024; i++) { w.append('x'); } w.close(); } catch (IOException e) { e.printStackTrace(); } stopWatch.stop(); System.out.printf("Writing file took %s\n", DurationFormatUtils.formatDurationHMS(stopWatch.getTime())); }
From source file:com.qualogy.qafe.core.application.ApplicationContextLoader.java
public synchronized static void load(URI applicationFilePath, boolean validating) { logger.info("start application loading according to config file: [" + applicationFilePath + "]"); StopWatch watch = new StopWatch(); watch.start();// ww w . java 2 s .c o m ApplicationStack contexts = read(applicationFilePath, validating); load(contexts, applicationFilePath); watch.stop(); logger.info("done loading from [" + applicationFilePath + "] in " + watch.getTime() + "ms"); ApplicationCluster.getInstance().putAll(contexts); }
From source file:com.liferay.portlet.wiki.util.WikiCacheUtil.java
public static WikiPageDisplay getDisplay(long nodeId, String title, PortletURL viewPageURL, PortletURL editPageURL, String attachmentURLPrefix) { StopWatch stopWatch = null;// w ww.ja va2s .co m if (_log.isDebugEnabled()) { stopWatch = new StopWatch(); stopWatch.start(); } String key = _encodeKey(nodeId, title, viewPageURL.toString()); WikiPageDisplay pageDisplay = (WikiPageDisplay) _portalCache.get(key); if (pageDisplay == null) { pageDisplay = _getPageDisplay(nodeId, title, viewPageURL, editPageURL, attachmentURLPrefix); _portalCache.put(key, pageDisplay); } if (_log.isDebugEnabled()) { _log.debug("getDisplay for {" + nodeId + ", " + title + ", " + viewPageURL + ", " + editPageURL + "} takes " + stopWatch.getTime() + " ms"); } return pageDisplay; }
From source file:com.redhat.rhn.taskomatic.task.test.ErrataCacheTaskTest.java
public void aTestExecute() throws Exception { StopWatch sw = new StopWatch(); ErrataCacheTask ect = new ErrataCacheTask(); sw.start();//w w w .jav a2 s . c o m ect.execute(null); sw.stop(); System.out.println("ErrataCacheTask took [" + sw.getTime() + "]"); }
From source file:com.icantrap.collections.dawg.TrieValidationTest.java
@Before public void before() throws IOException { assumeThat(System.getProperty("RUN_VALIDATION"), is("on")); LineIterator iter = IOUtils.lineIterator(getClass().getResourceAsStream("/TWL06.txt"), null); dawgBuilder = new DawgBuilder(); while (iter.hasNext()) dawgBuilder.add(iter.next());/*from w w w.j av a2 s. c o m*/ LineIterator.closeQuietly(iter); System.out.println("Uncompressed: " + dawgBuilder.nodeCount() + " nodes"); StopWatch stopWatch = new StopWatch(); stopWatch.start(); dawgBuilder.build(); stopWatch.stop(); System.out.println("Time to compress: " + stopWatch.getTime() + " ms."); System.out.println("Compressed: " + dawgBuilder.nodeCount() + " nodes"); }
From source file:com.liferay.wiki.util.WikiCacheUtil.java
public static WikiPageDisplay getDisplay(long nodeId, String title, PortletURL viewPageURL, PortletURL editPageURL, String attachmentURLPrefix) { StopWatch stopWatch = new StopWatch(); stopWatch.start();// w ww . j a v a 2 s . c om String key = _encodeKey(nodeId, title, viewPageURL.toString()); WikiPageDisplay pageDisplay = (WikiPageDisplay) _portalCache.get(key); if (pageDisplay == null) { pageDisplay = _getPageDisplay(nodeId, title, viewPageURL, editPageURL, attachmentURLPrefix); if (pageDisplay != null) { PortalCacheHelperUtil.putWithoutReplicator(_portalCache, key, pageDisplay); } } if (_log.isDebugEnabled()) { _log.debug(StringBundler.concat("getDisplay for {", String.valueOf(nodeId), ", ", title, ", ", String.valueOf(viewPageURL), ", ", String.valueOf(editPageURL), "} takes ", String.valueOf(stopWatch.getTime()), " ms")); } return pageDisplay; }
From source file:com.liferay.portal.convert.ConvertProcess.java
public void convert() throws ConvertException { try {/*from w w w . j a va 2 s.co m*/ if (getPath() != null) { return; } StopWatch stopWatch = null; if (_log.isInfoEnabled()) { stopWatch = new StopWatch(); stopWatch.start(); _log.info("Starting conversion for " + getClass().getName()); } doConvert(); if (_log.isInfoEnabled()) { _log.info("Finished conversion for " + getClass().getName() + " in " + stopWatch.getTime() + " ms"); } } catch (Exception e) { throw new ConvertException(e); } finally { setParameterValues(null); MaintenanceUtil.cancel(); } }
From source file:dataform.components.WorkTimer.java
public void reset() { stopWatch.stop(); stopWatch = new StopWatch(); stopWatch.start(); }
From source file:fr.inria.edelweiss.kgdqp.core.CentralizedInferrencingNoSpin.java
public static void main(String args[]) throws ParseException, EngineException, InterruptedException, IOException, LoadException { List<String> endpoints = new ArrayList<String>(); String queryPath = null;// w ww .j av a2s. c o m boolean rulesSelection = false; File rulesDir = null; File ontDir = null; ///////////////// Graph graph = Graph.create(); QueryProcess exec = QueryProcess.create(graph); Options options = new Options(); Option helpOpt = new Option("h", "help", false, "print this message"); // Option queryOpt = new Option("q", "query", true, "specify the sparql query file"); // Option endpointOpt = new Option("e", "endpoint", true, "a federated sparql endpoint URL"); Option versionOpt = new Option("v", "version", false, "print the version information and exit"); Option rulesOpt = new Option("r", "rulesDir", true, "directory containing the inference rules"); Option ontOpt = new Option("o", "ontologiesDir", true, "directory containing the ontologies for rules selection"); // Option locOpt = new Option("c", "centralized", false, "performs centralized inferences"); Option dataOpt = new Option("l", "load", true, "data file or directory to be loaded"); // Option selOpt = new Option("s", "rulesSelection", false, "if set to true, only the applicable rules are run"); // options.addOption(queryOpt); // options.addOption(endpointOpt); options.addOption(helpOpt); options.addOption(versionOpt); options.addOption(rulesOpt); options.addOption(ontOpt); // options.addOption(selOpt); // options.addOption(locOpt); options.addOption(dataOpt); String header = "Corese/KGRAM rule engine experiment command line interface"; String footer = "\nPlease report any issue to alban.gaignard@cnrs.fr, olivier.corby@inria.fr"; CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("kgdqp", header, options, footer, true); System.exit(0); } if (cmd.hasOption("o")) { rulesSelection = true; String ontDirPath = cmd.getOptionValue("o"); ontDir = new File(ontDirPath); if (!ontDir.isDirectory()) { logger.warn(ontDirPath + " is not a valid directory path."); System.exit(0); } } if (!cmd.hasOption("r")) { logger.info("You must specify a path for inference rules directory !"); System.exit(0); } if (cmd.hasOption("l")) { String[] dataPaths = cmd.getOptionValues("l"); for (String path : dataPaths) { Load ld = Load.create(graph); ld.load(path); logger.info("Loaded " + path); } } if (cmd.hasOption("v")) { logger.info("version 3.0.4-SNAPSHOT"); System.exit(0); } String rulesDirPath = cmd.getOptionValue("r"); rulesDir = new File(rulesDirPath); if (!rulesDir.isDirectory()) { logger.warn(rulesDirPath + " is not a valid directory path."); System.exit(0); } // Local rules graph initialization Graph rulesG = Graph.create(); Load ld = Load.create(rulesG); if (rulesSelection) { // Ontology loading if (ontDir.isDirectory()) { for (File o : ontDir.listFiles()) { logger.info("Loading " + o.getAbsolutePath()); ld.load(o.getAbsolutePath()); } } } // Rules loading if (rulesDir.isDirectory()) { for (File r : rulesDir.listFiles()) { if (r.getAbsolutePath().endsWith(".rq")) { logger.info("Loading " + r.getAbsolutePath()); // ld.load(r.getAbsolutePath()); // byte[] encoded = Files.readAllBytes(Paths.get(r.getAbsolutePath())); // String construct = new String(encoded, "UTF-8"); //StandardCharsets.UTF_8); FileInputStream f = new FileInputStream(r); QueryLoad ql = QueryLoad.create(); String construct = ql.read(f); f.close(); SPINProcess sp = SPINProcess.create(); String spinConstruct = sp.toSpin(construct); ld.load(new ByteArrayInputStream(spinConstruct.getBytes()), Load.TURTLE_FORMAT); logger.info("Rules graph size : " + rulesG.size()); } } } // Rule engine initialization RuleEngine ruleEngine = RuleEngine.create(graph); ruleEngine.set(exec); ruleEngine.setOptimize(true); ruleEngine.setConstructResult(true); ruleEngine.setTrace(true); StopWatch sw = new StopWatch(); logger.info("Federated graph size : " + graph.size()); logger.info("Rules graph size : " + rulesG.size()); // Rule selection logger.info("Rules selection"); QueryProcess localKgram = QueryProcess.create(rulesG); ArrayList<String> applicableRules = new ArrayList<String>(); sw.start(); String rulesSelQuery = ""; if (rulesSelection) { rulesSelQuery = pertinentRulesQuery; } else { rulesSelQuery = allRulesQuery; } Mappings maps = localKgram.query(rulesSelQuery); logger.info("Rules selected in " + sw.getTime() + " ms"); logger.info("Applicable rules : " + maps.size()); // Selected rule loading for (Mapping map : maps) { IDatatype dt = (IDatatype) map.getValue("?res"); String rule = dt.getLabel(); //loading rule in the rule engine // logger.info("Adding rule : "); // System.out.println("-------"); // System.out.println(rule); // System.out.println(""); // if (! rule.toLowerCase().contains("sameas")) { applicableRules.add(rule); ruleEngine.addRule(rule); // } } // Rules application on distributed sparql endpoints logger.info("Rules application (" + applicableRules.size() + " rules)"); ExecutorService threadPool = Executors.newCachedThreadPool(); RuleEngineThread ruleThread = new RuleEngineThread(ruleEngine); sw.reset(); sw.start(); // ruleEngine.process(); threadPool.execute(ruleThread); threadPool.shutdown(); //monitoring loop while (!threadPool.isTerminated()) { // System.out.println("******************************"); // System.out.println(Util.jsonDqpCost(QueryProcessDQP.queryCounter, QueryProcessDQP.queryVolumeCounter, QueryProcessDQP.sourceCounter, QueryProcessDQP.sourceVolumeCounter)); // System.out.println("Rule engine running for " + sw.getTime() + " ms"); // System.out.println("Federated graph size : " + graph.size()); System.out.println(sw.getTime() + " , " + graph.size()); Thread.sleep(5000); } logger.info("Federated graph size : " + graph.size()); // logger.info(Util.jsonDqpCost(QueryProcessDQP.queryCounter, QueryProcessDQP.queryVolumeCounter, QueryProcessDQP.sourceCounter, QueryProcessDQP.sourceVolumeCounter)); // TripleFormat f = TripleFormat.create(graph, true); // f.write("/tmp/gAll.ttl"); }
From source file:com.liferay.portal.util.InitUtil.java
public static synchronized void init() { if (_initialized) { return;/* w w w . ja v a 2 s . c om*/ } StopWatch stopWatch = null; if (_PRINT_TIME) { stopWatch = new StopWatch(); stopWatch.start(); } // Set the default locale used by Liferay. This locale is no longer set // at the VM level. See LEP-2584. String userLanguage = SystemProperties.get("user.language"); String userCountry = SystemProperties.get("user.country"); String userVariant = SystemProperties.get("user.variant"); LocaleUtil.setDefault(userLanguage, userCountry, userVariant); // Set the default time zone used by Liferay. This time zone is no // longer set at the VM level. See LEP-2584. String userTimeZone = SystemProperties.get("user.timezone"); TimeZoneUtil.setDefault(userTimeZone); // Shared class loader try { Thread currentThread = Thread.currentThread(); PortalClassLoaderUtil.setClassLoader(currentThread.getContextClassLoader()); } catch (Exception e) { e.printStackTrace(); } // Log4J if (GetterUtil.getBoolean(SystemProperties.get("log4j.configure.on.startup"), true)) { ClassLoader classLoader = InitUtil.class.getClassLoader(); Log4JUtil.configureLog4J(classLoader.getResource("META-INF/portal-log4j.xml")); try { Log _log = LogFactoryUtil.getLog(InitUtil.class); String configName = "META-INF/portal-log4j-ext.xml"; Enumeration<URL> configs = classLoader.getResources(configName); if (_log.isDebugEnabled() && !configs.hasMoreElements()) { _log.debug("No " + configName + " has been found"); } while (configs.hasMoreElements()) { URL config = configs.nextElement(); Log4JUtil.configureLog4J(config); } } catch (Exception e) { e.printStackTrace(); } } // Shared log try { LogFactoryUtil.setLogFactory(new Log4jLogFactoryImpl()); } catch (Exception e) { e.printStackTrace(); } // Cache registry CacheRegistryUtil.setCacheRegistry(new CacheRegistryImpl()); // Configuration factory ConfigurationFactoryUtil.setConfigurationFactory(new ConfigurationFactoryImpl()); // Data source factory DataSourceFactoryUtil.setDataSourceFactory(new DataSourceFactoryImpl()); // DB factory DBFactoryUtil.setDBFactory(new DBFactoryImpl()); // Java properties JavaProps.isJDK5(); // ROME XmlReader.setDefaultEncoding(StringPool.UTF8); if (_PRINT_TIME) { System.out.println("InitAction takes " + stopWatch.getTime() + " ms"); } _initialized = true; }