@Test public void testWriteXML() throws IOException { Profiler profiler = new Profiler(); Profiler another = new Profiler(); profiler.start(String.class); another.start(Object.class); try { Thread.sleep(32); } catch (InterruptedException e) { throw new RuntimeException(e); } profiler.end(String.class); another.end(Object.class); ProfileSummary summary = new ProfileSummary(profiler, another); ByteArrayOutputStream byteArray = new ByteArrayOutputStream(); XMLOutput output = new OutputStreamXMLOutput(byteArray); summary.writeXML(output); output.finish(); String xml = byteArray.toString(StandardCharsets.UTF_8.name()); assertThat(xml, containsString("name=\"java.lang.Object\"")); assertThat(xml, containsString("name=\"java.lang.String\"")); }
@Override public void writeXML(@NonNull XMLOutput xmlOutput) throws IOException { xmlOutput.startTag("FindBugsProfile"); xmlOutput.stopTag(false); Comparator<Class<?>> reportComparator = new Profiler.TotalTimeComparator(this); TreeSet<Class<?>> treeSet = Arrays.stream(profilers) .map(Profiler::getTargetClasses) .flatMap(Set::stream) .collect(Collectors.toCollection(() -> new TreeSet<>(reportComparator))); long totalTime = Arrays.stream(profilers) .map(Profiler::getProfiles) .flatMap(Collection::stream) .mapToLong(Profiler.Profile::getTotalTime) .sum(); long accumulatedTime = 0; for (Class<?> c : treeSet) { Profile p = getProfile(c); p.writeXML(xmlOutput); accumulatedTime += p.getTotalTime(); if (accumulatedTime > 3 * totalTime / 4) { break; } } xmlOutput.closeTag("FindBugsProfile"); }
ProfileSummary implements IProfiler, XMLWriteable { @Override public void writeXML(@NonNull XMLOutput xmlOutput) throws IOException { xmlOutput.startTag("FindBugsProfile"); xmlOutput.stopTag(false); Comparator<Class<?>> reportComparator = new Profiler.TotalTimeComparator(this); TreeSet<Class<?>> treeSet = Arrays.stream(profilers) .map(Profiler::getTargetClasses) .flatMap(Set::stream) .collect(Collectors.toCollection(() -> new TreeSet<>(reportComparator))); long totalTime = Arrays.stream(profilers) .map(Profiler::getProfiles) .flatMap(Collection::stream) .mapToLong(Profiler.Profile::getTotalTime) .sum(); long accumulatedTime = 0; for (Class<?> c : treeSet) { Profile p = getProfile(c); p.writeXML(xmlOutput); accumulatedTime += p.getTotalTime(); if (accumulatedTime > 3 * totalTime / 4) { break; } } xmlOutput.closeTag("FindBugsProfile"); } }
ProfileSummary implements IProfiler, XMLWriteable { @Override public void writeXML(@NonNull XMLOutput xmlOutput) throws IOException { xmlOutput.startTag("FindBugsProfile"); xmlOutput.stopTag(false); Comparator<Class<?>> reportComparator = new Profiler.TotalTimeComparator(this); TreeSet<Class<?>> treeSet = Arrays.stream(profilers) .map(Profiler::getTargetClasses) .flatMap(Set::stream) .collect(Collectors.toCollection(() -> new TreeSet<>(reportComparator))); long totalTime = Arrays.stream(profilers) .map(Profiler::getProfiles) .flatMap(Collection::stream) .mapToLong(Profiler.Profile::getTotalTime) .sum(); long accumulatedTime = 0; for (Class<?> c : treeSet) { Profile p = getProfile(c); p.writeXML(xmlOutput); accumulatedTime += p.getTotalTime(); if (accumulatedTime > 3 * totalTime / 4) { break; } } xmlOutput.closeTag("FindBugsProfile"); } ProfileSummary(@NonNull Profiler... profilers); }
ProfileSummary implements IProfiler, XMLWriteable { @Override public void writeXML(@NonNull XMLOutput xmlOutput) throws IOException { xmlOutput.startTag("FindBugsProfile"); xmlOutput.stopTag(false); Comparator<Class<?>> reportComparator = new Profiler.TotalTimeComparator(this); TreeSet<Class<?>> treeSet = Arrays.stream(profilers) .map(Profiler::getTargetClasses) .flatMap(Set::stream) .collect(Collectors.toCollection(() -> new TreeSet<>(reportComparator))); long totalTime = Arrays.stream(profilers) .map(Profiler::getProfiles) .flatMap(Collection::stream) .mapToLong(Profiler.Profile::getTotalTime) .sum(); long accumulatedTime = 0; for (Class<?> c : treeSet) { Profile p = getProfile(c); p.writeXML(xmlOutput); accumulatedTime += p.getTotalTime(); if (accumulatedTime > 3 * totalTime / 4) { break; } } xmlOutput.closeTag("FindBugsProfile"); } 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 { @Override public void writeXML(@NonNull XMLOutput xmlOutput) throws IOException { xmlOutput.startTag("FindBugsProfile"); xmlOutput.stopTag(false); Comparator<Class<?>> reportComparator = new Profiler.TotalTimeComparator(this); TreeSet<Class<?>> treeSet = Arrays.stream(profilers) .map(Profiler::getTargetClasses) .flatMap(Set::stream) .collect(Collectors.toCollection(() -> new TreeSet<>(reportComparator))); long totalTime = Arrays.stream(profilers) .map(Profiler::getProfiles) .flatMap(Collection::stream) .mapToLong(Profiler.Profile::getTotalTime) .sum(); long accumulatedTime = 0; for (Class<?> c : treeSet) { Profile p = getProfile(c); p.writeXML(xmlOutput); accumulatedTime += p.getTotalTime(); if (accumulatedTime > 3 * totalTime / 4) { break; } } xmlOutput.closeTag("FindBugsProfile"); } 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);  }