org.springframework.util.StopWatch.prettyPrint()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(281)

本文整理了Java中org.springframework.util.StopWatch.prettyPrint()方法的一些代码示例,展示了StopWatch.prettyPrint()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StopWatch.prettyPrint()方法的具体详情如下:
包路径:org.springframework.util.StopWatch
类名称:StopWatch
方法名:prettyPrint

StopWatch.prettyPrint介绍

[英]Return a string with a table describing all tasks performed. For custom reporting, call getTaskInfo() and use the task info directly.
[中]返回一个字符串,其中包含一个描述所有已执行任务的表。对于自定义报告,请调用getTaskInfo()并直接使用任务信息。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Test
@Ignore("Intended for use during development only")
public void shouldBeFasterThanSynchronizedMap() throws InterruptedException {
  Map<Integer, WeakReference<String>> synchronizedMap = Collections.synchronizedMap(new WeakHashMap<Integer, WeakReference<String>>());
  StopWatch mapTime = timeMultiThreaded("SynchronizedMap", synchronizedMap, v -> new WeakReference<>(String.valueOf(v)));
  System.out.println(mapTime.prettyPrint());
  this.map.setDisableTestHooks(true);
  StopWatch cacheTime = timeMultiThreaded("WeakConcurrentCache", this.map, String::valueOf);
  System.out.println(cacheTime.prettyPrint());
  // We should be at least 4 time faster
  assertThat(cacheTime.getTotalTimeSeconds(), is(lessThan(mapTime.getTotalTimeSeconds() / 4.0)));
}

代码示例来源:origin: spring-projects/spring-framework

private long testRepeatedAroundAdviceInvocations(String file, int howmany, String technology) {
  ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
  StopWatch sw = new StopWatch();
  sw.start(howmany + " repeated around advice invocations with " + technology);
  ITestBean adrian = (ITestBean) bf.getBean("adrian");
  assertTrue(AopUtils.isAopProxy(adrian));
  assertEquals(68, adrian.getAge());
  for (int i = 0; i < howmany; i++) {
    adrian.getAge();
  }
  sw.stop();
  System.out.println(sw.prettyPrint());
  return sw.getLastTaskTimeMillis();
}

代码示例来源:origin: spring-projects/spring-framework

private long testAfterReturningAdviceWithoutJoinPoint(String file, int howmany, String technology) {
  ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
  StopWatch sw = new StopWatch();
  sw.start(howmany + " repeated after returning advice invocations with " + technology);
  ITestBean adrian = (ITestBean) bf.getBean("adrian");
  assertTrue(AopUtils.isAopProxy(adrian));
  Advised a = (Advised) adrian;
  assertTrue(a.getAdvisors().length >= 3);
  // Hits joinpoint
  adrian.setAge(25);
  for (int i = 0; i < howmany; i++) {
    adrian.setAge(i);
  }
  sw.stop();
  System.out.println(sw.prettyPrint());
  return sw.getLastTaskTimeMillis();
}

代码示例来源:origin: spring-projects/spring-framework

private long testBeforeAdviceWithoutJoinPoint(String file, int howmany, String technology) {
  ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
  StopWatch sw = new StopWatch();
  sw.start(howmany + " repeated before advice invocations with " + technology);
  ITestBean adrian = (ITestBean) bf.getBean("adrian");
  assertTrue(AopUtils.isAopProxy(adrian));
  Advised a = (Advised) adrian;
  assertTrue(a.getAdvisors().length >= 3);
  assertEquals("adrian", adrian.getName());
  for (int i = 0; i < howmany; i++) {
    adrian.getName();
  }
  sw.stop();
  System.out.println(sw.prettyPrint());
  return sw.getLastTaskTimeMillis();
}

代码示例来源:origin: spring-projects/spring-framework

private long testMix(String file, int howmany, String technology) {
  ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
  StopWatch sw = new StopWatch();
  sw.start(howmany + " repeated mixed invocations with " + technology);
  ITestBean adrian = (ITestBean) bf.getBean("adrian");
  assertTrue(AopUtils.isAopProxy(adrian));
  Advised a = (Advised) adrian;
  assertTrue(a.getAdvisors().length >= 3);
  for (int i = 0; i < howmany; i++) {
    // Hit all 3 joinpoints
    adrian.getAge();
    adrian.getName();
    adrian.setAge(i);
    // Invoke three non-advised methods
    adrian.getDoctor();
    adrian.getLawyer();
    adrian.getSpouse();
  }
  sw.stop();
  System.out.println(sw.prettyPrint());
  return sw.getLastTaskTimeMillis();
}

代码示例来源:origin: spring-projects/spring-framework

String pp = sw.prettyPrint();
assertTrue(pp.contains("kept"));

代码示例来源:origin: spring-projects/spring-framework

String pp = sw.prettyPrint();
assertTrue(pp.contains(name1));
assertTrue(pp.contains(name2));

代码示例来源:origin: spring-projects/spring-framework

System.out.println(sw.prettyPrint());

代码示例来源:origin: net.oschina.zcx7878/cicada.boot-web

StringBuffer getEnd(StringBuffer sb, StopWatch sw)
  {
    sb.insert(0, "\r\n" + sw.prettyPrint());
    sb.append("\r\n");
    sb.append("-----------------------------------------");
    return sb;
  }
}

代码示例来源:origin: net.oschina.zcx7878/cicada.web

StringBuffer getEnd(StringBuffer sb, StopWatch sw)
  {
    sb.insert(0, "\r\n" + sw.prettyPrint());
    sb.append("\r\n");
    sb.append("-----------------------------------------");
    return sb;
  }
}

代码示例来源:origin: uk.ac.ebi.intact.core/intact-core-readonly

public Object profile(ProceedingJoinPoint call) throws Throwable {
  Object returnValue;
  StopWatch clock = new StopWatch(getClass().getName());
  try {
   clock.start(call.toShortString());
   returnValue = call.proceed();
  } finally {
   clock.stop();
   System.out.println(clock.prettyPrint());
  }
  return returnValue;
 }
}

代码示例来源:origin: uk.ac.ebi.intact.core/intact-core

public Object profile(ProceedingJoinPoint call) throws Throwable {
  Object returnValue;
  StopWatch clock = new StopWatch(getClass().getName());
  try {
   clock.start(call.toShortString());
   returnValue = call.proceed();
  } finally {
   clock.stop();
   System.out.println(clock.prettyPrint());
  }
  return returnValue;
 }
}

代码示例来源:origin: kloiasoft/eventapis

@Override
public void run() {
  StopWatch stopWatch = new StopWatch();
  boolean isSuccess;
  try {
    isSuccess = runInternal(stopWatch);
    if (isSuccess) {
      metaMap.set(getLastSuccessKey(), System.currentTimeMillis());
    }
  } catch (InterruptedException | ExecutionException e) {
    log.warn("Error While trying to run ScheduledTask: " + e.getMessage(), e);
  }
  log.debug(stopWatch.prettyPrint());
}

代码示例来源:origin: org.dataconservancy.ui/dcs-ui-services-impl

public Object profile(ProceedingJoinPoint call) throws Throwable {
    Object returnValue;
    StopWatch clock = new StopWatch(getClass().getName());
    try {
      clock.start(call.toShortString());
      System.out.println(call.toLongString() + " - Start");
      returnValue = call.proceed();
    } finally {
      clock.stop();
      System.out.println(clock.prettyPrint());
    }
    return returnValue;
  }
}

代码示例来源:origin: kloiasoft/eventapis

@Override
boolean runInternal(StopWatch stopWatch) {
  stopWatch.start("collectEndOffsets");
  List<TopicPartition> collect = topicsMap.entrySet().stream().flatMap(
      topic -> topic.getValue().getPartitions().values().stream().map(partition -> new TopicPartition(topic.getKey(), partition.getNumber()))
  ).collect(Collectors.toList());
  java.util.Map<TopicPartition, Long> map = kafkaConsumer.endOffsets(collect);
  java.util.Map<String, List<Partition>> result = new HashMap<>();
  map.forEach((topicPartition, endOffset) -> {
    if (!result.containsKey(topicPartition.topic()))
      result.put(topicPartition.topic(), new ArrayList<>());
    result.get(topicPartition.topic()).add(new Partition(topicPartition.partition(), endOffset));
  });
  result.forEach((topic, endOffset) -> topicsMap.executeOnKey(topic, new EndOffsetSetter(endOffset)));
  log.debug("collectEndOffsets:" + result.toString());
  stopWatch.stop();
  log.debug("TopicEndOffsetSchedule:" + topicsMap.entrySet());
  log.debug(stopWatch.prettyPrint());
  return true;
}

代码示例来源:origin: kloiasoft/eventapis

@Override
boolean runInternal(StopWatch stopWatch) throws InterruptedException, ExecutionException {
  stopWatch.start("adminClient.listTopics()");
  Collection<String> topicNames = adminClient.listTopics().listings().get()
      .stream().map(TopicListing::name).filter(this::shouldCollectEvent).collect(Collectors.toList());
  topicsMap.removeAll(new RemoveTopicPredicate(topicNames));
  DescribeTopicsResult describeTopicsResult = adminClient.describeTopics(topicNames);
  describeTopicsResult.all().get().forEach(
      (topic, topicDescription) -> topicsMap.executeOnKey(topic, new SetTopicPartitionsProcessor(
          topicDescription.partitions().stream().map(TopicPartitionInfo::partition).collect(Collectors.toList()))
      )
  );
  metaMap.set(this.getName() + TopicServiceScheduler.LAST_SUCCESS_PREFIX, System.currentTimeMillis());
  log.debug("Topics:" + topicsMap.entrySet());
  log.debug(stopWatch.prettyPrint());
  return true;
}

代码示例来源:origin: arawn/building-serverless-application-with-spring-webflux

@Test
public void lookUpLocalHost() throws UnknownHostException, URISyntaxException {
  StopWatch stopWatch = new StopWatch();
  stopWatch.start();
  String hostName = InetAddress.getLocalHost().getHostName();
  stopWatch.stop();
  System.out.println(stopWatch.prettyPrint());;
  System.out.println(new URI("/test"));
}

代码示例来源:origin: e-biz/spring-dbunit

@Override
public void populate(Connection connection) throws SQLException {
  LOGGER.debug("populating");
  StopWatch sw = new StopWatch("DbUnitDatabasePopulator");
  DatabaseOperation operation = phase.getOperation(dataSetConfiguration);
  try {
    IDataSet dataSet = decorateDataSetIfNeeded(dataSetConfiguration.getDataSet(), dataSetConfiguration.getDecorators());
    String schema = dataSetConfiguration.getSchema();
    DatabaseConnection databaseConnection = getDatabaseConnection(connection, schema, dataSetConfiguration);
    sw.start("populating");
    operation.execute(databaseConnection, dataSet);
    sw.stop();
    LOGGER.debug(sw.prettyPrint());
  } catch (BatchUpdateException e) {
    LOGGER.error("BatchUpdateException while loading dataset", e);
    LOGGER.error("Caused by : ", e.getNextException());
    throw e;
  } catch (DatabaseUnitException e) {
    throw new DbUnitException(e);
  } catch (IOException e) {
    throw new DbUnitException(e);
  }
}

代码示例来源:origin: spring-projects/spring-ldap

@Test
public void testCreateFromString() {
  StopWatch stopWatch = new StopWatch("Create from String");
  stopWatch.start();
  for (int i = 0; i < 2000; i++) {
    DistinguishedName migpath = new DistinguishedName("OU=G,OU=I,OU=M");
    DistinguishedName path1 = new DistinguishedName("cn=john.doe, OU=Users,OU=SE,OU=G,OU=I,OU=M");
    DistinguishedName path2 = new DistinguishedName("cn=john.doe, OU=Users,OU=SE,ou=G,OU=i,OU=M, ou=foo");
    DistinguishedName path3 = new DistinguishedName("ou=G,OU=i,OU=M, ou=foo");
    DistinguishedName path4 = new DistinguishedName("ou=G,OU=i,ou=m");
    DistinguishedName pathE1 = new DistinguishedName("cn=john.doe, OU=Users,OU=SE,ou=G,OU=L,OU=M, ou=foo");
    DistinguishedName pathE2 = new DistinguishedName("cn=john.doe, OU=Users,OU=SE");
  }
  stopWatch.stop();
  System.out.println(stopWatch.prettyPrint());
}

代码示例来源:origin: spring-projects/spring-ldap

@Test
  public void testCreateFromDistinguishedName() {
    DistinguishedName migpath = new DistinguishedName("OU=G,OU=I,OU=M");
    DistinguishedName path1 = new DistinguishedName("cn=john.doe, OU=Users,OU=SE,OU=G,OU=I,OU=M");
    DistinguishedName path2 = new DistinguishedName("cn=john.doe, OU=Users,OU=SE,ou=G,OU=i,OU=M, ou=foo");
    DistinguishedName path3 = new DistinguishedName("ou=G,OU=i,OU=M, ou=foo");
    DistinguishedName path4 = new DistinguishedName("ou=G,OU=i,ou=m");

    DistinguishedName pathE1 = new DistinguishedName("cn=john.doe, OU=Users,OU=SE,ou=G,OU=L,OU=M, ou=foo");
    DistinguishedName pathE2 = new DistinguishedName("cn=john.doe, OU=Users,OU=SE");

    StopWatch stopWatch = new StopWatch("Create from DistinguishedName");
    stopWatch.start();
    
    for (int i = 0; i < 2000; i++) {
      migpath = new DistinguishedName(migpath);
      path1 = new DistinguishedName(path1);
      path2 = new DistinguishedName(path2);
      path3 = new DistinguishedName(path3);
      path4 = new DistinguishedName(path4);

      pathE1 = new DistinguishedName(pathE1);
      pathE2 = new DistinguishedName(pathE2);
    }

    stopWatch.stop();
    System.out.println(stopWatch.prettyPrint());
  }
}

相关文章