Changeset 9786 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2016-02-11T23:37:07+01:00 (8 years ago)
Author:
bastiK
Message:

new mappaint performance test
tests different features separately

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

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

    r9351 r9786  
    3333import java.util.List;
    3434import java.util.Map;
     35import java.util.Map.Entry;
    3536import java.util.concurrent.ForkJoinPool;
    3637import java.util.concurrent.ForkJoinTask;
     
    237238    }
    238239
     240    /**
     241     * Saves benchmark data for tests.
     242     */
     243    public static class BenchmarkData {
     244        public long generateTime;
     245        public long sortTime;
     246        public long drawTime;
     247        public Map<Class<? extends StyleElement>, Integer> styleElementCount;
     248        public boolean skipDraw;
     249
     250        private void recordElementStats(List<StyleRecord> srs) {
     251            styleElementCount = new HashMap<>();
     252            for (StyleRecord r : srs) {
     253                Class<? extends StyleElement> klass = r.style.getClass();
     254                Integer count = styleElementCount.get(klass);
     255                if (count == null) {
     256                    count = 0;
     257                }
     258                styleElementCount.put(klass, count + 1);
     259            }
     260
     261        }
     262    }
     263    /* can be set by tests, if detailed benchmark data is requested */
     264    public BenchmarkData benchmarkData = null;
     265
    239266    private static Map<Font, Boolean> IS_GLYPH_VECTOR_DOUBLE_TRANSLATION_BUG = new HashMap<>();
    240267
     
    18681895        BBox bbox = bounds.toBBox();
    18691896        getSettings(renderVirtualNodes);
    1870         boolean benchmark = Main.isTraceEnabled() || Main.pref.getBoolean("mappaint.render.benchmark", false);
     1897        boolean benchmarkOutput = Main.isTraceEnabled() || Main.pref.getBoolean("mappaint.render.benchmark", false);
     1898        boolean benchmark = benchmarkOutput || benchmarkData != null;
    18711899
    18721900        data.getReadLock().lock();
     
    18741902            highlightWaySegments = data.getHighlightedWaySegments();
    18751903
    1876             long timeStart = 0, timePhase1 = 0, timeFinished;
     1904            long timeStart = 0, timeGenerateDone = 0, timeSortingDone = 0, timeFinished;
    18771905            if (benchmark) {
    18781906                timeStart = System.currentTimeMillis();
     
    18971925
    18981926            if (benchmark) {
    1899                 timePhase1 = System.currentTimeMillis();
    1900                 System.err.print("phase 1 (calculate styles): " + Utils.getDurationString(timePhase1 - timeStart));
     1927                timeGenerateDone = System.currentTimeMillis();
     1928                if (benchmarkOutput) {
     1929                    System.err.print("phase 1 (calculate styles): " + Utils.getDurationString(timeGenerateDone - timeStart));
     1930                }
     1931                if (benchmarkData != null) {
     1932                    benchmarkData.generateTime = timeGenerateDone - timeStart;
     1933                }
    19011934            }
    19021935
    19031936            Collections.sort(allStyleElems); // TODO: try parallel sort when switching to Java 8
     1937
     1938            if (benchmarkData != null) {
     1939                timeSortingDone = System.currentTimeMillis();
     1940                benchmarkData.sortTime = timeSortingDone - timeGenerateDone;
     1941                if (benchmarkData.skipDraw) {
     1942                    benchmarkData.recordElementStats(allStyleElems);
     1943                    return;
     1944                }
     1945            }
    19041946
    19051947            for (StyleRecord r : allStyleElems) {
     
    19161958            if (benchmark) {
    19171959                timeFinished = System.currentTimeMillis();
    1918                 System.err.println("; phase 2 (draw): " + Utils.getDurationString(timeFinished - timePhase1) +
    1919                     "; total: " + Utils.getDurationString(timeFinished - timeStart) +
    1920                     " (scale: " + circum + " zoom level: " + Selector.GeneralSelector.scale2level(circum) + ')');
     1960                if (benchmarkData != null) {
     1961                    benchmarkData.drawTime = timeFinished - timeGenerateDone;
     1962                    benchmarkData.recordElementStats(allStyleElems);
     1963                }
     1964                if (benchmarkOutput) {
     1965                    System.err.println("; phase 2 (draw): " + Utils.getDurationString(timeFinished - timeGenerateDone) +
     1966                        "; total: " + Utils.getDurationString(timeFinished - timeStart) +
     1967                        " (scale: " + circum + " zoom level: " + Selector.GeneralSelector.scale2level(circum) + ')');
     1968                }
    19211969            }
    19221970
  • trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSetting.java

    r8674 r9786  
    6060                @Override
    6161                public void actionPerformed(ActionEvent e) {
    62                     boolean b = item.isSelected();
    63                     if (b == def) {
    64                         Main.pref.put(prefKey, null);
    65                     } else {
    66                         Main.pref.put(prefKey, b);
    67                     }
     62                    setValue(item.isSelected());
    6863                    Main.worker.submit(new MapPaintStyles.MapPaintStyleLoader(Arrays.asList(parentStyle)));
    6964                }
     
    9590            return Boolean.valueOf(val);
    9691        }
     92
     93        public void setValue(Object o) {
     94            if (o == null || !(o instanceof Boolean)) {
     95                throw new IllegalArgumentException();
     96            }
     97            boolean b = (Boolean) o;
     98            if (b == def) {
     99                Main.pref.put(prefKey, null);
     100            } else {
     101                Main.pref.put(prefKey, b);
     102            }
     103        }
    97104    }
    98105}
Note: See TracChangeset for help on using the changeset viewer.