Changeset 10697 in josm for trunk/src


Ignore:
Timestamp:
2016-08-01T22:56:04+02:00 (9 years ago)
Author:
Don-vip
Message:

fix #13258 - Pull benchmark code out of renderer (patch by michael2402) - gsoc-core

Location:
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java

    r10662 r10697  
    3737import java.util.concurrent.ForkJoinTask;
    3838import java.util.concurrent.RecursiveTask;
     39import java.util.function.Supplier;
    3940
    4041import javax.swing.AbstractButton;
     
    6364import org.openstreetmap.josm.gui.mappaint.StyleElementList;
    6465import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
    65 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector;
    6666import org.openstreetmap.josm.gui.mappaint.styleelement.AreaElement;
    6767import org.openstreetmap.josm.gui.mappaint.styleelement.BoxTextElement;
     
    192192    }
    193193
    194     private static class StyleRecord implements Comparable<StyleRecord> {
     194    public static class StyleRecord implements Comparable<StyleRecord> {
    195195        private final StyleElement style;
    196196        private final OsmPrimitive osm;
     
    240240            return Float.compare(this.style.objectZIndex, other.style.objectZIndex);
    241241        }
    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    }
    270251
    271252    private static Map<Font, Boolean> IS_GLYPH_VECTOR_DOUBLE_TRANSLATION_BUG = new HashMap<>();
     
    373354    private boolean leftHandTraffic;
    374355    private Object antialiasing;
     356
     357    private Supplier<RenderBenchmarkCollector> benchmarkFactory = RenderBenchmarkCollector.defaultBenchmarkSupplier();
    375358
    376359    /**
     
    19021885    }
    19031886
     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
    19041896    @Override
    19051897    public void render(final DataSet data, boolean renderVirtualNodes, Bounds bounds) {
     1898        RenderBenchmarkCollector benchmark = benchmarkFactory.get();
    19061899        BBox bbox = bounds.toBBox();
    19071900        getSettings(renderVirtualNodes);
    1908         boolean benchmarkOutput = Main.isTraceEnabled() || Main.pref.getBoolean("mappaint.render.benchmark", false);
    1909         boolean benchmark = benchmarkOutput || benchmarkData != null;
    19101901
    19111902        data.getReadLock().lock();
     
    19131904            highlightWaySegments = data.getHighlightedWaySegments();
    19141905
    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);
    19221907
    19231908            List<Node> nodes = data.searchNodes(bbox);
     
    19371922                    Math.max(100, (nodes.size() + ways.size()) / THREAD_POOL.getParallelism() / 3)));
    19381923
    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;
    19471926            }
    19481927
    19491928            Collections.sort(allStyleElems); // TODO: try parallel sort when switching to Java 8
    19501929
    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;
    19581932            }
    19591933
     
    19691943            }
    19701944
    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 
    19841945            drawVirtualNodes(data, bbox);
     1946
     1947            benchmark.renderDone();
    19851948        } finally {
    19861949            data.getReadLock().unlock();
Note: See TracChangeset for help on using the changeset viewer.