Ignore:
Timestamp:
2020-01-23T22:57:46+01:00 (4 years ago)
Author:
simon04
Message:

Introduce Stopwatch class to measure elapsed time

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/SplashScreen.java

    r15719 r15755  
    4242import org.openstreetmap.josm.tools.ImageProvider;
    4343import org.openstreetmap.josm.tools.Logging;
     44import org.openstreetmap.josm.tools.Stopwatch;
    4445import org.openstreetmap.josm.tools.Utils;
    4546
     
    150151    private static class MeasurableTask extends Task {
    151152        private final String name;
    152         private final long start;
     153        private final Stopwatch stopwatch;
    153154        private String duration = "";
    154155
    155156        MeasurableTask(String name) {
    156157            this.name = name;
    157             this.start = System.currentTimeMillis();
     158            this.stopwatch = Stopwatch.createStarted();
    158159        }
    159160
     
    162163                throw new IllegalStateException("This task has already been finished: " + name);
    163164            }
    164             long time = System.currentTimeMillis() - start;
    165             if (time >= 0) {
    166                 duration = tr(" ({0})", Utils.getDurationString(time));
     165            if (stopwatch.elapsed() >= 0) {
     166                duration = tr(" ({0})", stopwatch);
    167167            }
    168168        }
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java

    r15606 r15755  
    5858import org.openstreetmap.josm.tools.JosmRuntimeException;
    5959import org.openstreetmap.josm.tools.Logging;
     60import org.openstreetmap.josm.tools.Stopwatch;
    6061import org.openstreetmap.josm.tools.Utils;
    6162
     
    420421    public void drawAll(Graphics2D g, MapView mv, List<WayPoint> visibleSegments, Bounds clipBounds) {
    421422
    422         final long timeStart = System.currentTimeMillis();
     423        final Stopwatch stopwatch = Stopwatch.createStarted();
    423424
    424425        checkCache();
     
    487488        // show some debug info
    488489        if (Logging.isDebugEnabled() && !visibleSegments.isEmpty()) {
    489             final long timeDiff = System.currentTimeMillis() - timeStart;
    490 
    491490            Logging.debug("gpxdraw::draw takes " +
    492                          Utils.getDurationString(timeDiff) +
     491                         stopwatch +
    493492                         "(" +
    494493                         "segments= " + visibleSegments.size() +
    495                          ", per 10000 = " + Utils.getDurationString(10_000 * timeDiff / visibleSegments.size()) +
     494                         ", per 10000 = " + Utils.getDurationString(10_000 * stopwatch.elapsed() / visibleSegments.size()) +
    496495                         ")"
    497496              );
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

    r15717 r15755  
    2929import org.openstreetmap.josm.tools.ListenerList;
    3030import org.openstreetmap.josm.tools.Logging;
     31import org.openstreetmap.josm.tools.Stopwatch;
    3132import org.openstreetmap.josm.tools.Utils;
    3233
     
    321322
    322323    private static void loadStyleForFirstTime(StyleSource source) {
    323         final long startTime = System.currentTimeMillis();
     324        final Stopwatch stopwatch = Stopwatch.createStarted();
    324325        source.loadStyleSource();
    325326        if (Config.getPref().getBoolean("mappaint.auto_reload_local_styles", true) && source.isLocal()) {
     
    331332        }
    332333        if (Logging.isDebugEnabled() || !source.isValid()) {
    333             final long elapsedTime = System.currentTimeMillis() - startTime;
    334             String message = "Initializing map style " + source.url + " completed in " + Utils.getDurationString(elapsedTime);
     334            String message = "Initializing map style " + source.url + " completed in " + stopwatch;
    335335            if (!source.isValid()) {
    336336                Logging.warn(message + " (" + source.getErrors().size() + " errors, " + source.getWarnings().size() + " warnings)");
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetReader.java

    r15072 r15755  
    4747import org.openstreetmap.josm.tools.I18n;
    4848import org.openstreetmap.josm.tools.Logging;
     49import org.openstreetmap.josm.tools.Stopwatch;
    4950import org.openstreetmap.josm.tools.Utils;
    5051import org.openstreetmap.josm.tools.XmlObjectParser;
     
    353354        Collection<TaggingPreset> tp;
    354355        Logging.debug("Reading presets from {0}", source);
    355         long startTime = System.currentTimeMillis();
     356        Stopwatch stopwatch = Stopwatch.createStarted();
    356357        try (
    357358            CachedFile cf = new CachedFile(source).setHttpAccept(PRESET_MIME_TYPES);
     
    368369        }
    369370        if (Logging.isDebugEnabled()) {
    370             Logging.debug("Presets read in {0}", Utils.getDurationString(System.currentTimeMillis() - startTime));
     371            Logging.debug("Presets read in {0}", stopwatch);
    371372        }
    372373        return tp;
Note: See TracChangeset for help on using the changeset viewer.