org.apache.commons.lang3.time.StopWatch Java Examples

The following examples show how to use org.apache.commons.lang3.time.StopWatch. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContentStoreServiceTreeBasedContextCacheWarmer.java    From engine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void warmUpCache(Context context) {
    for (Map.Entry<String, Integer> entry : getDescriptorPreloadFolders().entrySet()) {
        String treeRoot = entry.getKey();
        int depth = entry.getValue();
        StopWatch stopWatch = new StopWatch();

        logger.info("Starting preload of tree [{}] with depth {}", treeRoot, depth);

        stopWatch.start();

        try {
            contentStoreService.getTree(context, treeRoot, depth);
        } catch (Exception e) {
            logger.error("Error while preloading tree at [{}]", treeRoot, e);
        }

        stopWatch.stop();

        logger.info("Preload of tree [{}] with depth {} completed in {} secs", treeRoot, depth,
                    stopWatch.getTime(TimeUnit.SECONDS));
    }
}
 
Example #2
Source File: AMOPChannel.java    From WeEvent with Apache License 2.0 6 votes vote down vote up
public ChannelResponse sendEvent(String topic, FileEvent fileEvent) throws BrokerException {
    if (this.subTopics.contains(topic) || this.subVerifyTopics.containsKey(topic)) {
        log.error("this is already receiver side for topic: {}", topic);
        throw new BrokerException(ErrorCode.FILE_SENDER_RECEIVER_CONFLICT);
    }

    byte[] json = JsonHelper.object2JsonBytes(fileEvent);
    ChannelRequest channelRequest = new ChannelRequest();
    channelRequest.setToTopic(topic);
    channelRequest.setMessageID(this.service.newSeq());
    channelRequest.setTimeout(this.service.getConnectSeconds() * 1000);
    channelRequest.setContent(json);

    log.info("send channel request, topic: {} {} id: {}", channelRequest.getToTopic(), fileEvent.getEventType(), channelRequest.getMessageID());
    ChannelResponse rsp;
    StopWatch sw = StopWatch.createStarted();
    if (this.senderVerifyTopics.containsKey(topic)) {
        log.info("over verified AMOP channel");
        rsp = this.service.sendChannelMessageForVerifyTopic(channelRequest);
    } else {
        rsp = this.service.sendChannelMessage2(channelRequest);
    }
    sw.stop();
    log.info("receive channel response, id: {} result: {}-{} cost: {}", rsp.getMessageID(), rsp.getErrorCode(), rsp.getErrorMessage(), sw.getTime());
    return rsp;
}
 
Example #3
Source File: BaseTest.java    From sqlg with MIT License 6 votes vote down vote up
@Before
public void before() throws Exception {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    this.sqlgGraph = SqlgGraph.open(configuration);
    SqlgUtil.dropDb(this.sqlgGraph);
    this.sqlgGraph.tx().commit();
    this.sqlgGraph.close();
    this.sqlgGraph = SqlgGraph.open(configuration);
    grantReadOnlyUserPrivileges();
    assertNotNull(this.sqlgGraph);
    assertNotNull(this.sqlgGraph.getBuildVersion());
    this.gt = this.sqlgGraph.traversal();
    if (configuration.getBoolean("distributed", false)) {
        this.sqlgGraph1 = SqlgGraph.open(configuration);
        assertNotNull(this.sqlgGraph1);
        assertEquals(this.sqlgGraph.getBuildVersion(), this.sqlgGraph1.getBuildVersion());
    }
    stopWatch.stop();
    logger.info("Startup time for test = " + stopWatch.toString());
}
 
Example #4
Source File: AbstractUnstatefullJob.java    From liteflow with Apache License 2.0 6 votes vote down vote up
public void execute(){
    try {
        if(isRunning.get()){
            return;
        }
        isRunning.set(true);
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        LOG.info("job start");
        executeInternal();
        LOG.info("job finished, takes {} ms", stopWatch.getTime());
    } catch (Exception e) {
        LOG.error("run error", e);
    }finally{
        isRunning.set(false);
    }
}
 
Example #5
Source File: TestBatchStreamEdge.java    From sqlg with MIT License 6 votes vote down vote up
private ArrayList<SqlgVertex> createMilCarVertex() {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    ArrayList<SqlgVertex> result = new ArrayList<>();
    this.sqlgGraph.tx().normalBatchModeOn();
    for (int i = 1; i < NUMBER_OF_VERTICES + 1; i++) {
        Map<String, Object> keyValue = new LinkedHashMap<>();
        for (int j = 0; j < 100; j++) {
            keyValue.put("name" + j, "aaaaaaaaaa" + i);
        }
        SqlgVertex car = (SqlgVertex) this.sqlgGraph.addVertex("Car", keyValue);
        result.add(car);
        if (i % (NUMBER_OF_VERTICES / 10) == 0) {
            this.sqlgGraph.tx().commit();
            this.sqlgGraph.tx().normalBatchModeOn();
        }
    }
    this.sqlgGraph.tx().commit();
    stopWatch.stop();
    System.out.println("createMilCarVertex took " + stopWatch.toString());
    return result;
}
 
Example #6
Source File: LogisticLoss.java    From pyramid with Apache License 2.0 6 votes vote down vote up
private void updatePredictedCounts(){
    StopWatch stopWatch = new StopWatch();
    if (logger.isDebugEnabled()){
        stopWatch.start();
    }
    IntStream intStream;
    if (isParallel){
        intStream = IntStream.range(0,numParameters).parallel();
    } else {
        intStream = IntStream.range(0,numParameters);
    }

    intStream.forEach(i -> this.predictedCounts.set(i, calPredictedCount(i)));
    if (logger.isDebugEnabled()){
        logger.debug("time spent on updatePredictedCounts = "+stopWatch);
    }
}
 
Example #7
Source File: IndyRepositorySession.java    From pnc with Apache License 2.0 6 votes vote down vote up
@Override
public void deleteBuildGroup() throws RepositoryManagerException {
    logger.info("BEGIN: Removing build aggregation group: {}", buildContentId);
    userLog.info("Removing build aggregation group");
    StopWatch stopWatch = StopWatch.createStarted();

    try {
        StoreKey key = new StoreKey(packageType, StoreType.group, buildContentId);
        serviceAccountIndy.stores().delete(key, "[Post-Build] Removing build aggregation group: " + buildContentId);
    } catch (IndyClientException e) {
        throw new RepositoryManagerException(
                "Failed to retrieve Indy stores module. Reason: %s",
                e,
                e.getMessage());
    }
    logger.info(
            "END: Removing build aggregation group: {}, took: {} seconds",
            buildContentId,
            stopWatch.getTime(TimeUnit.SECONDS));
    stopWatch.reset();
}
 
Example #8
Source File: ErrataManagerTest.java    From uyuni with GNU General Public License v2.0 6 votes vote down vote up
public void xxxxLookupErrataByAdvisoryType() throws IOException {

        String bugfix = "Bug Fix Advisory";
        String pea = "Product Enhancement Advisory";
        String security = "Security Advisory";

        StopWatch st = new StopWatch();
        st.start();
        List erratas = ErrataManager.lookupErrataByType(bugfix);
        outputErrataList(erratas);
        System.out.println("Got bugfixes: "  + erratas.size() + " time: " + st);
        assertTrue(erratas.size() > 0);
        erratas = ErrataManager.lookupErrataByType(pea);
        outputErrataList(erratas);
        System.out.println("Got pea enhancments: "  + erratas.size() + " time: " + st);
        assertTrue(erratas.size() > 0);
        erratas = ErrataManager.lookupErrataByType(security);
        outputErrataList(erratas);
        assertTrue(erratas.size() > 0);
        System.out.println("Got security advisories: "  + erratas.size() + " time: " + st);
        st.stop();
        System.out.println("TIME: " + st.getTime());
    }
 
Example #9
Source File: IndyRepositorySession.java    From pnc with Apache License 2.0 6 votes vote down vote up
/**
 * Promote all build dependencies NOT ALREADY CAPTURED to the hosted repository holding store for the shared imports
 * and return dependency artifacts meta data.
 *
 * @param report The tracking report that contains info about artifacts downloaded by the build
 * @param promote flag if collected dependencies should be promoted
 * @return List of dependency artifacts meta data
 * @throws RepositoryManagerException In case of a client API transport error or an error during promotion of
 *         artifacts
 * @throws PromotionValidationException when the promotion process results in an error due to validation failure
 */
private List<Artifact> processDownloads(final TrackedContentDTO report, final boolean promote)
        throws RepositoryManagerException, PromotionValidationException {
    List<Artifact> deps;

    logger.info("BEGIN: Process artifacts downloaded by build");
    userLog.info("Processing dependencies");
    StopWatch stopWatch = StopWatch.createStarted();

    Set<TrackedContentEntryDTO> downloads = report.getDownloads();
    if (CollectionUtils.isEmpty(downloads)) {
        deps = Collections.emptyList();
    } else {
        deps = collectDownloadedArtifacts(report);

        if (promote) {
            Map<StoreKey, Map<StoreKey, Set<String>>> depMap = collectDownloadsPromotionMap(downloads);
            promoteDownloads(depMap);
        }
    }

    logger.info("END: Process artifacts downloaded by build, took {} seconds", stopWatch.getTime(TimeUnit.SECONDS));
    return deps;
}
 
Example #10
Source File: ElasticSearchServer.java    From vind with Apache License 2.0 6 votes vote down vote up
private IndexResult indexSingleDocument(Document doc, int withinMs) {
    log.warn("Parameter 'within' not in use in elastic search backend");
    final StopWatch elapsedTime = StopWatch.createStarted();
    final Map<String,Object> document = DocumentUtil.createInputDocument(doc);

    try {
        if (elasticClientLogger.isTraceEnabled()) {
            elasticClientLogger.debug(">>> add({})", doc.getId());
        } else {
            elasticClientLogger.debug(">>> add({})", doc.getId());
        }

        final BulkResponse response = this.elasticSearchClient.add(document);
        elapsedTime.stop();
        return new IndexResult(response.getTook().getMillis()).setElapsedTime(elapsedTime.getTime());

    } catch (ElasticsearchException | IOException e) {
        log.error("Cannot index document {}", document.get(FieldUtil.ID) , e);
        throw new SearchServerException("Cannot index document", e);
    }
}
 
Example #11
Source File: ElasticSearchServer.java    From vind with Apache License 2.0 6 votes vote down vote up
@Override
public GetResult execute(RealTimeGet search, DocumentFactory assets) {
    try {
        final StopWatch elapsedTime = StopWatch.createStarted();
        final MultiGetResponse response = elasticSearchClient.realTimeGet(search.getValues());
        elapsedTime.stop();

        if(response!=null){
            return ResultUtils.buildRealTimeGetResult(response, search, assets, elapsedTime.getTime()).setElapsedTime(elapsedTime.getTime());
        }else {
            log.error("Null result from ElasticClient");
            throw new SearchServerException("Null result from ElasticClient");
        }

    } catch (ElasticsearchException | IOException e) {
        log.error("Cannot execute realTime get query");
        throw new SearchServerException("Cannot execute realTime get query", e);
    }
}
 
Example #12
Source File: ENRecoverCBMOptimizer.java    From pyramid with Apache License 2.0 6 votes vote down vote up
@Override
protected void updateBinaryClassifier(int component, int label, MultiLabelClfDataSet activeDataset, double[] activeGammas) {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();

    if (cbm.binaryClassifiers[component][label] == null || cbm.binaryClassifiers[component][label] instanceof PriorProbClassifier){
        cbm.binaryClassifiers[component][label] = new LogisticRegression(2, activeDataset.getNumFeatures());
    }


    int[] binaryLabels = DataSetUtil.toBinaryLabels(activeDataset.getMultiLabels(), label);
    double[][] targetsDistribution = DataSetUtil.labelsToDistributions(binaryLabels, 2);
    // no parallelism
    ElasticNetLogisticTrainer elasticNetLogisticTrainer = new ElasticNetLogisticTrainer.Builder((LogisticRegression)
            cbm.binaryClassifiers[component][label],  activeDataset, 2, targetsDistribution, activeGammas)
            .setRegularization(regularizationBinary)
            .setL1Ratio(l1RatioBinary)
            .setLineSearch(lineSearch).build();
    elasticNetLogisticTrainer.setActiveSet(activeSet);
    elasticNetLogisticTrainer.getTerminator().setMaxIteration(this.binaryUpdatesPerIter);
    elasticNetLogisticTrainer.optimize();
    if (logger.isDebugEnabled()){
        logger.debug("time spent on updating component "+component+" label "+label+" = "+stopWatch);
    }
}
 
Example #13
Source File: TestBatch.java    From sqlg with MIT License 6 votes vote down vote up
@Test
public void testVerticesBatchOn() throws InterruptedException {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    this.sqlgGraph.tx().normalBatchModeOn();
    for (int i = 0; i < 10000; i++) {
        Vertex v1 = this.sqlgGraph.addVertex(T.label, "MO1", "name", "marko" + i);
        Vertex v2 = this.sqlgGraph.addVertex(T.label, "Person", "name", "marko" + i);
        v1.addEdge("Friend", v2, "name", "xxx");
    }
    this.sqlgGraph.tx().commit();
    stopWatch.stop();
    System.out.println(stopWatch.toString());
    testVerticesBatchOn_assert(this.sqlgGraph);
    if (this.sqlgGraph1 != null) {
        Thread.sleep(1000);
        testVerticesBatchOn_assert(this.sqlgGraph1);
    }
}
 
Example #14
Source File: LKTreeBoostTest.java    From pyramid with Apache License 2.0 6 votes vote down vote up
/**
 * second stage
 * @throws Exception
 */
static void spam_resume_train_2() throws Exception{
    System.out.println("loading ensemble");
    LKBoost lkBoost = LKBoost.deserialize(new File(TMP, "/LKTreeBoostTest/ensemble.ser"));

    ClfDataSet dataSet = TRECFormat.loadClfDataSet(new File(DATASETS,"spam/trec_data/train.trec"),
            DataSetType.CLF_DENSE,true);

    LKBoostOptimizer trainer = new LKBoostOptimizer(lkBoost,dataSet);
    trainer.initialize();

    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    for (int round =50;round<100;round++){
        System.out.println("round="+round);
        trainer.iterate();
    }
    stopWatch.stop();
    System.out.println(stopWatch);


    double accuracy = Accuracy.accuracy(lkBoost,dataSet);
    System.out.println(accuracy);

}
 
Example #15
Source File: TestCellBlockBuilder.java    From hbase with Apache License 2.0 6 votes vote down vote up
private static void timerTests(final CellBlockBuilder builder, final int count, final int size,
    final Codec codec, final CompressionCodec compressor) throws IOException {
  final int cycles = 1000;
  StopWatch timer = new StopWatch();
  timer.start();
  for (int i = 0; i < cycles; i++) {
    timerTest(builder, timer, count, size, codec, compressor, false);
  }
  timer.stop();
  LOG.info("Codec=" + codec + ", compression=" + compressor + ", sized=" + false + ", count="
      + count + ", size=" + size + ", + took=" + timer.getTime() + "ms");
  timer.reset();
  timer.start();
  for (int i = 0; i < cycles; i++) {
    timerTest(builder, timer, count, size, codec, compressor, true);
  }
  timer.stop();
  LOG.info("Codec=" + codec + ", compression=" + compressor + ", sized=" + true + ", count="
      + count + ", size=" + size + ", + took=" + timer.getTime() + "ms");
}
 
Example #16
Source File: OperationStats.java    From soundwave with Apache License 2.0 5 votes vote down vote up
public OperationStats(String methodName, String statsName, Map<String, String> tags) {
  this.methodName = methodName;
  this.statsName = statsName;
  this.tags = tags;
  Stats.incr(StatsUtil.getStatsName(methodName, statsName, tags));
  watch = new StopWatch();
  watch.start();
}
 
Example #17
Source File: EntityIndexTest.java    From usergrid with Apache License 2.0 5 votes vote down vote up
private CandidateResults testQuery( final SearchEdge scope, final SearchTypes searchTypes,
                                  final String queryString,
                                    final int num ) {

    StopWatch timer = new StopWatch();
    timer.start();
    CandidateResults candidateResults  = entityIndex.search( scope, searchTypes, queryString, 1000, 0, false );

    timer.stop();

    assertEquals(num, candidateResults.size());
    logger.debug("Query time {}ms", timer.getTime());
    return candidateResults;
}
 
Example #18
Source File: ElasticNetLogisticTrainerTest.java    From pyramid with Apache License 2.0 5 votes vote down vote up
private static void test5() throws Exception{
    ClfDataSet dataSet = TRECFormat.loadClfDataSet(new File(DATASETS, "/cnn/4/train.trec"),
            DataSetType.CLF_SPARSE, true);
    ClfDataSet testSet = TRECFormat.loadClfDataSet(new File(DATASETS, "/cnn/4/test.trec"),
            DataSetType.CLF_SPARSE, true);
    System.out.println(dataSet.getMetaInfo());
    LogisticRegression logisticRegression = new LogisticRegression(dataSet.getNumClasses(),dataSet.getNumFeatures());

    Comparator<Double> comparator = Comparator.comparing(Double::doubleValue);
    List<Double> lambdas = Grid.logUniform(0.00000001, 0.1, 100).stream().sorted(comparator.reversed()).collect(Collectors.toList());

    for (double lambda: lambdas){
        ElasticNetLogisticTrainer trainer = ElasticNetLogisticTrainer.newBuilder(logisticRegression, dataSet)
                .setEpsilon(0.01).setL1Ratio(1).setRegularization(lambda).build();

        System.out.println("=================================");
        System.out.println("lambda = "+lambda);
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        trainer.optimize();
        System.out.println(stopWatch);
        System.out.println("training accuracy = "+ Accuracy.accuracy(logisticRegression,dataSet));
        System.out.println("test accuracy = "+ Accuracy.accuracy(logisticRegression,testSet));
        System.out.println("number of non-zeros= "+logisticRegression.getWeights().getAllWeights().getNumNonZeroElements());
    }

}
 
Example #19
Source File: Hierarchy.java    From mobi with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Writes the {@link Model} of hierarchy relationships as JSON-LD in a hierarchical view to the provided
 * {@link OutputStream}.
 *
 * @param transformer A {@link SesameTransformer} to utilize when writing the JSON-LD
 * @param outputStream The {@link OutputStream} to write the hierarchy string to
 */
public void writeHierarchyString(SesameTransformer transformer, OutputStream outputStream) {
    StopWatch watch = new StopWatch();
    LOG.trace("Start writing hierarchy JSON-LD");
    watch.start();
    RDFWriter writer = Rio.createWriter(RDFFormat.JSONLD, outputStream);
    writer.getWriterConfig().set(JSONLDSettings.HIERARCHICAL_VIEW, true);
    Rio.write(transformer.sesameModel(getModel()), writer);
    watch.stop();
    LOG.trace("End writing hierarchy JSON-LD: " + watch.getTime() + "ms");
}
 
Example #20
Source File: RidgeLogisticOptimizerTest.java    From pyramid with Apache License 2.0 5 votes vote down vote up
private static void test4() throws Exception{
//        ClfDataSet dataSet = TRECFormat.loadClfDataSet(new File(DATASETS, "/imdb/3/train.trec"),
//                DataSetType.CLF_SPARSE, true);
//        ClfDataSet testSet = TRECFormat.loadClfDataSet(new File(DATASETS, "/imdb/3/test.trec"),
//                DataSetType.CLF_SPARSE, true);
        ClfDataSet dataSet = TRECFormat.loadClfDataSet(new File(DATASETS, "20newsgroup/1/train.trec"),
                DataSetType.CLF_SPARSE, true);
        ClfDataSet testSet = TRECFormat.loadClfDataSet(new File(DATASETS, "20newsgroup/1/test.trec"),
                DataSetType.CLF_SPARSE, true);
//        ClfDataSet dataSet = TRECFormat.loadClfDataSet(new File(DATASETS, "/spam/trec_data/train.trec"),
//                DataSetType.CLF_SPARSE, true);
//        ClfDataSet testSet = TRECFormat.loadClfDataSet(new File(DATASETS, "/spam/trec_data/test.trec"),
//                DataSetType.CLF_SPARSE, true);
        double variance =1000;
        LogisticRegression logisticRegression = new LogisticRegression(dataSet.getNumClasses(),dataSet.getNumFeatures());
        double[] weights = new double[dataSet.getNumDataPoints()];
        for (int i=0;i<weights.length;i++){
            if (Math.random()<0.1){
                weights[i] = 0;
            } else {
                weights[i] = 1;
            }
        }
        RidgeLogisticOptimizer optimizer = new RidgeLogisticOptimizer(logisticRegression, dataSet, dataSet.getLabels(),weights, variance, true);
        System.out.println("after initialization");
        System.out.println("train acc = " + Accuracy.accuracy(logisticRegression, dataSet));
        System.out.println("test acc = "+Accuracy.accuracy(logisticRegression,testSet));
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        for (int i=0;i<20;i++){
            ((LBFGS)optimizer.getOptimizer()).iterate();
            System.out.println("after iteration "+i);
            System.out.println(stopWatch);
//            System.out.println("train acc = " + Accuracy.accuracy(logisticRegression, dataSet));
//            System.out.println("test acc = "+Accuracy.accuracy(logisticRegression,testSet));
//            System.out.println(logisticRegression);
        }

    }
 
Example #21
Source File: NodeComponent.java    From liteFlow with Apache License 2.0 5 votes vote down vote up
public void execute() throws Exception{
	Slot slot = this.getSlot();
	LOG.info("[{}]:[O]start component[{}] execution",slot.getRequestId(),this.getClass().getSimpleName());
	slot.addStep(new CmpStep(nodeId, CmpStepType.START));
	StopWatch stopWatch = new StopWatch();
	stopWatch.start();

	process();

	stopWatch.stop();
	long timeSpent = stopWatch.getTime();

	slot.addStep(new CmpStep(nodeId, CmpStepType.END));

	//性能统计
	CompStatistics statistics = new CompStatistics();
	statistics.setComponentClazzName(this.getClass().getSimpleName());
	statistics.setTimeSpent(timeSpent);
	MonitorBus.load().addStatistics(statistics);


	if(this instanceof NodeCondComponent){
		String condNodeId = slot.getCondResult(this.getClass().getName());
		if(StringUtils.isNotBlank(condNodeId)){
			Node thisNode = FlowBus.getNode(nodeId);
			Node condNode = thisNode.getCondNode(condNodeId);
			if(condNode != null){
				NodeComponent condComponent = condNode.getInstance();
				condComponent.setSlotIndex(slotIndexTL.get());
				condComponent.execute();
			}
		}
	}

	LOG.debug("[{}]:componnet[{}] finished in {} milliseconds",slot.getRequestId(),this.getClass().getSimpleName(),timeSpent);
}
 
Example #22
Source File: ElasticSearchServer.java    From vind with Apache License 2.0 5 votes vote down vote up
@Override
public DeleteResult execute(Delete delete, DocumentFactory factory) {
    try {
        final StopWatch elapsedTime = StopWatch.createStarted();
        elasticClientLogger.debug(">>> delete({})", delete);
        final QueryBuilder deleteQuery = ElasticQueryBuilder.buildFilterQuery(delete.getQuery(), factory, delete.getUpdateContext());
        final BulkByScrollResponse response = elasticSearchClient.deleteByQuery(deleteQuery);
        elapsedTime.stop();
        return new DeleteResult(response.getTook().getMillis()).setElapsedTime(elapsedTime.getTime());
    } catch (ElasticsearchException | IOException e) {
        log.error("Cannot delete with query {}", delete.getQuery() , e);
        throw new SearchServerException(
                String.format("Cannot delete with query %s", delete.getQuery().toString()), e);
    }
}
 
Example #23
Source File: SlimFixture.java    From hsac-fitnesse-fixtures with Apache License 2.0 5 votes vote down vote up
private int getNextInterval(StopWatch loopTimer) {
    int nextInterval;
    long loopTime = loopTimer.getTime();
    nextInterval = Math.max(0, ((int) (repeatInterval - loopTime)));
    loopTimer.reset();
    return nextInterval;
}
 
Example #24
Source File: ESMessageListener.java    From elastic-rabbitmq with MIT License 5 votes vote down vote up
private void handleMsg(ESHandleMessage message) {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    boolean successful = false;

    lightLogger.info("ES sync start on ESHandleMessage " + message.toString());
    ESHandler handler = null;
    try {
        handler = handlerManager.getHandler(message);
        if (handler == null) {
            lightLogger.info("Handler is null for message" + message.toString());
            return;
        }

        handler.onMessage(message);

        successful = true;
    } catch (Throwable t) {
        successful = false;
        throw t;
    } finally {
        stopWatch.stop();
        String metricName = message.getClass().getSimpleName() + "." + handler.getClass().getSimpleName();
        //counterService.increment(metricName + "." + (successful ? ".success" : "failed"));
        //gaugeService.submit(metricName, stopWatch.getTime());
        lightLogger.info("ES sync end on execTime[" + stopWatch.getTime() + "]");
    }
}
 
Example #25
Source File: GenericControllerAspect.java    From controller-logger with Apache License 2.0 5 votes vote down vote up
@Around("allPublicControllerMethodsPointcut() "
        + "&& methodLoggingNotDisabledPointcut() "
        + "&& methodOrClassLoggingEnabledPointcut()")
@Nullable
public Object log(@Nonnull ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    Object result = null;
    String returnType = null;
    RequestMapping methodRequestMapping = null;
    RequestMapping classRequestMapping = null;

    try {
        MethodSignature methodSignature = (MethodSignature)proceedingJoinPoint.getSignature();
        methodRequestMapping = methodSignature.getMethod().getAnnotation(RequestMapping.class);
        classRequestMapping = proceedingJoinPoint.getTarget().getClass().getAnnotation(RequestMapping.class);

        // this is required to distinguish between a returned value of null and no return value, as in case of
        // void return type.
        returnType = methodSignature.getReturnType().getName();

        logPreExecutionData(proceedingJoinPoint, methodRequestMapping);
    } catch (Exception e) {
        LOG.error("Exception occurred in pre-proceed logic", e);
    }

    StopWatch timer = new StopWatch();
    try {
        timer.start();
        result = proceedingJoinPoint.proceed();
    } finally {
        timer.stop();
        if (returnType != null) {
            logPostExecutionData(
                    proceedingJoinPoint, timer, result, returnType, methodRequestMapping, classRequestMapping
            );
        }
    }

    return result;
}
 
Example #26
Source File: DBRefPopulatorRunner.java    From gazpachoquest with GNU General Public License v3.0 5 votes vote down vote up
public static void main(final String... args) {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("dbpopulator-ref-datasource-context.xml",
            "dbpopulator-jpa-context.xml", "services-context.xml", "facades-context.xml", "components-context.xml");
    DBPopulator populator = ctx.getBean(DBPopulator.class);
    StopWatch stopWatch = new StopWatch();
    logger.info("Populating database");
    stopWatch.start();
    ShiroLogin.login();
    populator.populate();
    stopWatch.stop();
    ShiroLogin.logout();
    logger.info("Database populated in {} {}", stopWatch.getTime(), "ms");

    ctx.close();
}
 
Example #27
Source File: CBMEN.java    From pyramid with Apache License 2.0 5 votes vote down vote up
private static void reportAccPrediction(Config config, CBM cbm, MultiLabelClfDataSet dataSet, String name) throws Exception{
    System.out.println("============================================================");
    System.out.println("Making predictions on "+name +" set with the instance set accuracy optimal predictor");
    String output = config.getString("output.dir");
    AccPredictor accPredictor = new AccPredictor(cbm);
    accPredictor.setComponentContributionThreshold(config.getDouble("predict.piThreshold"));
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    MultiLabel[] predictions = accPredictor.predict(dataSet);
    System.out.println("time spent on prediction = "+stopWatch);
    MLMeasures mlMeasures = new MLMeasures(dataSet.getNumClasses(),dataSet.getMultiLabels(),predictions);
    System.out.println(name+" performance with the instance set accuracy optimal predictor");
    System.out.println(mlMeasures);
    File performanceFile = Paths.get(output,name+"_predictions", "instance_accuracy_optimal","performance.txt").toFile();
    FileUtils.writeStringToFile(performanceFile, mlMeasures.toString());
    System.out.println(name+" performance is saved to "+performanceFile.toString());


    // Here we do not use approximation
    double[] setProbs = IntStream.range(0, predictions.length).parallel().
            mapToDouble(i->cbm.predictAssignmentProb(dataSet.getRow(i),predictions[i])).toArray();
    File predictionFile = Paths.get(output,name+"_predictions", "instance_accuracy_optimal","predictions.txt").toFile();
    try (BufferedWriter br = new BufferedWriter(new FileWriter(predictionFile))){
        for (int i=0;i<dataSet.getNumDataPoints();i++){
            br.write(predictions[i].toString());
            br.write(":");
            br.write(""+setProbs[i]);
            br.newLine();
        }
    }

    System.out.println("predicted sets and their probabilities are saved to "+predictionFile.getAbsolutePath());

    boolean individualPerformance = true;
    if (individualPerformance){
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.writeValue(Paths.get(output,name+"_predictions", "instance_accuracy_optimal","individual_performance.json").toFile(),mlMeasures.getMacroAverage());
    }
    System.out.println("============================================================");
}
 
Example #28
Source File: TestBulkWithin.java    From sqlg with MIT License 5 votes vote down vote up
@Test
public void testBulkWithinWithPercentageInJoinProperties() throws InterruptedException {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    if (this.sqlgGraph.getSqlDialect().supportsBatchMode()) {
        this.sqlgGraph.tx().normalBatchModeOn();
    }
    Vertex god = this.sqlgGraph.addVertex(T.label, "God");
    List<String> uuids = new ArrayList<>();
    for (int i = 0; i < 100; i++) {
        String uuid = UUID.randomUUID().toString();
        uuids.add("\"BLRNC5->CXC4030052~%%%~FAJ1211373~%%%~2015-07-19~%%%~9999-12-31~%%%~Enabled~%%%~Licensed~%%%~Improved~%%%~compressed~%%%~mode~%%%~handling.~%%%~Restricted:~%%%~\"\"Partial.~%%%~Feature~%%%~is~%%%~restricted~%%%~in~%%%~RNC~%%%~W12B~%%%~SW.~%%%~RNC~%%%~W13.0.1.1~%%%~or~%%%~later~%%%~SW~%%%~is~%%%~required~%%%~in~%%%~order~%%%~to~%%%~run~%%%~this~%%%~feature.~%%%~For~%%%~RBS~%%%~W12.1.2.2/~%%%~W13.0.0.0~%%%~or~%%%~later~%%%~is~%%%~required.~%%%~OSS-RC~%%%~12.2~%%%~or~%%%~later~%%%~is~%%%~required.\"\".~%%%~GA:~%%%~W13A\"" + uuid);
        Vertex person = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", "\"BLRNC5->CXC4030052~%%%~FAJ1211373~%%%~2015-07-19~%%%~9999-12-31~%%%~Enabled~%%%~Licensed~%%%~Improved~%%%~compressed~%%%~mode~%%%~handling.~%%%~Restricted:~%%%~\"\"Partial.~%%%~Feature~%%%~is~%%%~restricted~%%%~in~%%%~RNC~%%%~W12B~%%%~SW.~%%%~RNC~%%%~W13.0.1.1~%%%~or~%%%~later~%%%~SW~%%%~is~%%%~required~%%%~in~%%%~order~%%%~to~%%%~run~%%%~this~%%%~feature.~%%%~For~%%%~RBS~%%%~W12.1.2.2/~%%%~W13.0.0.0~%%%~or~%%%~later~%%%~is~%%%~required.~%%%~OSS-RC~%%%~12.2~%%%~or~%%%~later~%%%~is~%%%~required.\"\".~%%%~GA:~%%%~W13A\"" + uuid);
        god.addEdge("creator", person);
    }
    this.sqlgGraph.tx().commit();
    stopWatch.stop();
    System.out.println(stopWatch.toString());
    stopWatch.reset();
    stopWatch.start();
    testBulkWithinWithPercentageInJoinProperties_assert(this.sqlgGraph, uuids);
    if (this.sqlgGraph1 != null) {
        Thread.sleep(SLEEP_TIME);
        testBulkWithinWithPercentageInJoinProperties_assert(this.sqlgGraph1, uuids);
    }
    stopWatch.stop();
    System.out.println(stopWatch.toString());
}
 
Example #29
Source File: FetchExecutionRangeAccumulator.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
public FetchExecutionRangeAccumulator(String partitionKeyRangeId) {
    this.partitionKeyRangeId = partitionKeyRangeId;
    this.constructionTime = Instant.now();
    // This stopwatch is always running and is only used to calculate deltas that are synchronized with the construction time.
    this.stopwatch = new StopWatch();
    stopwatch.start();
    this.fetchExecutionRanges = new ArrayList<FetchExecutionRange>();
}
 
Example #30
Source File: CustomMetaDataRetrieverImpl.java    From components with Apache License 2.0 5 votes vote down vote up
public List<NsRef> retrieveCustomizationIds(final BasicRecordType type) throws NetSuiteException {
    GetCustomizationIdResult result = clientService.execute(new NetSuiteClientService.PortOperation<GetCustomizationIdResult, NetSuitePortType>() {
        @Override public GetCustomizationIdResult execute(NetSuitePortType port) throws Exception {
            logger.debug("Retrieving customization IDs: {}", type.getType());
            StopWatch stopWatch = new StopWatch();
            try {
                stopWatch.start();
                final GetCustomizationIdRequest request = new GetCustomizationIdRequest();
                CustomizationType customizationType = new CustomizationType();
                customizationType.setGetCustomizationType(GetCustomizationType.fromValue(type.getType()));
                request.setCustomizationType(customizationType);
                return port.getCustomizationId(request).getGetCustomizationIdResult();
            } finally {
                stopWatch.stop();
                logger.debug("Retrieved customization IDs: {}, {}", type.getType(), stopWatch);
            }
        }
    });
    if (result.getStatus().getIsSuccess()) {
        List<NsRef> nsRefs;
        if (result.getTotalRecords() > 0) {
            final List<CustomizationRef> refs = result.getCustomizationRefList().getCustomizationRef();
            nsRefs = new ArrayList<>(refs.size());
            for (final CustomizationRef ref : refs) {
                NsRef nsRef = new NsRef();
                nsRef.setRefType(RefType.CUSTOMIZATION_REF);
                nsRef.setScriptId(ref.getScriptId());
                nsRef.setInternalId(ref.getInternalId());
                nsRef.setType(ref.getType().value());
                nsRef.setName(ref.getName());
                nsRefs.add(nsRef);
            }
        } else {
            nsRefs = Collections.emptyList();
        }
        return nsRefs;
    } else {
        throw new NetSuiteException("Retrieving of customizations was not successful: " + type);
    }
}