コード例 #1
0
  public static LinkedHashMap<String, Long> getTopData(List<ProcessTime> models, int top) {
    // 同一命令只留最耗时的命令
    models = mini(models);

    LinkedHashMap<Long, ProcessTime> LinkedHashMap = new LinkedHashMap<>();
    // 将日志数据转换为统计报表数据
    for (ProcessTime item : models) {
      LinkedHashMap.put(item.getProcessTime(), item);
    }
    Collection<Long> keys = LinkedHashMap.keySet();
    List<Long> list = new ArrayList<>();
    for (Long key : keys) {
      list.add(key);
    }
    Collections.sort(list);
    Collections.reverse(list);
    LinkedHashMap<String, Long> result = new LinkedHashMap<>();
    int i = 0;
    for (Long processTime : list) {
      String newKey =
          DateTypeConverter.toDefaultDateTime(LinkedHashMap.get(processTime).getStartTime())
              + ", "
              + LinkedHashMap.get(processTime).getResource();
      result.put(newKey, processTime);
      i++;
      if (i >= top) {
        break;
      }
    }
    return result;
  }
コード例 #2
0
  public static LinkedHashMap<String, Long> getProcessRate(List<ProcessTime> models) {
    Collections.sort(
        models,
        new Comparator() {

          @Override
          public int compare(Object o1, Object o2) {
            ProcessTime p1 = (ProcessTime) o1;
            ProcessTime p2 = (ProcessTime) o2;
            return (int) (p1.getStartTime().getTime() - p2.getStartTime().getTime());
          }
        });
    LinkedHashMap<String, Long> data = new LinkedHashMap<>();
    if (models.size() < 1) {
      return data;
    }
    ProcessTime first = models.get(0);
    ProcessTime latest = models.get(models.size() - 1);
    log.debug("首次请求时间:" + DateTypeConverter.toDefaultDateTime(first.getStartTime()));
    log.debug("最后请求时间:" + DateTypeConverter.toDefaultDateTime(latest.getEndTime()));
    long totalTime = latest.getEndTime().getTime() - first.getStartTime().getTime();
    log.debug(
        "系统总时间:"
            + latest.getEndTime().getTime()
            + "-"
            + first.getStartTime().getTime()
            + "="
            + totalTime);
    long processTime = 0;
    for (ProcessTime item : models) {
      log.debug("      增加请求处理时间:" + item.getProcessTime());
      processTime += item.getProcessTime();
    }
    log.debug("处理请求时间:" + processTime);
    long waitTime = totalTime - processTime;
    log.debug("系统空闲时间:" + waitTime);
    data.put("处理请求时间", processTime);
    data.put("系统空闲时间", -waitTime);

    return data;
  }
コード例 #3
0
  public static LinkedHashMap<String, Long> getSequenceData(List<IndexLog> models) {
    Collections.sort(
        models,
        new Comparator() {

          @Override
          public int compare(Object o1, Object o2) {
            IndexLog p1 = (IndexLog) o1;
            IndexLog p2 = (IndexLog) o2;
            return (int) (p1.getStartTime().getTime() - p2.getStartTime().getTime());
          }
        });
    LinkedHashMap<String, Long> data = new LinkedHashMap<>();
    if (models.size() < 1) {
      return data;
    }
    for (IndexLog item : models) {
      String key = DateTypeConverter.toDefaultDateTime(item.getStartTime());
      data.put(key, item.getProcessTime());
    }
    return data;
  }