List of usage examples for java.lang Runtime maxMemory
public native long maxMemory();
From source file:Main.java
public static void main(String[] args) { // print the maximum memory Runtime runTime = Runtime.getRuntime(); System.out.println(runTime.maxMemory()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Runtime runTime = Runtime.getRuntime(); long heapSize = runTime.totalMemory(); long heapMaxSize = runTime.maxMemory(); long heapFreeSize = runTime.freeMemory(); }
From source file:org.apache.ranger.policyengine.RangerPolicyenginePerfTester.java
public static void main(String[] args) { if (LOG.isDebugEnabled()) { LOG.debug("==> RangerPolicyenginePerfTester.main()"); }//from w w w . ja v a2s .co m CommandLineParser commandLineParser = new CommandLineParser(); PerfTestOptions perfTestOptions = commandLineParser.parse(args); if (perfTestOptions != null) { URL statCollectionFileURL = perfTestOptions.getStatCollectionFileURL(); List<String> perfModuleNames = statCollectionFileURL != null ? buildPerfModuleNames(statCollectionFileURL) : new ArrayList<String>(); PerfDataRecorder.initialize(perfModuleNames); URL servicePoliciesFileURL = perfTestOptions.getServicePoliciesFileURL(); RangerPolicyEngineOptions policyEngineOptions = new RangerPolicyEngineOptions(); policyEngineOptions.disableTagPolicyEvaluation = false; policyEngineOptions.evaluatorType = RangerPolicyEvaluator.EVALUATOR_TYPE_OPTIMIZED; policyEngineOptions.disableTrieLookupPrefilter = perfTestOptions.getIsTrieLookupPrefixDisabled(); PerfTestEngine perfTestEngine = new PerfTestEngine(servicePoliciesFileURL, policyEngineOptions, perfTestOptions.getIsDynamicReorderingDisabled()); if (!perfTestEngine.init()) { LOG.error("Error initializing test data. Existing..."); System.exit(1); } URL[] requestFileURLs = perfTestOptions.getRequestFileURLs(); int requestFilesCount = requestFileURLs.length; // warm-up policy engine LOG.error("Warming up.."); try { for (URL requestFileURL : requestFileURLs) { PerfTestClient perfTestClient = new PerfTestClient(perfTestEngine, 0, requestFileURL, 1); if (perfTestClient.init()) { perfTestClient.start(); perfTestClient.join(); } else { LOG.error("Error initializing warm-up PerfTestClient"); } } } catch (Throwable t) { LOG.error("Error during warmup", t); } LOG.error("Warmed up!"); PerfDataRecorder.clearStatistics(); int clientsCount = perfTestOptions.getConcurrentClientCount(); List<PerfTestClient> perfTestClients = new ArrayList<PerfTestClient>(clientsCount); for (int i = 0; i < clientsCount; i++) { URL requestFileURL = requestFileURLs[i % requestFilesCount]; PerfTestClient perfTestClient = new PerfTestClient(perfTestEngine, i, requestFileURL, perfTestOptions.getIterationsCount()); if (!perfTestClient.init()) { LOG.error("Error initializing PerfTestClient: (id=" + i + ")"); } else { perfTestClients.add(perfTestClient); } } if (LOG.isDebugEnabled()) { LOG.debug("Number of perfTestClients=" + perfTestClients.size()); } Runtime runtime = Runtime.getRuntime(); runtime.gc(); long totalMemory = runtime.totalMemory(); long freeMemory = runtime.freeMemory(); LOG.info("Memory stats: max-available=:" + runtime.maxMemory() + "; in-use=" + (totalMemory - freeMemory) + "; free=" + freeMemory); LOG.info("Starting " + perfTestClients.size() + " clients.."); for (PerfTestClient client : perfTestClients) { try { client.start(); } catch (Throwable t) { LOG.error("Error in starting client: " + client.getName(), t); } } LOG.info("Started " + perfTestClients.size() + " clients"); LOG.info("Waiting for " + perfTestClients.size() + " clients to finish up"); for (PerfTestClient client : perfTestClients) { while (client.isAlive()) { try { client.join(1000); runtime.gc(); totalMemory = runtime.totalMemory(); freeMemory = runtime.freeMemory(); LOG.info("Memory stats: max-available=:" + runtime.maxMemory() + "; in-use=" + (totalMemory - freeMemory) + "; free=" + freeMemory); } catch (InterruptedException interruptedException) { LOG.error("PerfTestClient.join() was interrupted"); } } } if (LOG.isDebugEnabled()) { LOG.debug("<== RangerPolicyenginePerfTester.main()"); } LOG.info("Completed performance-run"); perfTestEngine.cleanup(); PerfDataRecorder.printStatistics(); } LOG.info("Exiting..."); }
From source file:org.apache.ranger.policyengine.RangerPluginPerfTester.java
public static void main(String[] args) { if (!parseArguments(args)) { System.err.println("Exiting.. "); System.exit(-1);//from w ww. ja v a 2 s . co m } System.out.println("Arguments:"); System.out.println("\t\tservice-type:\t\t\t" + serviceType); System.out.println("\t\tservice-name:\t\t\t" + serviceName); System.out.println("\t\tapp-id:\t\t\t\t" + appId); System.out.println("\t\tranger-host:\t\t\t" + rangerHostName); System.out.println("\t\tsocket-read-timeout:\t\t" + socketReadTimeout); System.out.println("\t\tpolling-interval:\t\t" + pollingInterval); System.out.println("\t\tpolicy-cache-dir:\t\t" + policyCacheDir); System.out.println("\t\tuse-cached-policy-evaluator:\t" + useCachedPolicyEvaluator); System.out.println("\n\n"); Path filePath = buildConfigurationFile(); if (filePath != null) { RangerConfiguration rangerConfig = RangerConfiguration.getInstance(); rangerConfig.addResource(filePath); plugin = new RangerBasePlugin(serviceType, appId); Runtime runtime = Runtime.getRuntime(); runtime.gc(); long totalMemory = runtime.totalMemory(); long freeMemory = runtime.freeMemory(); System.out.println("Initial Memory Statistics:"); System.out.println("\t\tMaximum Memory available for the process:\t" + runtime.maxMemory()); System.out.println("\t\tInitial In-Use memory:\t\t\t\t" + (totalMemory - freeMemory)); System.out.println("\t\tInitial Free memory:\t\t\t\t" + freeMemory); System.out.println("\n\n"); plugin.init(); while (true) { runtime.gc(); freeMemory = runtime.freeMemory(); totalMemory = runtime.totalMemory(); System.out.println("Memory Statistics:"); System.out.println("\t\tCurrently In-Use memory:\t" + (totalMemory - freeMemory)); System.out.println("\t\tCurrently Free memory:\t\t" + freeMemory); System.out.println("\n\n"); try { Thread.sleep(60 * 1000); } catch (InterruptedException e) { System.err.println("Main thread interrupted..., exiting..."); break; } } } else { System.err.println("Failed to build configuration file"); } }
From source file:org.lenskit.cli.Main.java
public static void main(String[] args) { ArgumentParser parser = ArgumentParsers.newArgumentParser("lenskit") .description("Work with LensKit recommenders and data."); Logging.addLoggingGroup(parser);//ww w . j ava 2s . c o m Subparsers subparsers = parser.addSubparsers().metavar("COMMAND").title("commands"); ServiceLoader<Command> loader = ServiceLoader.load(Command.class); for (Command cmd : loader) { Subparser cp = subparsers.addParser(cmd.getName()).help(cmd.getHelp()).setDefault("command", cmd); cmd.configureArguments(cp); } try { Namespace options = parser.parseArgs(args); Logging.configureLogging(options); Runtime rt = Runtime.getRuntime(); logger.info("Starting LensKit {} on Java {} from {}", LenskitInfo.lenskitVersion(), SystemUtils.JAVA_VERSION, SystemUtils.JAVA_VENDOR); logger.debug("Built from Git revision {}", LenskitInfo.getHeadRevision()); logger.debug("Using VM '{}' version {} from {}", SystemUtils.JAVA_VM_NAME, SystemUtils.JAVA_VM_VERSION, SystemUtils.JAVA_VM_VENDOR); logger.info("Have {} processors and heap limit of {} MiB", rt.availableProcessors(), rt.maxMemory() >> 20); Command cmd = options.get("command"); cmd.execute(options); logger.info("If you use LensKit in published research, please see http://lenskit.org/research/"); } catch (ArgumentParserException e) { parser.handleError(e); System.exit(1); } catch (Exception e) { logger.error("error running command: " + e, e); System.exit(2); } }
From source file:com.aestel.chemistry.openEye.fp.Fingerprinter.java
public static void main(String... args) throws IOException { long start = System.currentTimeMillis(); long iCounter = 0; // create command line Options object Options options = new Options(); Option opt = new Option("in", true, "input file [.ism,.sdf,...]"); opt.setRequired(true);//from w w w. j a va2 s . c o m options.addOption(opt); opt = new Option("out", true, "output file .tsv or oe-supported"); opt.setRequired(true); options.addOption(opt); opt = new Option("idTag", true, "field with ID (default title)"); opt.setRequired(false); options.addOption(opt); opt = new Option("fpType", true, "fingerPrintType: maccs|linear7|linear7*4|HashLinear7*4\n" + " maccs: generate maccs keys\n" + " linear7 generate 7 bonds long linear fingerprints (210k known rest hashed)\n" + " linear7*4 linear 7 bonds if more than 4 atoms code atoms as * (5.1k known rest hashed)\n" + " HashLinear7*4: as linear7*4 but hashed to 16k"); opt.setRequired(true); options.addOption(opt); opt = new Option("format", true, "folded512|folded2048|bitList|fragList|none\n" + " folded512/2048: hex encoded 512/2048 bits\n" + " bitList: list of bitpositions\n" + " none: no fp output for use with writeCodeMap"); opt.setRequired(true); options.addOption(opt); opt = new Option("writeCodeMap", false, "Overwrite the codeMap file at the end of processing"); opt.setRequired(false); options.addOption(opt); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.err.println(e.getMessage()); exitWithHelp(options); } args = cmd.getArgs(); if (cmd.hasOption("d")) { System.err.println("Start debugger and press return:"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } String idTag = null; if (cmd.hasOption("idTag")) idTag = cmd.getOptionValue("idTag"); String outformat = cmd.getOptionValue("format").toLowerCase().intern(); if (args.length != 0) { exitWithHelp(options); } String type = cmd.getOptionValue("fpType"); boolean updateDictionaryFile = cmd.hasOption("writeCodeMap"); boolean hashUnknownFrag = true; if (type.equals("HashLinear7*4")) hashUnknownFrag = false; if (type.equals("maccs")) hashUnknownFrag = false; if (updateDictionaryFile) hashUnknownFrag = false; Fingerprinter fprinter = createFingerprinter(type, updateDictionaryFile, hashUnknownFrag); OEMolBase mol = new OEGraphMol(); String inFile = cmd.getOptionValue("in"); String outFile = cmd.getOptionValue("out"); oemolistream ifs = new oemolistream(inFile); Runtime rt = Runtime.getRuntime(); Outputter out; if (outFile.endsWith(".txt") || outFile.endsWith(".tab")) out = new TabOutputter(fprinter.getMapper(), outFile, outformat); else out = new OEOutputter(fprinter.getMapper(), outFile, type, outformat); while (oechem.OEReadMolecule(ifs, mol)) { iCounter++; Fingerprint fp = fprinter.getFingerprint(mol); String id; if (idTag == null) id = mol.GetTitle(); else id = oechem.OEGetSDData(mol, idTag); if (iCounter % 100 == 0) System.err.print("."); if (iCounter % 4000 == 0) { System.err.printf(" %d %dsec\tt=%d f=%d u=%d m=%d tf=%d\n", iCounter, (System.currentTimeMillis() - start) / 1000, rt.totalMemory() / 1024, rt.freeMemory() / 1024, (rt.totalMemory() - rt.freeMemory()) / 1024, rt.maxMemory() / 1024, (rt.freeMemory() + (rt.maxMemory() - rt.totalMemory())) / 1024); } out.output(id, mol, fp); } System.err.printf("Fingerprinter: Read %d structures in %d sec\n", iCounter, (System.currentTimeMillis() - start) / 1000); if (updateDictionaryFile) fprinter.writeDictionary(); out.close(); fprinter.close(); }
From source file:Main.java
/** * Determine the amount of available memory. "Available" memory is calculated as * <code>(max - total) + free</code>. * * @return the number of bytes of memory available according to the above algorithm. *///from ww w .j ava 2s . c o m public static long availableMemory() { Runtime rt = Runtime.getRuntime(); return rt.maxMemory() - rt.totalMemory() + rt.freeMemory(); }
From source file:MemoryUtils.java
static double maxMemory(Runtime runtime) { long maxMemory = runtime.maxMemory(); double memory = (double) maxMemory / (double) (1024 * 1024); return memory; }
From source file:org.codelibs.fess.util.MemoryUtil.java
public static String getMemoryUsageLog() { final Runtime runtime = Runtime.getRuntime(); final long freeBytes = runtime.freeMemory(); final long maxBytes = runtime.maxMemory(); final long totalBytes = runtime.totalMemory(); final long usedBytes = totalBytes - freeBytes; return "Mem:{used " + byteCountToDisplaySize(usedBytes) + ", heap " + byteCountToDisplaySize(totalBytes) + ", max " + byteCountToDisplaySize(maxBytes) + "}"; }
From source file:osmcb.program.EnvironmentSetup.java
public static void checkMemory() { Runtime r = Runtime.getRuntime(); long maxHeap = r.maxMemory(); String heapMBFormatted = String.format(Locale.ENGLISH, "%3.2f MiB", maxHeap / 1048576d); log.info("Total available memory to OSMCB: " + heapMBFormatted); if (maxHeap < 200000000) { String msg = String.format(OSMCBStrs.RStr("msg_environment_lack_memory"), heapMBFormatted); JOptionPane.showMessageDialog(null, msg, OSMCBStrs.RStr("msg_environment_lack_memory_title"), JOptionPane.WARNING_MESSAGE); }// w ww. j ava2 s .c om }