Search in sources :

Example 41 with StopWatch

use of org.apache.commons.lang.time.StopWatch in project archiva by apache.

the class DefaultRepositoryStatisticsManager method getLastStatistics.

@Override
public RepositoryStatistics getLastStatistics(MetadataRepository metadataRepository, String repositoryId) throws MetadataRepositoryException {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    // TODO: consider a more efficient implementation that directly gets the last one from the content repository
    List<String> scans = metadataRepository.getMetadataFacets(repositoryId, DefaultRepositoryStatistics.FACET_ID);
    if (scans == null) {
        return null;
    }
    Collections.sort(scans);
    if (!scans.isEmpty()) {
        String name = scans.get(scans.size() - 1);
        RepositoryStatistics repositoryStatistics = RepositoryStatistics.class.cast(metadataRepository.getMetadataFacet(repositoryId, RepositoryStatistics.FACET_ID, name));
        stopWatch.stop();
        log.debug("time to find last RepositoryStatistics: {} ms", stopWatch.getTime());
        return repositoryStatistics;
    } else {
        return null;
    }
}
Also used : RepositoryStatistics(org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics) DefaultRepositoryStatistics(org.apache.archiva.metadata.repository.stats.model.DefaultRepositoryStatistics) StopWatch(org.apache.commons.lang.time.StopWatch)

Example 42 with StopWatch

use of org.apache.commons.lang.time.StopWatch in project eol-globi-data by jhpoelen.

the class NameResolver method resolveNames.

public void resolveNames(Long batchSize) {
    StopWatch watchForEntireRun = new StopWatch();
    watchForEntireRun.start();
    StopWatch watchForBatch = new StopWatch();
    watchForBatch.start();
    Long count = 0L;
    Index<Node> studyIndex = graphService.index().forNodes("studies");
    IndexHits<Node> studies = studyIndex.query("title", "*");
    for (Node studyNode : studies) {
        final Study study1 = new StudyNode(studyNode);
        final Iterable<Relationship> specimens = NodeUtil.getSpecimens(study1);
        for (Relationship collected : specimens) {
            SpecimenNode specimen = new SpecimenNode(collected.getEndNode());
            final Relationship classifiedAs = specimen.getUnderlyingNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING);
            if (classifiedAs == null) {
                final Relationship describedAs = specimen.getUnderlyingNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.ORIGINALLY_DESCRIBED_AS), Direction.OUTGOING);
                final TaxonNode describedAsTaxon = new TaxonNode(describedAs.getEndNode());
                try {
                    if (taxonFilter.shouldInclude(describedAsTaxon)) {
                        Taxon resolvedTaxon = taxonIndex.getOrCreateTaxon(describedAsTaxon);
                        if (resolvedTaxon != null) {
                            specimen.classifyAs(resolvedTaxon);
                        }
                    }
                } catch (NodeFactoryException e) {
                    LOG.warn("failed to create taxon with name [" + describedAsTaxon.getName() + "] and id [" + describedAsTaxon.getExternalId() + "]", e);
                } finally {
                    count++;
                    if (count % batchSize == 0) {
                        watchForBatch.stop();
                        final long duration = watchForBatch.getTime();
                        if (duration > 0) {
                            LOG.info("resolved batch of [" + batchSize + "] names in " + getProgressMsg(batchSize, duration));
                        }
                        watchForBatch.reset();
                        watchForBatch.start();
                    }
                }
            }
        }
    }
    studies.close();
    watchForEntireRun.stop();
    LOG.info("resolved [" + count + "] names in " + getProgressMsg(count, watchForEntireRun.getTime()));
}
Also used : Node(org.neo4j.graphdb.Node) StopWatch(org.apache.commons.lang.time.StopWatch) NodeFactoryException(org.eol.globi.data.NodeFactoryException) Relationship(org.neo4j.graphdb.Relationship)

Example 43 with StopWatch

use of org.apache.commons.lang.time.StopWatch in project eol-globi-data by jhpoelen.

the class LinkUtil method doTimedLink.

public static void doTimedLink(Linker linker) {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    String linkName = Linker.class.getSimpleName();
    LOG.info(linkName + " started...");
    try {
        linker.link();
    } finally {
        stopWatch.stop();
        LOG.info(linkName + " completed in [" + stopWatch.getTime() / 1000 + "]s");
    }
}
Also used : StopWatch(org.apache.commons.lang.time.StopWatch)

Example 44 with StopWatch

use of org.apache.commons.lang.time.StopWatch in project eol-globi-data by jhpoelen.

the class TaxonInteractionIndexer method createTaxonInteractions.

public void createTaxonInteractions(Map<Fun.Tuple3<Long, String, Long>, Long> taxonInteractions) {
    StopWatch watchForEntireRun = new StopWatch();
    watchForEntireRun.start();
    long count = 0;
    Transaction tx = null;
    for (Fun.Tuple3<Long, String, Long> uniqueTaxonInteraction : taxonInteractions.keySet()) {
        if (count % 1000 == 0) {
            finalizeTx(tx);
            tx = graphService.beginTx();
        }
        final Node sourceTaxon = graphService.getNodeById(uniqueTaxonInteraction.a);
        final Node targetTaxon = graphService.getNodeById(uniqueTaxonInteraction.c);
        if (sourceTaxon != null && targetTaxon != null) {
            final InteractType relType = InteractType.valueOf(uniqueTaxonInteraction.b);
            final Long interactionCount = taxonInteractions.get(uniqueTaxonInteraction);
            createInteraction(sourceTaxon, targetTaxon, relType, false, interactionCount);
            createInteraction(targetTaxon, sourceTaxon, InteractType.inverseOf(relType), true, interactionCount);
        }
        count++;
    }
    finalizeTx(tx);
    watchForEntireRun.stop();
    LOG.info("created [" + count + "] taxon interactions in " + getProgressMsg(count, watchForEntireRun.getTime()));
}
Also used : InteractType(org.eol.globi.domain.InteractType) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) SpecimenNode(org.eol.globi.domain.SpecimenNode) Fun(org.mapdb.Fun) StopWatch(org.apache.commons.lang.time.StopWatch)

Example 45 with StopWatch

use of org.apache.commons.lang.time.StopWatch in project elephant-bird by twitter.

the class TimeProtoConversions method main.

/**
 * @param args
 * @throws ExecException
 */
public static void main(String[] args) throws ExecException {
    int iterations = 100000;
    ProtobufToPig protoConv = new ProtobufToPig();
    for (int i = 0; i < iterations; i++) {
        Person proto = Fixtures.buildPersonProto();
        Tuple t = protoConv.toTuple(proto);
        t.get(0);
        t = new ProtobufTuple(proto);
        t.get(0);
    }
    StopWatch timer = new StopWatch();
    timer.start();
    for (int i = 0; i < iterations; i++) {
        Person proto = Fixtures.buildPersonProto();
        Tuple t = protoConv.toTuple(proto);
        t.get(0);
    }
    timer.split();
    System.err.println(timer.getSplitTime());
    timer.reset();
    timer.start();
    for (int i = 0; i < iterations; i++) {
        Person proto = Fixtures.buildPersonProto();
        Tuple t = new ProtobufTuple(proto);
        t.get(0);
    }
    timer.split();
    System.err.println(timer.getSplitTime());
}
Also used : ProtobufToPig(com.twitter.elephantbird.pig.util.ProtobufToPig) ProtobufTuple(com.twitter.elephantbird.pig.util.ProtobufTuple) Person(com.twitter.data.proto.tutorial.AddressBookProtos.Person) ProtobufTuple(com.twitter.elephantbird.pig.util.ProtobufTuple) Tuple(org.apache.pig.data.Tuple) StopWatch(org.apache.commons.lang.time.StopWatch)

Aggregations

StopWatch (org.apache.commons.lang.time.StopWatch)48 IOException (java.io.IOException)13 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 File (java.io.File)4 Path (java.nio.file.Path)4 HashMap (java.util.HashMap)4 FileNotFoundException (java.io.FileNotFoundException)3 ObjectOutputStream (java.io.ObjectOutputStream)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 Map (java.util.Map)3 SchemaHolder (org.motechproject.mds.dto.SchemaHolder)3 YarnApplicationReport (com.continuuity.weave.internal.yarn.YarnApplicationReport)2 BufferedInputStream (java.io.BufferedInputStream)2 BufferedOutputStream (java.io.BufferedOutputStream)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 NoSuchFileException (java.nio.file.NoSuchFileException)2 HashSet (java.util.HashSet)2