Changeset 10697 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
r10662 r10697 37 37 import java.util.concurrent.ForkJoinTask; 38 38 import java.util.concurrent.RecursiveTask; 39 import java.util.function.Supplier; 39 40 40 41 import javax.swing.AbstractButton; … … 63 64 import org.openstreetmap.josm.gui.mappaint.StyleElementList; 64 65 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 65 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector;66 66 import org.openstreetmap.josm.gui.mappaint.styleelement.AreaElement; 67 67 import org.openstreetmap.josm.gui.mappaint.styleelement.BoxTextElement; … … 192 192 } 193 193 194 p rivatestatic class StyleRecord implements Comparable<StyleRecord> {194 public static class StyleRecord implements Comparable<StyleRecord> { 195 195 private final StyleElement style; 196 196 private final OsmPrimitive osm; … … 240 240 return Float.compare(this.style.objectZIndex, other.style.objectZIndex); 241 241 } 242 } 243 244 /** 245 * Saves benchmark data for tests. 246 */ 247 public static class BenchmarkData { 248 public long generateTime; 249 public long sortTime; 250 public long drawTime; 251 public Map<Class<? extends StyleElement>, Integer> styleElementCount; 252 public boolean skipDraw; 253 254 private void recordElementStats(List<StyleRecord> srs) { 255 styleElementCount = new HashMap<>(); 256 for (StyleRecord r : srs) { 257 Class<? extends StyleElement> klass = r.style.getClass(); 258 Integer count = styleElementCount.get(klass); 259 if (count == null) { 260 count = 0; 261 } 262 styleElementCount.put(klass, count + 1); 263 } 264 265 } 266 } 267 268 /* can be set by tests, if detailed benchmark data is requested */ 269 public BenchmarkData benchmarkData; 242 243 /** 244 * Get the style for this style element. 245 * @return The style 246 */ 247 public StyleElement getStyle() { 248 return style; 249 } 250 } 270 251 271 252 private static Map<Font, Boolean> IS_GLYPH_VECTOR_DOUBLE_TRANSLATION_BUG = new HashMap<>(); … … 373 354 private boolean leftHandTraffic; 374 355 private Object antialiasing; 356 357 private Supplier<RenderBenchmarkCollector> benchmarkFactory = RenderBenchmarkCollector.defaultBenchmarkSupplier(); 375 358 376 359 /** … … 1902 1885 } 1903 1886 1887 /** 1888 * Sets the factory that creates the benchmark data receivers. 1889 * @param benchmarkFactory The factory. 1890 * @since 10697 1891 */ 1892 public void setBenchmarkFactory(Supplier<RenderBenchmarkCollector> benchmarkFactory) { 1893 this.benchmarkFactory = benchmarkFactory; 1894 } 1895 1904 1896 @Override 1905 1897 public void render(final DataSet data, boolean renderVirtualNodes, Bounds bounds) { 1898 RenderBenchmarkCollector benchmark = benchmarkFactory.get(); 1906 1899 BBox bbox = bounds.toBBox(); 1907 1900 getSettings(renderVirtualNodes); 1908 boolean benchmarkOutput = Main.isTraceEnabled() || Main.pref.getBoolean("mappaint.render.benchmark", false);1909 boolean benchmark = benchmarkOutput || benchmarkData != null;1910 1901 1911 1902 data.getReadLock().lock(); … … 1913 1904 highlightWaySegments = data.getHighlightedWaySegments(); 1914 1905 1915 long timeStart = 0, timeGenerateDone = 0, timeSortingDone = 0, timeFinished; 1916 if (benchmark) { 1917 timeStart = System.currentTimeMillis(); 1918 if (benchmarkOutput) { 1919 System.err.print("BENCHMARK: rendering "); 1920 } 1921 } 1906 benchmark.renderStart(circum); 1922 1907 1923 1908 List<Node> nodes = data.searchNodes(bbox); … … 1937 1922 Math.max(100, (nodes.size() + ways.size()) / THREAD_POOL.getParallelism() / 3))); 1938 1923 1939 if (benchmark) { 1940 timeGenerateDone = System.currentTimeMillis(); 1941 if (benchmarkOutput) { 1942 System.err.print("phase 1 (calculate styles): " + Utils.getDurationString(timeGenerateDone - timeStart)); 1943 } 1944 if (benchmarkData != null) { 1945 benchmarkData.generateTime = timeGenerateDone - timeStart; 1946 } 1924 if (!benchmark.renderSort()) { 1925 return; 1947 1926 } 1948 1927 1949 1928 Collections.sort(allStyleElems); // TODO: try parallel sort when switching to Java 8 1950 1929 1951 if (benchmarkData != null) { 1952 timeSortingDone = System.currentTimeMillis(); 1953 benchmarkData.sortTime = timeSortingDone - timeGenerateDone; 1954 if (benchmarkData.skipDraw) { 1955 benchmarkData.recordElementStats(allStyleElems); 1956 return; 1957 } 1930 if (!benchmark.renderDraw(allStyleElems)) { 1931 return; 1958 1932 } 1959 1933 … … 1969 1943 } 1970 1944 1971 if (benchmark) {1972 timeFinished = System.currentTimeMillis();1973 if (benchmarkData != null) {1974 benchmarkData.drawTime = timeFinished - timeGenerateDone;1975 benchmarkData.recordElementStats(allStyleElems);1976 }1977 if (benchmarkOutput) {1978 System.err.println("; phase 2 (draw): " + Utils.getDurationString(timeFinished - timeGenerateDone) +1979 "; total: " + Utils.getDurationString(timeFinished - timeStart) +1980 " (scale: " + circum + " zoom level: " + Selector.GeneralSelector.scale2level(circum) + ')');1981 }1982 }1983 1984 1945 drawVirtualNodes(data, bbox); 1946 1947 benchmark.renderDone(); 1985 1948 } finally { 1986 1949 data.getReadLock().unlock(); -
trunk/test/performance/org/openstreetmap/josm/gui/mappaint/MapRendererPerformanceTest.java
r10222 r10697 11 11 import java.util.Collections; 12 12 import java.util.EnumMap; 13 import java.util.HashMap; 13 14 import java.util.List; 14 15 import java.util.Locale; 15 16 import java.util.Map; 17 import java.util.stream.Collectors; 16 18 17 19 import javax.imageio.ImageIO; … … 30 32 import org.openstreetmap.josm.data.coor.LatLon; 31 33 import org.openstreetmap.josm.data.osm.DataSet; 34 import org.openstreetmap.josm.data.osm.visitor.paint.RenderBenchmarkCollector.CapturingBenchmark; 32 35 import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer; 36 import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer.StyleRecord; 33 37 import org.openstreetmap.josm.data.projection.Projections; 34 38 import org.openstreetmap.josm.gui.NavigatableComponent; … … 208 212 Main.warn(ex); 209 213 } 210 StyledMapRenderer.BenchmarkData data = new StyledMapRenderer.BenchmarkData(); 211 data.skipDraw = skipDraw; 212 renderer.benchmarkData = data; 214 BenchmarkData data = new BenchmarkData(); 215 renderer.setBenchmarkFactory(() -> data); 213 216 renderer.render(dsCity, false, bounds); 214 217 215 218 if (i > noWarmup) { 216 generateTimes.add(data.ge nerateTime);217 sortTimes.add(data. sortTime);218 drawTimes.add(data. drawTime);219 totalTimes.add(data.ge nerateTime + data.sortTime + data.drawTime);219 generateTimes.add(data.getGenerateTime()); 220 sortTimes.add(data.getSortTime()); 221 drawTimes.add(data.getDrawTime()); 222 totalTimes.add(data.getGenerateTime() + data.getSortTime() + data.getDrawTime()); 220 223 } 221 224 if (i == 1) { … … 318 321 } 319 322 320 public static void dumpTimes(StyledMapRenderer.BenchmarkData bd) { 321 System.out.print(String.format("gen. %3d, sort %3d, draw %3d%n", bd.generateTime, bd.sortTime, bd.drawTime)); 322 } 323 324 public static void dumpElementCount(StyledMapRenderer.BenchmarkData bd) { 325 String sep = null; 326 for (Map.Entry<Class<? extends StyleElement>, Integer> e : bd.styleElementCount.entrySet()) { 327 if (sep == null) { 328 sep = " "; 329 } else { 330 System.out.print(sep); 331 } 332 System.out.print(e.getKey().getSimpleName().replace("Element", "") + ":" + e.getValue()); 333 } 334 System.out.println(); 323 public static void dumpTimes(BenchmarkData bd) { 324 System.out.print(String.format("gen. %3d, sort %3d, draw %3d%n", bd.getGenerateTime(), bd.getSortTime(), bd.getDrawTime())); 325 } 326 327 public static void dumpElementCount(BenchmarkData bd) { 328 System.out.println(bd.recordElementStats().entrySet().stream() 329 .map(e -> e.getKey().getSimpleName().replace("Element", "") + ":" + e.getValue()).collect(Collectors.joining(" "))); 330 } 331 332 public static class BenchmarkData extends CapturingBenchmark { 333 334 private List<StyleRecord> allStyleElems; 335 336 @Override 337 public boolean renderDraw(List<StyleRecord> allStyleElems) { 338 this.allStyleElems = allStyleElems; 339 return super.renderDraw(allStyleElems); 340 } 341 342 private Map<Class<? extends StyleElement>, Integer> recordElementStats() { 343 Map<Class<? extends StyleElement>, Integer> styleElementCount = new HashMap<>(); 344 for (StyleRecord r : allStyleElems) { 345 Class<? extends StyleElement> klass = r.getStyle().getClass(); 346 Integer count = styleElementCount.get(klass); 347 if (count == null) { 348 count = 0; 349 } 350 styleElementCount.put(klass, count + 1); 351 } 352 return styleElementCount; 353 } 335 354 } 336 355 }
Note:
See TracChangeset
for help on using the changeset viewer.