/** * Given milliseconds, return milliseconds, seconds, minutes, hours, days, or years as appropriate. Note that years is approximate since the logic always assumes there are * exactly 365 days per year. */ public static String getTime(long millis) { return getTime(millis, timeFormatter); }
protected void afterDump(MySqlDumpContext context, long elapsed, long lineCount, long skippedCount) { long length = context.getOutputFile().length(); String time = FormatUtils.getTime(elapsed); String size = FormatUtils.getSize(length); String rate = FormatUtils.getRate(elapsed, length); String lines = FormatUtils.getCount(lineCount); String skipped = FormatUtils.getCount(skippedCount); Object[] args = { time, size, rate, lines, skipped }; logger.info("Dump completed. [Time:{}, Size:{}, Rate:{}, Lines:{} Skipped:{}]", args); }
/** * Parse bytes from a size string that ends with a unit of measure. If no unit of measure is provided, bytes is assumed. Unit of measure is case insensitive. * * <pre> * 1 == 1 byte * 1b == 1 byte * 1k == 1 kilobyte == 1024 bytes == 1,024 bytes * 1m == 1 megabyte == 1024^2 bytes == 1,048,576 bytes * 1g == 1 gigabyte == 1024^3 bytes == 1,073,741,824 bytes * 1t == 1 terabyte == 1024^4 bytes == 1,099,511,627,776 bytes * 1p == 1 petabyte == 1024^5 bytes == 1,125,899,906,842,624 bytes * 1e == 1 exabyte == 1024^6 bytes == 1,152,921,504,606,846,976 bytes * </pre> */ public static long getBytes(String size) { return getBytes(size, SIZE_TOKENS, BASE); }
protected static void logCopy(String src, String dst, long elapsed) { String rate = ""; String size = ""; if (LocationUtils.isExistingFile(src)) { long bytes = new File(src).length(); rate = FormatUtils.getRate(elapsed, bytes); size = FormatUtils.getSize(bytes); } Object[] args = { dst, size, FormatUtils.getTime(elapsed), rate }; logger.debug("Source -> [{}]", src); logger.debug(" created [{}] - [{} {} {}]", args); }
protected void logStats(ThreadSafeListener listener, ExecutionStatistics stats, List<SqlBucket> buckets) { // Display thread related stats long aggregateTime = listener.getAggregateTime(); long wallTime = stats.getExecutionTime(); String avgMillis = FormatUtils.getTime(aggregateTime / buckets.size()); String aTime = FormatUtils.getTime(aggregateTime); String wTime = FormatUtils.getTime(wallTime); String sqlCount = FormatUtils.getCount(listener.getAggregateSqlCount()); String sqlSize = FormatUtils.getSize(listener.getAggregateSqlSize()); Object[] args = { buckets.size(), wTime, aTime, avgMillis, sqlCount, sqlSize }; logger.debug("Threads - [count: {} time: {} aggregate: {} avg: {} sql: {} - {}]", args); }
protected void showResult(ExecutionResult result) { String updates = FormatUtils.getCount(result.getUpdateCount()); String statements = FormatUtils.getCount(result.getStatementsExecuted()); String elapsed = FormatUtils.getTime(result.getElapsed()); Object[] args = { updates, statements, elapsed }; logger.info("Rows updated: {} SQL Statements: {} Total time: {}", args); }
/** * Show information about the transfer of data from a remote server */ protected void from(String absolutePath, CopyResult result) { if (context.isEcho()) { String elapsed = FormatUtils.getTime(result.getElapsedMillis()); String rate = FormatUtils.getRate(result.getElapsedMillis(), result.getAmountInBytes()); Object[] args = { absolutePath, elapsed, rate }; logger.info("copied <- [{}] - [{}, {}]", args); } }
/** * Given a number of bytes return bytes, kilobytes, megabytes, gigabytes, terabytes, petabytes, or exabytes as appropriate. */ public static String getSize(long bytes) { return getSize(bytes, (Size) null); }
/** * Return a formatted <code>count</code> representing the number of keys in the map */ public static String getCount(Map<?, ?> map) { return getCount(map.keySet()); }
/** * Given a number of bytes and the number of milliseconds it took to transfer that number of bytes, return bytes/s, KB/s, MB/s, GB/s, TB/s, PB/s, or EB/s as appropriate */ public static String getRate(long millis, long bytes) { return getRate(millis, bytes, rateFormatter); }
public Builder sleepInterval(String sleepInterval) { this.sleepIntervalMillis = getMillisAsInt(sleepInterval); return this; }
/** * Return a formatted date */ public static String getDate(long millis) { return getDate(new Date(millis)); }
public List<String[]> getRows(String bucket, List<BucketDeltaLine> deltaLines) { List<String[]> rows = new ArrayList<String[]>(); for (BucketDeltaLine deltaLine : deltaLines) { String files = FormatUtils.getCount(deltaLine.getFileDelta()); String size = FormatUtils.getSize(deltaLine.getByteDelta()); String start = shortDateFormatter.format(deltaLine.getStartDate()); String end = shortDateFormatter.format(deltaLine.getEndDate()); String interval = FormatUtils.getTime(deltaLine.getInterval()); String[] row = new String[] { bucket, files, size, start, end, interval }; rows.add(row); } return rows; }
protected String[] getPerDayRow(BucketDeltaSummary bds) { String perDay = "per day"; double days = bds.getInterval() / FormatUtils.DAY; String files = FormatUtils.getCount((long) (bds.getFileDelta() / days)); long byteDelta = bds.getByteDelta(); long bytesPerDay = (long) (byteDelta / days); String bytes = FormatUtils.getSize(bytesPerDay); return new String[] { perDay, files, bytes, "", "", "" }; }
@Override public void execute() { if (skip) { logger.info("Skipping execution"); return; } Assert.notNull(service, "service is null"); Assert.notNull(context, "context is null"); ExecutionResult result = service.executeSql(context); if (result.getStatementsExecuted() > 0) { String updates = FormatUtils.getCount(result.getUpdateCount()); String statements = FormatUtils.getCount(result.getStatementsExecuted()); String elapsed = FormatUtils.getTime(result.getElapsed()); Object[] args = { updates, statements, elapsed }; logger.info("Rows updated: {} SQL Statements: {} Total time: {}", args); } }
/** * Show information about the transfer of data to a remote server */ protected void to(RemoteFile destination, CopyResult result) { if (context.isEcho()) { String elapsed = FormatUtils.getTime(result.getElapsedMillis()); String rate = FormatUtils.getRate(result.getElapsedMillis(), result.getAmountInBytes()); Object[] args = { destination.getAbsolutePath(), elapsed, rate }; logger.info("created -> [{}] - [{}, {}]", args); } }
/** * Given a number of bytes return a string formatted into the unit of measure indicated */ public static String getSize(long bytes, NumberFormat formatter) { return getSize(bytes, null, formatter); }
/** * Return a formatted <code>count</code> representing the number of elements in the iterable */ public static String getCount(Iterable<?> iterable) { return getCount(Iterables.size(iterable)); }
public Builder overallTimeout(String overallTimeout) { this.overallTimeoutMillis = getMillisAsInt(overallTimeout); return this; }