@Test public void testReport() throws UnsupportedEncodingException { Profiler profiler = new Profiler(); profiler.start(String.class); profiler.end(String.class); Profiler another = new Profiler(); another.start(Object.class); another.end(Object.class); ProfileSummary summary = new ProfileSummary(profiler, another); ByteArrayOutputStream byteArray = new ByteArrayOutputStream(); PrintStream stream = new PrintStream(byteArray); summary.report(new Profiler.ClassNameComparator(summary), (profile) -> true, stream); String report = byteArray.toString(StandardCharsets.UTF_8.name()); assertThat(report, containsString("Object")); assertThat(report, containsString("String")); }
public void report(Comparator<Class<?>> reportComparator, Predicate<Profile> filter, PrintStream stream) { stream.println("PROFILE REPORT"); try { TreeSet<Class<?>> treeSet = Arrays.stream(profilers) .map(Profiler::getTargetClasses) .flatMap(Set::stream) .collect(Collectors.toCollection(() -> new TreeSet<>(reportComparator))); stream.printf("%8s %8s %9s %s%n", "msecs", "#calls", "usecs/call", "Class"); for (Class<?> c : treeSet) { Profile p = getProfile(c); if (filter.test(p)) { long time = p.totalTime.get(); int callCount = p.totalCalls.get(); stream.printf("%8d %8d %8d %s%n", Long.valueOf(TimeUnit.MILLISECONDS.convert(time, TimeUnit.NANOSECONDS)), Integer.valueOf(callCount), Long.valueOf(TimeUnit.MICROSECONDS.convert(time / callCount, TimeUnit.NANOSECONDS)), c.getSimpleName()); } } stream.flush(); } catch (RuntimeException e) { LOG.error("Failed to print profile report.", e); } }
ProfileSummary implements IProfiler, XMLWriteable { public void report(Comparator<Class<?>> reportComparator, Predicate<Profile> filter, PrintStream stream) { stream.println("PROFILE REPORT"); try { TreeSet<Class<?>> treeSet = Arrays.stream(profilers) .map(Profiler::getTargetClasses) .flatMap(Set::stream) .collect(Collectors.toCollection(() -> new TreeSet<>(reportComparator))); stream.printf("%8s %8s %9s %s%n", "msecs", "#calls", "usecs/call", "Class"); for (Class<?> c : treeSet) { Profile p = getProfile(c); if (filter.test(p)) { long time = p.totalTime.get(); int callCount = p.totalCalls.get(); stream.printf("%8d %8d %8d %s%n", Long.valueOf(TimeUnit.MILLISECONDS.convert(time, TimeUnit.NANOSECONDS)), Integer.valueOf(callCount), Long.valueOf(TimeUnit.MICROSECONDS.convert(time / callCount, TimeUnit.NANOSECONDS)), c.getSimpleName()); } } stream.flush(); } catch (RuntimeException e) { LOG.error("Failed to print profile report.", e); } } }
ProfileSummary implements IProfiler, XMLWriteable { public void report(Comparator<Class<?>> reportComparator, Predicate<Profile> filter, PrintStream stream) { stream.println("PROFILE REPORT"); try { TreeSet<Class<?>> treeSet = Arrays.stream(profilers) .map(Profiler::getTargetClasses) .flatMap(Set::stream) .collect(Collectors.toCollection(() -> new TreeSet<>(reportComparator))); stream.printf("%8s %8s %9s %s%n", "msecs", "#calls", "usecs/call", "Class"); for (Class<?> c : treeSet) { Profile p = getProfile(c); if (filter.test(p)) { long time = p.totalTime.get(); int callCount = p.totalCalls.get(); stream.printf("%8d %8d %8d %s%n", Long.valueOf(TimeUnit.MILLISECONDS.convert(time, TimeUnit.NANOSECONDS)), Integer.valueOf(callCount), Long.valueOf(TimeUnit.MICROSECONDS.convert(time / callCount, TimeUnit.NANOSECONDS)), c.getSimpleName()); } } stream.flush(); } catch (RuntimeException e) { LOG.error("Failed to print profile report.", e); } } ProfileSummary(@NonNull Profiler... profilers); }
ProfileSummary implements IProfiler, XMLWriteable { public void report(Comparator<Class<?>> reportComparator, Predicate<Profile> filter, PrintStream stream) { stream.println("PROFILE REPORT"); try { TreeSet<Class<?>> treeSet = Arrays.stream(profilers) .map(Profiler::getTargetClasses) .flatMap(Set::stream) .collect(Collectors.toCollection(() -> new TreeSet<>(reportComparator))); stream.printf("%8s %8s %9s %s%n", "msecs", "#calls", "usecs/call", "Class"); for (Class<?> c : treeSet) { Profile p = getProfile(c); if (filter.test(p)) { long time = p.totalTime.get(); int callCount = p.totalCalls.get(); stream.printf("%8d %8d %8d %s%n", Long.valueOf(TimeUnit.MILLISECONDS.convert(time, TimeUnit.NANOSECONDS)), Integer.valueOf(callCount), Long.valueOf(TimeUnit.MICROSECONDS.convert(time / callCount, TimeUnit.NANOSECONDS)), c.getSimpleName()); } } stream.flush(); } catch (RuntimeException e) { LOG.error("Failed to print profile report.", e); } } ProfileSummary(@NonNull Profiler... profilers); void report(Comparator<Class<?>> reportComparator, Predicate<Profile> filter, PrintStream stream); @Override void writeXML(@NonNull XMLOutput xmlOutput); @Override Profile getProfile(Class<?> clazz); }
ProfileSummary implements IProfiler, XMLWriteable { public void report(Comparator<Class<?>> reportComparator, Predicate<Profile> filter, PrintStream stream) { stream.println("PROFILE REPORT"); try { TreeSet<Class<?>> treeSet = Arrays.stream(profilers) .map(Profiler::getTargetClasses) .flatMap(Set::stream) .collect(Collectors.toCollection(() -> new TreeSet<>(reportComparator))); stream.printf("%8s %8s %9s %s%n", "msecs", "#calls", "usecs/call", "Class"); for (Class<?> c : treeSet) { Profile p = getProfile(c); if (filter.test(p)) { long time = p.totalTime.get(); int callCount = p.totalCalls.get(); stream.printf("%8d %8d %8d %s%n", Long.valueOf(TimeUnit.MILLISECONDS.convert(time, TimeUnit.NANOSECONDS)), Integer.valueOf(callCount), Long.valueOf(TimeUnit.MICROSECONDS.convert(time / callCount, TimeUnit.NANOSECONDS)), c.getSimpleName()); } } stream.flush(); } catch (RuntimeException e) { LOG.error("Failed to print profile report.", e); } } ProfileSummary(@NonNull Profiler... profilers); void report(Comparator<Class<?>> reportComparator, Predicate<Profile> filter, PrintStream stream); @Override void writeXML(@NonNull XMLOutput xmlOutput); @Override Profile getProfile(Class<?> clazz);  }