/** * 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); }
/** * 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); }
@Override public String toString() { return format("%s - %s", FormatUtils.getCount(count), FormatUtils.getSize(size)); }
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); }
@Override public void bucketsCreated(BucketEvent event) { List<SqlBucket> buckets = event.getBuckets(); List<Object[]> argsList = new ArrayList<Object[]>(); for (int i = 0; i < buckets.size(); i++) { SqlBucket bucket = buckets.get(i); List<SqlSupplier> suppliers = bucket.getSuppliers(); String count = FormatUtils.getCount(JdbcUtils.getSqlCount(suppliers)); String srcs = FormatUtils.getCount(suppliers.size()); String size = FormatUtils.getSize(JdbcUtils.getSqlSize(suppliers)); Object[] args = { i + 1, count, srcs, size }; argsList.add(args); } List<String> columns = Arrays.asList("Bucket", "SQL Count", "Sources", "Size"); LoggerUtils.logTable(columns, argsList, level, logger); }
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); }
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; }
public String toString(AccountDeltaSummary summary) { List<String[]> rows = new ArrayList<String[]>(); for (BucketDeltaSummary bds : summary.getBucketDeltaSummaries()) { rows.addAll(getRows(bds.getBucket(), bds.getDeltaLines())); String files = FormatUtils.getCount(bds.getFileDelta()); String bytes = FormatUtils.getSize(bds.getByteDelta()); String start = shortDateFormatter.format(bds.getStartDate()); String end = shortDateFormatter.format(bds.getEndDate()); String interval = FormatUtils.getTime(bds.getInterval()); rows.add(new String[] { "", "", "", "", "", "" }); rows.add(new String[] { "totals", files, bytes, start, end, interval }); rows.add(getPerDayRow(bds)); rows.add(new String[] { "", "", "", "", "", "" }); rows.add(new String[] { "", "", "", "", "", "" }); } List<String> columns = new ArrayList<String>(); columns.add("bucket"); columns.add("files"); columns.add("size"); columns.add("start"); columns.add("end"); columns.add("interval"); return S3Utils.getInstance().toString(columns, rows); }
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 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, "", "", "" }; }
public String toString(AccountSummary summary) { List<String> columns = getBucketSummaryColumns(); List<String[]> rows = getRows(summary.getBucketSummaries()); // Add a blank row for spacing rows.add(new String[] { "", "", "" }); // Add a row showing total count and size String count = FormatUtils.getCount(summary.getCount()); String size = FormatUtils.getSize(summary.getSize()); rows.add(new String[] { "Totals", count, size }); // Convert the rows to a string and return return toString(columns, rows); }
public void summarize(BucketPrefixSummary summary, List<S3ObjectSummary> summaries) { for (S3ObjectSummary element : summaries) { summary.setSize(summary.getSize() + element.getSize()); summary.setCount(summary.getCount() + 1); if (log.isDebugEnabled()) { log.debug(summary.getCount() + " - " + element.getKey() + " - " + FormatUtils.getSize(element.getSize())); } } if (log.isDebugEnabled()) { String prefix = summary.getPrefix(); long count = summary.getCount(); long bytes = summary.getSize(); log.debug(rpad(prefix, 40) + " Total Count: " + lpad(count + "", 3) + " Total Size: " + lpad(FormatUtils.getSize(bytes), 9)); } }
public List<BucketDisplay> getBucketDisplayList(List<BucketPrefixSummary> summaries, Size size) { List<BucketDisplay> list = new ArrayList<BucketDisplay>(); for (BucketPrefixSummary summary : summaries) { BucketDisplay display = new BucketDisplay(); display.setPrefix(summary.getPrefix() == null ? "/" : summary.getPrefix()); display.setCount(summary.getCount()); display.setSize(FormatUtils.getSize(summary.getSize(), size)); list.add(display); } return list; }
protected String[] getRow(BucketSummary summary) { String[] row = new String[3]; row[0] = summary.getBucket().getName(); row[1] = FormatUtils.getCount(summary.getCount()); row[2] = FormatUtils.getSize(summary.getSize()); return row; }
@Override public void afterMetaData(SqlMetaDataEvent event) { this.count = JdbcUtils.getSqlCount(event.getContext().getSuppliers()); this.size = JdbcUtils.getSqlSize(event.getContext().getSuppliers()); String count = FormatUtils.getCount(this.count); String sources = FormatUtils.getCount(event.getContext().getSuppliers().size()); String size = FormatUtils.getSize(this.size); Object[] args = { count, sources, size }; LoggerUtils.logMsg("Executing - [SQL Count: {} Sources: {} Size: {}]", args, logger, loggerLevel); }
@Override public void afterMetaData(SqlMetaDataEvent event) { this.count = JdbcUtils.getSqlCount(event.getContext().getSuppliers()); this.size = JdbcUtils.getSqlSize(event.getContext().getSuppliers()); String count = FormatUtils.getCount(this.count); String sources = FormatUtils.getCount(event.getContext().getSuppliers().size()); String size = FormatUtils.getSize(this.size); Object[] args = { label, count, sources, size }; LoggerUtils.logMsg("Executing - [{}: {} Sources: {} Size: {}]", args, logger, loggerLevel); }
@Override public void afterExecution(SqlExecutionEvent event) { long elapsed = event.getStopTimeMillis() - event.getStartTimeMillis(); String count = FormatUtils.getCount(this.count); String sources = FormatUtils.getCount(event.getContext().getSuppliers().size()); String size = FormatUtils.getSize(this.size); String time = FormatUtils.getTime(elapsed); String rate = FormatUtils.getRate(elapsed, this.size); String throughput = FormatUtils.getThroughputInSeconds(elapsed, this.count, "SQL/s"); Object[] args = { count, sources, size, time, throughput, rate }; if (showRate) { LoggerUtils.logMsg("Completed - [SQL Count: {} Sources: {} Size: {} Time: {} Throughput: {} Rate: {}]", args, logger, loggerLevel); } else { LoggerUtils.logMsg("Completed - [SQL Count: {} Sources: {} Size: {} Time: {} Throughput: {}]", args, logger, loggerLevel); } }
@Override public void afterExecution(SqlExecutionEvent event) { long elapsed = event.getStopTimeMillis() - event.getStartTimeMillis(); String count = FormatUtils.getCount(this.count); String sources = FormatUtils.getCount(event.getContext().getSuppliers().size()); String size = FormatUtils.getSize(this.size); String time = FormatUtils.getTime(elapsed); String rate = FormatUtils.getRate(elapsed, this.size); String throughput = FormatUtils.getThroughputInSeconds(elapsed, this.count, throughputLabel); Object[] args = { label, count, sources, size, time, throughput, rate }; if (showRate) { LoggerUtils.logMsg("Completed - [{}: {} Sources: {} Size: {} Time: {} Throughput: {} Rate: {}]", args, logger, loggerLevel); } else { LoggerUtils.logMsg("Completed - [{}: {} Sources: {} Size: {} Time: {} Throughput: {}]", args, logger, loggerLevel); } }
String wTime = FormatUtils.getTime(wallTime); String sqlCount = FormatUtils.getCount(etl.getAggregateSqlCount()); String sqlSize = FormatUtils.getSize(etl.getAggregateSqlSize()); Object[] args = { buckets.size(), wTime, aTime, avgMillis, sqlCount, sqlSize }; logger.debug("Threads - [count: {} time: {} aggregate: {} avg: {} sql: {} - {}]", args);