public static Optional<Double> bytesFor(String spec) { return convertBytes(Bytes.BYTE, spec); }
public static Optional<Double> doubleCountFor(String spec) { return convertDoubleCount(Count.UNIT, spec); }
public static Optional<Long> longCountFor(String spec) { spec = longConversions(spec); spec = spec.replace("MAX", String.valueOf(Long.MAX_VALUE)); try { long value = Long.parseLong(spec); return Optional.of(value); } catch (NumberFormatException ignored) { } return convertLongCount(Count.UNIT, spec); }
private void parseProgressSpec(String interval) { String[] parts = interval.split(":"); switch (parts.length) { case 2: intervalMillis = Unit.msFor(parts[1]).orElseThrow( () -> new RuntimeException("Unable to parse progress indicator indicatorSpec '" + parts[1] +"'") ); case 1: try { indicatorMode = IndicatorMode.valueOf(parts[0]); } catch (IllegalArgumentException ie) { throw new RuntimeException( "No such IndicatorMode exists for --progress: choose one of console or logonly." + " If you need to specify an interval such as 10m, then you must use --progress logonly:10m or --progress console:10m"); } break; default: throw new RuntimeException("This should never happen."); } }
public static Optional<Long> msFor(String duration) { return durationFor(Duration.MS, duration); }
public void setStartCycle(String startCycle) { setStartCycle(Unit.longCountFor(startCycle).orElseThrow( () -> new RuntimeException("Unable to convert start cycle '" + startCycle + "' to a value.") )); }
public RateSpec(String spec) { String[] specs = spec.split("[,:;]"); switch (specs.length) { case 3: verb = Verb.valueOf(specs[2].toLowerCase()); logger.debug("selected rate limiter type: " + verb); case 2: burstRatio = Double.valueOf(specs[1]); if (burstRatio < 1.0) { throw new RuntimeException("burst ratios less than 1.0 are invalid."); } case 1: opsPerSec = Unit.doubleCountFor(specs[0]).orElseThrow(() -> new RuntimeException("Unparsable:" + specs[0])); break; default: throw new RuntimeException("Rate specs must be either '<rate>' or '<rate>:<burstRatio>' as in 5000.0 or 5000.0:1.0"); } }
public static Optional<Long> convertLongCount(Count resultUnit, String spec) { spec = longConversions(spec); Matcher m = numberFmtPattern.matcher(spec); if (m.matches()) { String numberpart = m.group("number"); long base = Long.valueOf(numberpart); String unitpart = m.group("unit"); if (unitpart != null) { Count specifierUnit = Count.valueOfSuffix(unitpart); if (specifierUnit == null) { throw new RuntimeException("Unable to recognize counts unit:" + unitpart); } double specifierScale = specifierUnit.getMultiplier(); double resultScale = resultUnit.getMultiplier(); double multiplier = (specifierScale / resultScale); base *= multiplier; } return Optional.of(base); } else { logger.error("Parsing error for specifier:'" + spec + "'"); return Optional.empty(); } }
/** * Add a histogram interval logger to matching metrics in this JVM instance. * @param sessionName The name for the session to be annotated in the histogram log * @param pattern A regular expression pattern to filter out metric names for logging * @param filename A file to log the histogram data in * @param interval How many seconds to wait between writing each interval histogram */ public static void addHistoLogger(String sessionName, String pattern, String filename, String interval) { if (filename.contains("_SESSION_")) { filename = filename.replace("_SESSION_",sessionName); } Pattern compiledPattern = Pattern.compile(pattern); File logfile = new File(filename); long intervalMillis = Unit.msFor(interval).orElseThrow(()->new RuntimeException("Unable to parse interval spec:'" + interval + "'")); HistoIntervalLogger histoIntervalLogger = new HistoIntervalLogger(sessionName, logfile, compiledPattern, intervalMillis); logger.debug("attaching " + histoIntervalLogger + " to the metrics registry."); get().addListener(histoIntervalLogger); metricsCloseables.add(histoIntervalLogger); }
public static Optional<Long> microsecondsFor(String duration) { return durationFor(Duration.US, duration); }
public void setEndCycle(String endCycle) { setEndCycle(Unit.longCountFor(endCycle).orElseThrow( () -> new RuntimeException("Unable to convert end cycle '" + endCycle + "' to a value.") )); }
/** * Add a histogram stats logger to matching metrics in this JVM instance. * @param sessionName The name for the session to be annotated in the histogram log * @param pattern A regular expression pattern to filter out metric names for logging * @param filename A file to log the histogram data in * @param interval How many seconds to wait between writing each interval histogram */ public static void addStatsLogger(String sessionName, String pattern, String filename, String interval) { if (filename.contains("_SESSION_")) { filename = filename.replace("_SESSION_",sessionName); } Pattern compiledPattern = Pattern.compile(pattern); File logfile = new File(filename); long intervalMillis = Unit.msFor(interval).orElseThrow(() -> new RuntimeException("Unable to parse interval spec:" + interval + "'")); HistoStatsLogger histoStatsLogger = new HistoStatsLogger(sessionName, logfile, compiledPattern, intervalMillis, TimeUnit.NANOSECONDS); logger.debug("attaching " + histoStatsLogger + " to the metrics registry."); get().addListener(histoStatsLogger); metricsCloseables.add(histoStatsLogger); }
public static Optional<Long> nanosecondsFor(String duration) { return durationFor(Duration.NS, duration); }
/** * The last cycle that will be used for execution of this activity, inclusive. * * @return the long end cycle */ public long getEndCycle() { String cycles = parameterMap.getOptionalString(FIELD_CYCLES).orElse(DEFAULT_CYCLES); int rangeAt = cycles.indexOf(".."); String endCycle; if (rangeAt > 0) { endCycle = cycles.substring(rangeAt + 2); } else { endCycle = cycles; } return Unit.longCountFor(endCycle).orElseThrow( () -> new RuntimeException("Unable to convert end cycle from " + endCycle) ); }
/** * Add a classic histogram in addition to the default implementation in this runtime. This is a way to * get a view to both the enhanced histogram implementation as well as the classic implementation in the * same scenario. * @param sessionName The name of the session to be annotated in the classic histogram * @param pattern A regular expression pattern to filter out metric names for inclusion * @param prefix The name prefix to add to the classic histograms so that they fit into the existing metrics namespace * @param interval How frequently to update the histogram */ public static void addClassicHistos(String sessionName, String pattern, String prefix, String interval) { Pattern compiledPattern = Pattern.compile(pattern); long intervalMillis = Unit.msFor(interval).orElseThrow(() -> new RuntimeException("Unable to parse interval spec:" + interval + "'")); ClassicHistoListener classicHistoListener = new ClassicHistoListener(get(),sessionName, prefix, compiledPattern, interval, TimeUnit.NANOSECONDS); logger.debug("attaching histo listener " + classicHistoListener + " to the metrics registry."); get().addListener(classicHistoListener); ClassicTimerListener classicTimerListener = new ClassicTimerListener(get(),sessionName, prefix, compiledPattern, interval, TimeUnit.NANOSECONDS); logger.debug("attaching timer listener " + classicTimerListener + " to the metrics registry."); get().addListener(classicTimerListener); }
public static Optional<Long> secondsFor(String duration) { return durationFor(Duration.SECOND, duration); }
/** * The first cycle that will be used for execution of this activity, inclusive. * If the value is provided as a range as in 0..10, then the first number is the start cycle * and the second number is the end cycle +1. Effectively, cycle ranges * are [closed,open) intervals, as in [min..max) * * @return the long start cycle */ public long getStartCycle() { String cycles = parameterMap.getOptionalString("cycles").orElse(DEFAULT_CYCLES); int rangeAt = cycles.indexOf(".."); String startCycle; if (rangeAt > 0) { startCycle = cycles.substring(0, rangeAt); } else { startCycle = "0"; } return Unit.longCountFor(startCycle).orElseThrow( () -> new RuntimeException("Unable to parse start cycles from " + startCycle) ); }
public static Optional<Long> minutesFor(String duration) { return durationFor(Duration.MINUTE, duration); }