protected int encodeTransaction(
      MessageTree tree, Transaction transaction, ChannelBuffer buf, Locator locator, Ruler ruler) {
    List<Message> children = getVisibleChildren(transaction);
    int count = 0;

    locator.downLevel(children.isEmpty());
    locator.nextLine();
    count += encodeTransactionLine(tree, transaction, buf, locator, ruler);

    int len = children.size();

    for (int i = 0; i < len; i++) {
      Message child = children.get(i);

      locator.setLast(i == len - 1);

      if (child instanceof Transaction) {
        count += encodeTransaction(tree, (Transaction) child, buf, locator, ruler);
      } else if (child instanceof Event && "RemoteCall".equals(child.getType())) {
        count += encodeRemoteCall(tree, (Event) child, buf, locator, ruler);
      }
    }

    locator.upLevel();
    return count;
  }
  private int processLongService(Machine machine, MessageTree tree) {
    int count = 0;
    Message message = tree.getMessage();

    if (message instanceof Transaction) {
      String messageType = message.getType();

      if ("Service".equals(messageType) || "PigeonService".equals(messageType)) {
        long duration = ((Transaction) message).getDurationInMillis();
        String domain = tree.getDomain();
        long nomarizeDuration =
            computeLongDuration(
                duration, domain, m_defaultLongServiceDuration, m_longServiceThresholds);

        if (nomarizeDuration > 0) {
          String type = ProblemType.LONG_SERVICE.getName();
          String status = message.getName();

          Entry entry = findOrCreateEntry(machine, type, status);
          updateEntry(tree, entry, (int) nomarizeDuration);
          count++;
        }
      }
    }

    return count;
  }
  protected List<Message> getVisibleChildren(Transaction parent) {
    List<Message> children = new ArrayList<Message>();

    for (Message child : parent.getChildren()) {
      if (child instanceof Transaction) {
        children.add(child);
      } else if (child instanceof Event && "RemoteCall".equals(child.getType())) {
        children.add(child);
      }
    }

    return children;
  }
  protected int calculateLines(Transaction t) {
    int count = 1;

    for (Message child : t.getChildren()) {
      if (child instanceof Transaction) {
        count += calculateLines((Transaction) child);
      } else if (child instanceof Event) {
        if (child.getType().equals("RemoteCall")) {
          count++;
        }
      }
    }

    return count;
  }
Esempio n. 5
0
  private boolean isAtomicMessage(MessageTree tree) {
    Message message = tree.getMessage();

    if (message instanceof Transaction) {
      String type = message.getType();

      if (type.startsWith("Cache.") || "SQL".equals(type)) {
        return true;
      } else {
        return false;
      }
    } else {
      return true;
    }
  }
Esempio n. 6
0
  protected int encodeMessage(
      MessageTree tree, Message message, ChannelBuffer buf, int level, LineCounter counter) {
    if (message instanceof Transaction) {
      Transaction transaction = (Transaction) message;
      List<Message> children = transaction.getChildren();

      if (children.isEmpty()) {
        if (transaction.getDurationInMillis() < 0) {
          return encodeLine(tree, transaction, buf, 't', Policy.WITHOUT_STATUS, level, counter);
        } else {
          return encodeLine(tree, transaction, buf, 'A', Policy.WITH_DURATION, level, counter);
        }
      } else {
        int count = 0;

        count += encodeLine(tree, transaction, buf, 't', Policy.WITHOUT_STATUS, level, counter);

        for (Message child : children) {
          count += encodeMessage(tree, child, buf, level + 1, counter);
        }

        count += encodeLine(tree, transaction, buf, 'T', Policy.WITH_DURATION, level, counter);

        return count;
      }
    } else if (message instanceof Event) {
      String type = message.getType();

      if ("RemoteCall".equals(type)) {
        return encodeLogViewLink(tree, message, buf, level, counter);
      } else {
        return encodeLine(tree, message, buf, 'E', Policy.DEFAULT, level, counter);
      }
    } else if (message instanceof Metric) {
      return encodeLine(tree, message, buf, 'M', Policy.DEFAULT, level, counter);
    } else if (message instanceof Heartbeat) {
      return encodeLine(tree, message, buf, 'H', Policy.DEFAULT, level, counter);
    } else {
      throw new RuntimeException(
          String.format("Unsupported message type: %s.", message.getClass()));
    }
  }
Esempio n. 7
0
  protected int encodeLine(
      MessageTree tree,
      Message message,
      ChannelBuffer buf,
      char type,
      Policy policy,
      int level,
      LineCounter counter) {
    BufferHelper helper = m_bufferHelper;
    int count = 0;

    if (counter != null) {
      counter.inc();

      count += helper.tr1(buf, counter.getCount() % 2 != 0 ? "odd" : "even");
    } else {
      count += helper.tr1(buf, null);
    }

    count += helper.td1(buf);

    count += helper.nbsp(buf, level * 2); // 2 spaces per level
    count += helper.write(buf, (byte) type);

    if (type == 'T' && message instanceof Transaction) {
      long duration = ((Transaction) message).getDurationInMillis();

      count += helper.write(buf, m_dateHelper.format(message.getTimestamp() + duration));
    } else {
      count += helper.write(buf, m_dateHelper.format(message.getTimestamp()));
    }

    count += helper.td2(buf);

    count += helper.td(buf, message.getType());
    count += helper.td(buf, message.getName());

    if (policy != Policy.WITHOUT_STATUS) {
      if (Message.SUCCESS.equals(message.getStatus())) {
        count += helper.td(buf, "&nbsp;"); // do not output "0"
      } else {
        count += helper.td(buf, message.getStatus(), "class=\"error\"");
      }

      Object data = message.getData();

      count += helper.td1(buf);

      if (policy == Policy.WITH_DURATION && message instanceof Transaction) {
        long durationInMicro = ((Transaction) message).getDurationInMicros();
        long durationInMillis = durationInMicro / 1000L;

        if (durationInMicro < 100L) {
          count += helper.write(buf, String.format("%.2f", durationInMicro / 1000.0));
        } else if (durationInMicro < 10000L) { // less than 10 ms
          count += helper.write(buf, String.format("%.2f", durationInMicro / 1000.0));
        } else { // no fraction
          count += helper.write(buf, Long.toString(durationInMillis));
        }

        count += helper.write(buf, "ms ");
      }

      count += helper.writeRaw(buf, String.valueOf(data));
      count += helper.td2(buf);
    } else {
      count += helper.td(buf, "");
      count += helper.td(buf, "");
    }

    count += helper.tr2(buf);
    count += helper.crlf(buf);

    return count;
  }