Example usage for org.apache.commons.lang.time DurationFormatUtils formatDurationHMS

List of usage examples for org.apache.commons.lang.time DurationFormatUtils formatDurationHMS

Introduction

In this page you can find the example usage for org.apache.commons.lang.time DurationFormatUtils formatDurationHMS.

Prototype

public static String formatDurationHMS(long durationMillis) 

Source Link

Document

Formats the time gap as a string.

The format used is ISO8601-like: H:m:s.S.

Usage

From source file:de.unisb.cs.st.javalanche.mutation.util.FilePerformanceTest.java

public static void main(String[] args) throws IOException {
    int limit = 1000;
    int total = 0;
    StopWatch stp = new StopWatch();
    stp.start();//from www  .j av a2 s  .  c om
    File dir = new File("mutation-files/tmp");
    dir.mkdir();
    for (int i = 0; i < limit; i++) {
        Map<String, Set<Integer>> map = getMap();
        File tempFile = new File(dir, "test-" + i + ".ser");
        if (!tempFile.exists()) {
            SerializeIo.serializeToFile(map, tempFile);
        } else {
            Map<String, Set<Integer>> deserialize = SerializeIo.get(tempFile);
            total += deserialize.size();
        }
    }
    System.out.println(
            "Handling " + limit + " files took " + DurationFormatUtils.formatDurationHMS(stp.getTime()));
}

From source file:de.unisb.cs.st.javalanche.mutation.util.CsvWriter.java

public static void main(String[] args) throws IOException {
    // Set<Long> covered = MutationCoverageFile.getCoveredMutations();
    // List<Long> mutationIds = QueryManager.getMutationsWithoutResult(
    // covered, 0);

    Session session = HibernateUtil.getSessionFactory().openSession();
    List<Mutation> mutations = QueryManager.getMutationsForProject(
            ConfigurationLocator.getJavalancheConfiguration().getProjectPrefix(), session);

    logger.info("Got " + mutations.size() + " mutation ids.");
    List<String> lines = new ArrayList<String>();
    lines.add(Mutation.getCsvHead() + ",DETECTED");
    int counter = 0;
    int flushs = 0;
    StopWatch stp = new StopWatch();
    for (Mutation mutation : mutations) {
        // Mutation mutation = QueryManager.getMutationByID(id, session);
        lines.add(mutation.getCsvString() + "," + mutation.isKilled());
        counter++;//from www  . j a v a2 s .co m
        if (counter > 20) {
            counter = 0;
            // 20, same as the JDBC batch size
            // flush a batch of inserts and release memory:
            // see
            // http://www.hibernate.org/hib_docs/reference/en/html/batch.html
            stp.reset();
            stp.start();
            flushs++;
            session.flush();
            // session.clear();
            logger.info("Did flush. It took: " + DurationFormatUtils.formatDurationHMS(stp.getTime()));
        }
    }
    session.close();
    logger.info("Starting to write file with " + lines.size() + " entries.");
    FileUtils.writeLines(new File("mutations.csv"), lines);
}

From source file:de.unisb.cs.st.javalanche.mutation.util.DBPerformanceTest.java

private static void testWrite() {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();// w  ww .java  2  s .c  om
    try {
        File file = new File("test.txt");
        file.deleteOnExit();
        FileWriter fw = new FileWriter(file);
        BufferedWriter w = new BufferedWriter(fw);
        for (int i = 0; i < 50 * 1024 * 1024; i++) {
            w.append('x');
        }
        w.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    stopWatch.stop();
    System.out.printf("Writing file took %s\n", DurationFormatUtils.formatDurationHMS(stopWatch.getTime()));

}

From source file:com.pva.QueryGeneratorImpl.java

public void addToTimeSeriesQueue(TimeSeries timeSeries) {
    long startTime = 0L;
    timeSeriesSendCount.incrementAndGet();
    // we're gonna let Redis do the serialization..
    LOGGER.debug(String.format("Adding to queue: %s", timeSeries));
    startTime = System.nanoTime();
    timeSeriesQueue.add(timeSeries);//from w w w.j  a  va  2 s.  c  o m
    LOGGER.debug(String.format("Time to add to queue: %s",
            DurationFormatUtils.formatDurationHMS((System.nanoTime() - startTime) / 1000000)));
}

From source file:com.aef.TicketGeneratorImpl.java

public void addToTicketQueue(TicketBatch ticketBatch) {
    long startTime = 0L;
    ticketBatchSendCount.incrementAndGet();
    // we're gonna let Redis do the serialization..
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(String.format("Adding to queue: %s", ticketBatch));
        startTime = System.nanoTime();
    }//from   ww  w  .jav a  2  s. c  o  m
    ticketQueue.add(ticketBatch);
    if (LOGGER.isDebugEnabled()) {
        long elapsed = System.nanoTime() - startTime;
        LOGGER.debug(String.format("Time to add to queue: %s",
                DurationFormatUtils.formatDurationHMS(elapsed / 1000000)));
    }
}

From source file:de.unisb.cs.st.javalanche.mutation.util.DBPerformanceTest.java

private void queryMutations() {
    List<Long> ids = new ArrayList<Long>();
    for (Mutation m : getMutations()) {
        ids.add(m.getId());/*from w w  w  . j  av a2  s .  c  om*/
    }
    StringBuilder sb = new StringBuilder();
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    List<Mutation> mutations = QueryManager.getMutationsByIds(ids.toArray(new Long[0]));
    for (Mutation mutation : mutations) {
        sb.append(mutation.getClassName());
    }
    stopWatch.stop();
    System.out.printf("Querying %d mutations took %s -- checkvalue: %d\n", LIMIT,
            DurationFormatUtils.formatDurationHMS(stopWatch.getTime()), sb.length());
}

From source file:com.flexive.extractor.audio.FxAudioMetaDataImpl.java

/**
 * {@inheritDoc}
 */
@Override
public String getLengthAsTimeString() {
    return DurationFormatUtils.formatDurationHMS(length / 1000L);
}

From source file:de.unisb.cs.st.javalanche.mutation.util.DBPerformanceTest.java

private void testDelete() {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();/*from   w w w  .  jav a2s.  co  m*/
    MutationDeleter.deleteAllWithPrefix(PREFIX);
    stopWatch.stop();
    System.out.printf("Deleting %d mutations took %s\n", LIMIT,
            DurationFormatUtils.formatDurationHMS(stopWatch.getTime()));
}

From source file:com.spotify.helios.master.DeadAgentReaper.java

@Override
protected void runOneIteration() {
    log.debug("Reaping agents");
    final List<String> agents = masterModel.listHosts();
    for (final String agent : agents) {
        try {/*  w ww  .  j  a v a 2  s  . c o  m*/
            final HostStatus hostStatus = masterModel.getHostStatus(agent);
            if (hostStatus == null || hostStatus.getStatus() != HostStatus.Status.DOWN) {
                // Host not found or host not DOWN -- nothing to do, move on to the next host
                continue;
            }

            final AgentInfo agentInfo = hostStatus.getAgentInfo();
            if (agentInfo == null) {
                continue;
            }

            final long downSince = agentInfo.getStartTime() + agentInfo.getUptime();
            final long downDurationMillis = clock.now().getMillis() - downSince;

            if (downDurationMillis >= timeoutMillis) {
                try {
                    log.info("Reaping dead agent '{}' (DOWN for {} hours)", agent,
                            DurationFormatUtils.formatDurationHMS(downDurationMillis));
                    masterModel.deregisterHost(agent);
                } catch (Exception e) {
                    log.warn("Failed to reap agent '{}'", agent, e);
                }
            }
        } catch (Exception e) {
            log.warn("Failed to determine if agent '{}' should be reaped", agent, e);
        }
    }
}

From source file:de.unisb.cs.st.javalanche.rhino.RhinoTestRunnable.java

public void run() {
    List<String> argList = getArgs();
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final ByteArrayOutputStream err = new ByteArrayOutputStream();

    String[] arguments = argList.toArray(new String[0]);
    try {//from  w ww  .  j av a2  s . c o m
        stopWatch.start();
        exitCode = WrappedMain.wrappedExec(arguments, new PrintStream(out), new PrintStream(err));

    } catch (Throwable t) {
        String message = "Caught exception during mutation testing. Exception is most probably caused by the mutation";
        logger.warn(message, t);
        logger.warn(t.toString() + " " + Arrays.toString(t.getStackTrace()));
        exitCode = -1;
    } finally {
        stopWatch.stop();
    }
    byte[] outByteArray = out.toByteArray();
    outString = new String(outByteArray);
    byte[] errByteArray = err.toByteArray();
    errString = new String(errByteArray);
    synchronized (this) {
        hasRun = true;
    }
    logger.info("Runnable finsihed  Took " + DurationFormatUtils.formatDurationHMS(stopWatch.getTime())
            + " \nOUT:\n" + outString + " \nERR\n" + errString);
}