private void parseParameters(Output output, String param) { if ("enable".equalsIgnoreCase(param) || "+".equalsIgnoreCase(param)) { enableTiming(output); } else if ("disable".equalsIgnoreCase(param) || "-".equalsIgnoreCase(param)) { disableTiming(output); } else { output.line("Usage: timing enable|disable (You can use + and - for enable/disable)."); output.line("To enable tracing: timing trace <filter-expression>"); } }
private void disableTiming(Output output) { generateOutput(output); Microtiming.setEnabled(false); output.line("Disabling Microtiming..."); }
@Override public void execute(Output output, String... params) { if (params.length == 2) { output.apply("Setting %s to: %s", params[0], params[1]); Log.setLevel(params[0], Level.toLevel(params[1])); output.blankLine(); } else { output.line("Usage: logger <name> <LEVEL>"); output.blankLine(); output.line("Known loggers:"); output.separator(); for (Log l : Log.getAllLoggers()) { output.line(l.getName()); } output.separator(); } }
@Override public void execute(Output output, String... params) throws Exception { output.blankLine(); output.apply("C O N S O L E - %s", Product.getProduct()); output.blankLine(); output.apply("%-20s %s", "CMD", "DESCRIPTION"); output.separator(); List<Command> parts = new ArrayList<>(ctx.getParts(Command.class)); parts.sort(Comparator.comparing(Command::getName)); for (Command cmd : parts) { output.apply("%-20s %s", cmd.getName(), cmd.getDescription()); } output.separator(); }
@Override public void execute(Output output, String... params) throws Exception { boolean withTraces = Value.indexOf(0, params).isFilled(); boolean includeWaiting = "Y".equals(Value.indexOf(1, params).asString()); if (withTraces) { outputThreadInfos(output, includeWaiting, params[0]); } else { output.line("Usage: threads [<filter> (or 'all')] [Y=include WAITING/NATIVE]"); output.separator(); output.apply("%-15s %10s %53s", "STATE", "ID", "NAME"); output.separator(); for (ThreadInfo info : t.dumpAllThreads(false, false)) { output.apply("%-15s %10s %53s", info.isInNative() ? "NATIVE" : info.getThreadState().name(), info.getThreadId(), info.getThreadName()); } output.separator(); } }
@Override public void execute(Output output, String... params) throws Exception { output.line(Product.getProduct().toString()); output.blankLine(); output.line("MODULES"); output.separator(); output.blankLine(); Product.getModules().forEach(m -> { output.line(m.getName()); output.line(m.getDetails()); output.blankLine(); }); output.separator(); }
@Override public void execute(Output output, String... params) throws Exception { output.apply("%-8s %-30s %15s", "STATE", "NAME", "VALUE"); output.separator(); for (Metric metric : metrics.getMetrics()) { output.apply("%-8s %-30s %15s", metric.getState(), metric.getLabel(), metric.getValueAsString()); } output.separator(); }
private void outputMappingRow(Output output, Map.Entry<String, Object> e) { if (e.getValue() instanceof Map) { output.line(e.getKey()); for (Map.Entry<?, ?> subEntry : ((Map<?, ?>) e.getValue()).entrySet()) { output.line(" " + subEntry.getKey() + ": " + subEntry.getValue()); } } else { output.line(e.getKey() + ": " + e.getValue()); } }
@Override public void execute(Output output, String... params) throws Exception { if (params.length == 1 && Strings.isFilled(params[0])) { parseParameters(output, params[0]); } else { if (Microtiming.isEnabled()) { generateOutput(output); } else { output.line("Microtiming is disabled! Use: 'timing +' to enable."); } } }
private void outputThreadInfos(Output output, boolean includeWaiting, String threadName) { for (Map.Entry<Thread, StackTraceElement[]> thread : Thread.getAllStackTraces().entrySet()) { outputThreadInfo(output, includeWaiting, threadName, thread); } }
@Override public void execute(Output output, String... params) { if (params.length > 0) { for (Cache<?, ?> c : CacheManager.getCaches()) { if (Value.indexOf(0, params).asString().equals(c.getName())) { output.apply("Flushing: %s", params[0]); c.clear(); } } } else { output.line("Use cache <name> to flush the given cache..."); } output.blankLine(); output.apply("%-53s %8s %8s %8s", "NAME", "SIZE", "MAX-SIZE", "HIT-RATE"); output.separator(); for (Cache<?, ?> c : CacheManager.getCaches()) { output.apply("%-53s %8d %8d %8d", c.getName(), c.getSize(), c.getMaxSize(), c.getHitRate()); } output.separator(); }
@Override @SuppressWarnings("squid:S1215") @Explain("The whole purpose of this call is to invoke the garbage collector.") public void execute(Output output, String... params) throws Exception { output.apply(LINE_FORMAT, "TYPE", "SIZE"); output.separator(); output.apply(LINE_FORMAT, "Free", NLS.formatSize(Runtime.getRuntime().freeMemory())); output.apply(LINE_FORMAT, "Total", NLS.formatSize(Runtime.getRuntime().totalMemory())); output.apply(LINE_FORMAT, "Max", NLS.formatSize(Runtime.getRuntime().maxMemory())); Runtime.getRuntime().gc(); output.separator(); output.apply(LINE_FORMAT, "Free", NLS.formatSize(Runtime.getRuntime().freeMemory())); output.apply(LINE_FORMAT, "Total", NLS.formatSize(Runtime.getRuntime().totalMemory())); output.apply(LINE_FORMAT, "Max", NLS.formatSize(Runtime.getRuntime().maxMemory())); output.separator(); }
@Override public void execute(Output output, String... params) throws Exception { if (params.length < 1) { output.line("Usage: md5 <input>"); } else { output.line("Input: " + params[0]); output.line("Timestamp: " + System.currentTimeMillis() / 1000); output.line("MD5: " + Hashing.md5().hashString(params[0], Charsets.UTF_8).toString()); } }
private void enableTiming(Output output) { if (Microtiming.isEnabled()) { generateOutput(output); Microtiming.setEnabled(false); output.line("Resetting Microtiming..."); } else { output.line("Enabling Microtiming..."); } Microtiming.setEnabled(true); }
private static void reportUnknownType(Output output, String typeName) { output.line("Unknown type: " + typeName); Monoflop mf = Monoflop.create(); for (String name : index.getSchema().getTypeNames()) { if (name.toLowerCase().contains(typeName.toLowerCase())) { if (mf.firstCall()) { output.line("Did you mean one of those: "); } output.line(" * " + name); } } }
private void outputMapping(Output output, ImmutableOpenMap<String, MappingMetaData> c) throws IOException { Iterator<String> iter = c.keysIt(); while (iter.hasNext()) { String property = iter.next(); MappingMetaData md = c.get(property); output.line("routing: " + md.routing().toString()); for (Map.Entry<String, Object> e : md.getSourceAsMap().entrySet()) { outputMappingRow(output, e); } } }