Changeset 6354 in josm for trunk


Ignore:
Timestamp:
2013-11-02T16:36:10+01:00 (11 years ago)
Author:
Don-vip
Message:

print duration of tests for performance evaluation

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/Test.java

    r6336 r6354  
    2323import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    2424import org.openstreetmap.josm.tools.GBC;
     25import org.openstreetmap.josm.tools.Utils;
    2526
    2627/**
     
    6465    /** the progress monitor to use */
    6566    protected ProgressMonitor progressMonitor;
     67   
     68    /** the start time to compute elapsed time when test finishes */
     69    protected long startTime;
     70   
    6671    /**
    6772     * Constructor
     
    8792     */
    8893    public void initialize() throws Exception {
     94        this.startTime = -1;
    8995    }
    9096
     
    100106            this.progressMonitor = progressMonitor;
    101107        }
    102         this.progressMonitor.beginTask(tr("Running test {0}", name));
    103         errors = new ArrayList<TestError>(30);
     108        String startMessage = tr("Running test {0}", name);
     109        this.progressMonitor.beginTask(startMessage);
     110        Main.debug(startMessage);
     111        this.errors = new ArrayList<TestError>(30);
     112        this.startTime = System.currentTimeMillis();
    104113    }
    105114
     
    130139        progressMonitor.finishTask();
    131140        progressMonitor = null;
     141        if (startTime > 0) {
     142            long elapsedTime = System.currentTimeMillis() - startTime;
     143            Main.info(tr("Test ''{0}'' completed in {1}", getName(), Utils.getDurationString(elapsedTime)));
     144        }
    132145    }
    133146
  • trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java

    r6329 r6354  
    151151     */
    152152    public TagChecker() {
    153         super(tr("Tag checker :"), tr("This test checks for errors in tag keys and values."));
     153        super(tr("Tag checker"), tr("This test checks for errors in tag keys and values."));
    154154    }
    155155
     
    511511        a.anchor = GridBagConstraints.EAST;
    512512
    513         testPanel.add(new JLabel(name), GBC.eol().insets(3,0,0,0));
     513        testPanel.add(new JLabel(name+" :"), GBC.eol().insets(3,0,0,0));
    514514
    515515        prefCheckKeys = new JCheckBox(tr("Check property keys."), Main.pref.getBoolean(PREF_CHECK_KEYS, true));
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r6313 r6354  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.tools;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5import static org.openstreetmap.josm.tools.I18n.trn;
    36
    47import java.awt.Color;
     
    754757        return josmTmpDir;
    755758    }
     759
     760    /**
     761     * Returns a simple human readable (hours, minutes, seconds) string for a given duration in milliseconds.
     762     * @param elapsedTime The duration in milliseconds
     763     * @return A human redable string for the given duration
     764     * @throws IllegalArgumentException if elapsedTime is < 0
     765     * @since 6354
     766     */
     767    public static String getDurationString(long elapsedTime) throws IllegalArgumentException {
     768        if (elapsedTime < 0) {
     769            throw new IllegalArgumentException("elapsedTime must be > 0");
     770        }
     771        // Is it less than 1 second ?
     772        if (elapsedTime < 1000) {
     773            return String.format("%d %s", elapsedTime, tr("ms"));
     774        }
     775        // Is it less than 1 minute ?
     776        if (elapsedTime < 60*1000) {
     777            return String.format("%.1f %s", elapsedTime/1000f, tr("s"));
     778        }
     779        // Is it less than 1 hour ?
     780        if (elapsedTime < 60*60*1000) {
     781            return String.format("%d %s %d %s", elapsedTime/60000, tr("min"), elapsedTime/1000, tr("s"));
     782        }
     783        // Is it less than 1 day ?
     784        if (elapsedTime < 24*60*60*1000) {
     785            return String.format("%d %s %d %s", elapsedTime/3600000, tr("h"), elapsedTime/60000, tr("min"));
     786        }
     787        long days = elapsedTime/86400000;
     788        return String.format("%d %s %d %s", days, trn("day", "days", days), elapsedTime/3600000, tr("h"));
     789    }
    756790}
Note: See TracChangeset for help on using the changeset viewer.