public Metrics parse()

in dotTrace-agent/src/main/java/jetbrains/buildServer/dotTrace/agent/ReportParser.java [37:72]


  public Metrics parse(@NotNull final String reportContent) {
    if(StringUtil.isEmptyOrSpaces(reportContent)) {
      return new Metrics(Collections.<Metric>emptyList());
    }

    final List<Metric> metrics = new ArrayList<Metric>();
    final Document doc = myXmlDocumentManager.convertStringToDocument(reportContent);
    final XPath xpath = XPathFactory.newInstance().newXPath();
    try {
      final NodeList functionElements = (NodeList)xpath.evaluate(FUNCTION_XPATH, doc, XPathConstants.NODESET);
      for (int functionIndex = 0; functionIndex < functionElements.getLength(); functionIndex++) {
        final Node functionElement = functionElements.item(functionIndex);
        @Nullable final Node methodNameAttr = functionElement.getAttributes().getNamedItem(METHOD_NAME_ATTR);
        @Nullable final Node totalTimeAttr = functionElement.getAttributes().getNamedItem(TOTAL_TIME_ATTR);
        @Nullable final Node ownTimeAttr = functionElement.getAttributes().getNamedItem(OWN_TIME_ATTR);
        if(methodNameAttr == null || totalTimeAttr == null || ownTimeAttr == null) {
          continue;
        }

        final String methodName = methodNameAttr.getNodeValue();
        final String totalTime = totalTimeAttr.getNodeValue();
        final String ownTime = ownTimeAttr.getNodeValue();

        if(StringUtil.isEmptyOrSpaces(methodName) || StringUtil.isEmptyOrSpaces(totalTime) || StringUtil.isEmptyOrSpaces(ownTime)) {
          continue;
        }

        metrics.add(new Metric(methodName, totalTime, ownTime));
      }
    }
    catch (XPathExpressionException e) {
      throw new BuildException(ERROR_DURING_PARSING_ERROR_MESSAGE);
    }

    return new Metrics(metrics);
  }