@Override public long getSize() { return getEventFilesFromDisk() .collect(Collectors.summarizingLong(file -> file.length())) .getSum(); }
private void logTimingInfo(final AsyncClusterResponse response) { // Calculate min, max, mean for the requests final LongSummaryStatistics stats = response.getNodesInvolved().stream() .map(p -> response.getNodeResponse(p).getRequestDuration(TimeUnit.MILLISECONDS)) .collect(Collectors.summarizingLong(Long::longValue)); final StringBuilder sb = new StringBuilder(); sb.append("Node Responses for ").append(response.getMethod()).append(" ").append(response.getURIPath()).append(" (Request ID ").append(response.getRequestIdentifier()).append("):\n"); for (final NodeIdentifier node : response.getNodesInvolved()) { sb.append(node).append(": ").append(response.getNodeResponse(node).getRequestDuration(TimeUnit.MILLISECONDS)).append(" millis\n"); } logger.debug("For {} {} (Request ID {}), minimum response time = {}, max = {}, average = {} ms", response.getMethod(), response.getURIPath(), response.getRequestIdentifier(), stats.getMin(), stats.getMax(), stats.getAverage()); logger.debug(sb.toString()); }
default LongSummaryStatistics longStats(ToLongFunction<T> fn){ return stream().collect(Collectors.summarizingLong(fn)); } default IntSummaryStatistics intStats(ToIntFunction<T> fn){
/** * Logs information about the {@link TupleWindow}. * * @param window The tuple window. */ private void log(TupleWindow window) { // summarize the newly received tuples LongSummaryStatistics received = window.get() .stream() .map(tuple -> getField(TIMESTAMP_TUPLE_FIELD, tuple, Long.class)) .collect(Collectors.summarizingLong(Long::longValue)); LOG.debug("Tuple(s) received; count={}, min={}, max={}, range={} ms", received.getCount(), received.getMin(), received.getMax(), received.getMax() - received.getMin()); if (window.getExpired().size() > 0) { // summarize the expired tuples LongSummaryStatistics expired = window.getExpired() .stream() .map(tuple -> getField(TIMESTAMP_TUPLE_FIELD, tuple, Long.class)) .collect(Collectors.summarizingLong(Long::longValue)); LOG.debug("Tuple(s) expired; count={}, min={}, max={}, range={} ms, lag={} ms", expired.getCount(), expired.getMin(), expired.getMax(), expired.getMax() - expired.getMin(), received.getMin() - expired.getMin()); } }
public LongSummaryStatistics getStatistics() { return this.events.stream(). collect(Collectors.summarizingLong(TodoChangedEvent::getPriority)); } }
public LongSummaryStatistics getStatistics() { return this.events.stream(). collect(Collectors.summarizingLong(TodoServiceMethodInvokedEvent::getDuration)); } }
protected String getLongColumnSummary(TableModel model, int columnModel) { List<Long> values = new LinkedList<>(); for (int row = 0; row < model.getRowCount(); row++) { values.add((Long) model.getValueAt(row, columnModel)); } LongSummaryStatistics statistics = values.stream() .collect(Collectors.summarizingLong(Long::longValue)); return getSummary("integer", new SummaryStatistics(statistics)); }
public static void main(String[] args) throws Exception { // Warmup measure(); measure(); measure(); List<Long> timings = new ArrayList<>(); for (int i = 0; i < 9; i++) { timings.add(measure()); System.gc(); } System.out.println(timings.stream().collect(summarizingLong(x -> x))); }
/** * Verify if startStreamCut comes before endStreamCut. */ private void verifyStartAndEndStreamCuts(final StreamCut startStreamCut, final StreamCut endStreamCut) { final Map<Segment, Long> startPositions = startStreamCut.asImpl().getPositions(); final Map<Segment, Long> endPositions = endStreamCut.asImpl().getPositions(); //check offsets for overlapping segments. startPositions.keySet().stream().filter(endPositions::containsKey) .forEach(s -> Preconditions.checkArgument(startPositions.get(s) <= endPositions.get(s), "Segment offset in startStreamCut should be <= segment offset in endStreamCut.")); val fromSCSummary = startPositions.keySet() .stream().collect(summarizingLong(Segment::getSegmentId)); val toSCSummary = endPositions.keySet() .stream().collect(summarizingLong(Segment::getSegmentId)); Preconditions.checkArgument(fromSCSummary.getMin() <= toSCSummary.getMin(), "Start stream cut must precede end stream cut."); Preconditions.checkArgument(fromSCSummary.getMax() <= toSCSummary.getMax(), "Start stream cut must precede end stream cut."); }
default LongSummaryStatistics longStats(ToLongFunction<T> fn){ return stream().collect(Collectors.summarizingLong(fn)); } default IntSummaryStatistics intStats(ToIntFunction<T> fn){
.flatMap(Set::stream) .collect(groupingBy(Map.Entry::getKey, summarizingLong(entry -> ((Number) ((Map.Entry) entry).getValue()).longValue())));
private void go() throws Exception { List<Long> timings = new ArrayList<>(); try { setup(); // Warmup measure(); measure(); measure(); for (int i = 0; i < 9; i++) { timings.add(measure()); System.gc(); } } finally { Jet.shutdownAll(); } System.out.println(timings.stream().collect(summarizingLong(x -> x))); }
LongSummaryStatistics intSummaryStatistics = consumeTimes.stream().collect(Collectors.summarizingLong(value -> value));
LongSummaryStatistics intSummaryStatistics = consumeTimes.stream().collect(Collectors.summarizingLong(value -> value));
@Test public void distributionSummaries() { Registry r = newRegistry(true, 10000); r.distributionSummary("foo").record(1L); r.distributionSummary("foo", "a", "1", "b", "2").record(1L); r.distributionSummary("foo", "a", "1", "b", "3").record(13L); r.distributionSummary("foo", "a", "1", "b", "2").record(1L); r.distributionSummary("bar", "a", "1", "b", "2").record(1L); Assertions.assertEquals(4, r.distributionSummaries().count()); final LongSummaryStatistics countSummary = r.distributionSummaries() .filter(Functions.nameEquals("foo")) .collect(Collectors.summarizingLong(DistributionSummary::count)); Assertions.assertEquals(3L, countSummary.getCount()); Assertions.assertEquals(4L, countSummary.getSum()); Assertions.assertEquals(2L, countSummary.getMax()); final LongSummaryStatistics totalSummary = r.distributionSummaries() .filter(Functions.nameEquals("foo")) .collect(Collectors.summarizingLong(DistributionSummary::totalAmount)); Assertions.assertEquals(3L, totalSummary.getCount()); Assertions.assertEquals(16L, totalSummary.getSum()); Assertions.assertEquals(13L, totalSummary.getMax()); }
@Test public void timers() { Registry r = newRegistry(true, 10000); r.timer("foo").record(1L, TimeUnit.NANOSECONDS); r.timer("foo", "a", "1", "b", "2").record(1L, TimeUnit.NANOSECONDS); r.timer("foo", "a", "1", "b", "3").record(13L, TimeUnit.NANOSECONDS); r.timer("foo", "a", "1", "b", "2").record(1L, TimeUnit.NANOSECONDS); r.timer("bar", "a", "1", "b", "2").record(1L, TimeUnit.NANOSECONDS); Assertions.assertEquals(4, r.timers().count()); final LongSummaryStatistics countSummary = r.timers() .filter(Functions.nameEquals("foo")) .collect(Collectors.summarizingLong(Timer::count)); Assertions.assertEquals(3L, countSummary.getCount()); Assertions.assertEquals(4L, countSummary.getSum()); Assertions.assertEquals(2L, countSummary.getMax()); final LongSummaryStatistics totalSummary = r.timers() .filter(Functions.nameEquals("foo")) .collect(Collectors.summarizingLong(Timer::totalTime)); Assertions.assertEquals(3L, totalSummary.getCount()); Assertions.assertEquals(16L, totalSummary.getSum()); Assertions.assertEquals(13L, totalSummary.getMax()); }
@Test public void counters() { Registry r = newRegistry(true, 10000); r.counter("foo").increment(); r.counter("foo", "a", "1", "b", "2").increment(); r.counter("foo", "a", "1", "b", "3").increment(13L); r.counter("foo", "a", "1", "b", "2").increment(); r.counter("bar", "a", "1", "b", "2").increment(); Assertions.assertEquals(4, r.counters().count()); final LongSummaryStatistics summary = r.counters() .filter(Functions.nameEquals("foo")) .collect(Collectors.summarizingLong(Counter::count)); Assertions.assertEquals(3L, summary.getCount()); Assertions.assertEquals(16L, summary.getSum()); Assertions.assertEquals(13L, summary.getMax()); }