Example usage for com.google.common.base Stopwatch createStarted

List of usage examples for com.google.common.base Stopwatch createStarted

Introduction

In this page you can find the example usage for com.google.common.base Stopwatch createStarted.

Prototype

@CheckReturnValue
public static Stopwatch createStarted() 

Source Link

Document

Creates (and starts) a new stopwatch using System#nanoTime as its time source.

Usage

From source file:org.glowroot.agent.init.NettyWorkaround.java

private static void waitForMain(Instrumentation instrumentation) throws InterruptedException {
    Stopwatch stopwatch = Stopwatch.createStarted();
    while (stopwatch.elapsed(SECONDS) < 60) {
        Thread.sleep(100);//from ww  w  . j av  a2s.  c  o m
        for (Class<?> clazz : instrumentation.getInitiatedClasses(null)) {
            if (clazz.getName().equals("sun.misc.Launcher")) {
                return;
            }
        }
    }
    // something has gone wrong
    startupLogger.error("sun.misc.Launcher was never loaded");
}

From source file:edu.illinois.keshmesh.detector.Main.java

public static BugInstances initAndPerformAnalysis(IJavaProject javaProject, Reporter reporter,
        ConfigurationOptions configurationOptions) throws WALAInitializationException {
    BugInstances bugInstances = new BugInstances();
    int objectSensitivityLevel = configurationOptions.getObjectSensitivityLevel();
    reporter.report(new KeyValuePair("OBJECT_SENSITIVITY_LEVEL", String.valueOf(objectSensitivityLevel)));
    BasicAnalysisData basicAnalysisData = initBytecodeAnalysis(javaProject, reporter, configurationOptions);
    if (configurationOptions.shouldDumpCallGraph()) {
        dumpCallGraph(basicAnalysisData.callGraph);
    }/*from   w ww  .j a  va2 s  .  c om*/
    Iterator<BugPattern> bugPatternsIterator = BugPatterns.iterator();
    while (bugPatternsIterator.hasNext()) {
        BugPattern bugPattern = bugPatternsIterator.next();
        BugPatternDetector bugPatternDetector = bugPattern.createBugPatternDetector();
        Stopwatch stopWatch = Stopwatch.createStarted();
        BugInstances instancesOfCurrentBugPattern = bugPatternDetector.performAnalysis(javaProject,
                basicAnalysisData);
        stopWatch.stop();
        reporter.report(
                new KeyValuePair("BUG_PATTERN_" + bugPattern.getName() + "_DETECTION_TIME_IN_MILLISECONDS",
                        String.valueOf(stopWatch.elapsed(TimeUnit.MILLISECONDS))));
        bugInstances.addAll(instancesOfCurrentBugPattern);
        reporter.report(new KeyValuePair("NUMBER_OF_INSTANCES_OF_BUG_PATTERN_" + bugPattern.getName(),
                String.valueOf(instancesOfCurrentBugPattern.size())));
    }
    reporter.close();
    return bugInstances;
}

From source file:com.google.devtools.kythe.analyzers.base.AbstractCompilationAnalyzer.java

/**
 * Analyzes the given {@link AnalysisRequest}, emitting all facts with the given
 * {@link FactEmitter}.//from  w ww  . ja  va2 s.co  m
 */
public void analyzeRequest(AnalysisRequest req, FactEmitter emitter) throws AnalysisException {
    Preconditions.checkNotNull(req, "AnalysisRequest must be non-null");
    Stopwatch timer = Stopwatch.createStarted();
    try {
        analyzeCompilation(req.getCompilation(), parseFileDataService(req.getFileDataService()), emitter);
    } catch (Throwable t) {
        logger.warningfmt("Uncaught exception: %s", t);
        t.printStackTrace();
        throw t;
    } finally {
        logger.infofmt("Analysis completed in %s", timer.stop());
    }
}

From source file:com.palantir.atlasdb.keyvalue.cassandra.jmx.CassandraJmxCompactionManager.java

public void performTombstoneCompaction(long timeoutInSeconds, String keyspace, String tableName)
        throws InterruptedException, TimeoutException {
    Stopwatch stopWatch = Stopwatch.createStarted();
    if (!removeHintedHandoff(timeoutInSeconds)) {
        return;/*www .ja  va  2  s.  c  om*/
    }
    log.info("All hinted handoff deletion tasks are completed.");

    long elapsedSeconds = stopWatch.elapsed(TimeUnit.SECONDS);
    long remainingTimeoutSeconds = timeoutInSeconds - elapsedSeconds;
    if (remainingTimeoutSeconds <= 0) {
        throw new TimeoutException(String.format("Task execution timeout in {} seconds. Timeout seconds:{}.",
                elapsedSeconds, timeoutInSeconds));
    }

    // ALL HINTED HANDOFFS NEED TO BE DELETED BEFORE MOVING TO TOMBSTONE COMPACTION TASK
    if (!deleteTombstone(keyspace, tableName, remainingTimeoutSeconds)) {
        return;
    }
    log.info("All compaction tasks are completed.");
}

From source file:org.terasology.rendering.primitives.ChunkTessellator.java

public ChunkMesh generateMesh(ChunkView chunkView, int meshHeight, int verticalOffset) {
    PerformanceMonitor.startActivity("GenerateMesh");
    ChunkMesh mesh = new ChunkMesh(bufferPool);

    final Stopwatch watch = Stopwatch.createStarted();

    for (int x = 0; x < ChunkConstants.SIZE_X; x++) {
        for (int z = 0; z < ChunkConstants.SIZE_Z; z++) {
            for (int y = verticalOffset; y < verticalOffset + meshHeight; y++) {
                Biome biome = chunkView.getBiome(x, y, z);

                Block block = chunkView.getBlock(x, y, z);
                if (block != null && !block.isInvisible()) {
                    generateBlockVertices(chunkView, mesh, x, y, z, biome);
                }/*from  ww w. ja va 2  s  .  c  o m*/
            }
        }
    }
    watch.stop();

    mesh.setTimeToGenerateBlockVertices((int) watch.elapsed(TimeUnit.MILLISECONDS));

    watch.reset().start();
    generateOptimizedBuffers(chunkView, mesh);
    watch.stop();
    mesh.setTimeToGenerateOptimizedBuffers((int) watch.elapsed(TimeUnit.MILLISECONDS));
    statVertexArrayUpdateCount++;

    PerformanceMonitor.endActivity();
    return mesh;
}

From source file:suneido.DbTools.java

static void load2(String arg) {
    int i = arg.indexOf(SEPARATOR);
    String filename = arg.substring(0, i);
    String tempfile = arg.substring(i + SEPARATOR.length());
    // FIXME: The three lines above just assume the existence of SEPARATOR.
    //        But if it's not there, i == -1 and this function throws an
    //        obscure -- in the sense of non-informational --
    //        StringIndexOutOfBoundsError...
    try (Database db = Dbpkg.create(tempfile); FileInputStream fin = new FileInputStream(filename)) {
        Stopwatch sw = Stopwatch.createStarted();
        int n = Dbpkg.loadDatabase(db, fin.getChannel());
        System.out.println("loaded " + n + " tables from " + filename + " in " + sw);
    } catch (Exception e) {
        throw new RuntimeException("load failed", e);
    }/*w  w w  . j  ava  2s .  c  om*/
}

From source file:com.webbfontaine.valuewebb.irms.factory.risk.RiskActionProcessor.java

private void doApply() {
    Stopwatch stopwatch = Stopwatch.createStarted();

    TtGenHome ttGenHome = getTtGenHome();

    List<Criteria> criteria = criteriaRepository.loadRules(criteriaType);

    LOGGER.trace("Loaded Risk Criteria: {}", criteria);

    RiskResultCollector riskResultCollector = new RiskResultCollector();

    for (Criteria criterion : criteria) {
        RuleCallable<List<RiskResult>> runnable = createCallable(ttGenHome, criterion);
        runnable.setRuleRepository(riskRuleRepository);

        riskResultCollector.add(executor.submit(runnable));
    }//from  ww w  . ja va 2s  . c  o m

    riskResultCollector.calculateResults();

    getRiskResultMerger().merge(ttGenHome.getInstance(), riskResultCollector);

    stopwatch.stop();
    LOGGER.info("IRMS Risk for TT with id {} took: {}", ttGenHome.getId(), stopwatch);
}

From source file:org.apache.jackrabbit.oak.run.CompactCommand.java

@Override
public void execute(String... args) throws Exception {
    OptionParser parser = new OptionParser();
    OptionSpec<String> directoryArg = parser.nonOptions("Path to segment store (required)")
            .ofType(String.class);
    OptionSpec<Void> forceFlag = parser.accepts("force",
            "Force compaction and ignore non matching segment version");
    OptionSpec<?> segmentTar = parser.accepts("segment-tar", "Use oak-segment-tar instead of oak-segment");
    OptionSet options = parser.parse(args);

    String path = directoryArg.value(options);
    if (path == null) {
        System.err.println("Compact a file store. Usage: compact [path] <options>");
        parser.printHelpOn(System.err);
        System.exit(-1);/*from   w w  w  . j  av  a 2s . c  o  m*/
    }

    File directory = new File(path);
    boolean force = options.has(forceFlag);

    boolean success = false;
    Set<String> beforeLs = newHashSet();
    Set<String> afterLs = newHashSet();
    Stopwatch watch = Stopwatch.createStarted();

    System.out.println("Compacting " + directory);
    System.out.println("    before ");
    beforeLs.addAll(list(directory));
    long sizeBefore = FileUtils.sizeOfDirectory(directory);
    System.out
            .println("    size " + IOUtils.humanReadableByteCount(sizeBefore) + " (" + sizeBefore + " bytes)");
    System.out.println("    -> compacting");

    try {
        if (options.has(segmentTar)) {
            SegmentTarUtils.compact(directory, force);
        } else {
            SegmentUtils.compact(directory, force);
        }
        success = true;
    } catch (Throwable e) {
        System.out.println("Compaction failure stack trace:");
        e.printStackTrace(System.out);
    } finally {
        watch.stop();
        if (success) {
            System.out.println("    after ");
            afterLs.addAll(list(directory));
            long sizeAfter = FileUtils.sizeOfDirectory(directory);
            System.out.println(
                    "    size " + IOUtils.humanReadableByteCount(sizeAfter) + " (" + sizeAfter + " bytes)");
            System.out.println("    removed files " + difference(beforeLs, afterLs));
            System.out.println("    added files " + difference(afterLs, beforeLs));
            System.out.println("Compaction succeeded in " + watch.toString() + " ("
                    + watch.elapsed(TimeUnit.SECONDS) + "s).");
        } else {
            System.out.println("Compaction failed in " + watch.toString() + " ("
                    + watch.elapsed(TimeUnit.SECONDS) + "s).");
            System.exit(1);
        }
    }
}

From source file:org.catrobat.catroid.common.bluetooth.ConnectionDataLogger.java

private static byte[] getNextMessage(BlockingQueue<byte[]> messages, int messageOffset, int messageByteOffset) {

    Stopwatch stopWatch = Stopwatch.createStarted();

    for (int i = 0; i < messageOffset; i++) {
        byte[] message = pollMessage(messages, TIMEOUT_SECONDS - (int) stopWatch.elapsed(TimeUnit.SECONDS));
        if (message == null) {
            return null;
        }//from   w  w w. j av a  2  s  .c  o  m
    }

    byte[] message = pollMessage(messages, TIMEOUT_SECONDS - (int) stopWatch.elapsed(TimeUnit.SECONDS));
    if (message == null) {
        return null;
    }

    return BluetoothTestUtils.getSubArray(message, messageByteOffset);
}

From source file:org.obm.breakdownduration.BreakdownDurationInterceptor.java

@Override
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
    Watch watch = getClassAnnotation(methodInvocation);
    if (watch == null) {
        return methodInvocation.proceed();
    }/*ww w.  jav  a2 s . c o  m*/

    Stopwatch stopwatch = Stopwatch.createStarted();
    try {
        breakdownLogger.startRecordingNode(watch.value());
        return methodInvocation.proceed();
    } finally {
        breakdownLogger.endRecordingNode(stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
    }
}