コード例 #1
0
  public void startElement(String namespaceURI, String sName, String qName, Attributes attrs)
      throws SAXException {
    try {
      // System.out.println("START: [" + qName + "]");
      if (currentAF == null) {

        if ("af".equals(qName)) {
          currentAF = new AF();
          String type = attrs.getValue("type");
          String id = attrs.getValue("id");
          String ts = attrs.getValue("timestamp");
          currentAF.id = id;
          currentAF.type = type;
          final Date date = parseTime(ts);
          currentAF.timestamp = date;
          if (begin == null) {
            begin = date;
            currentAF.elapsedTime = 0L;
          } else {
            currentAF.elapsedTime = (currentAF.timestamp.getTime() - begin.getTime()) / 1000;
            System.out.println("ElapsedTime: " + currentAF.elapsedTime);
          }
          // System.out.println("START: [af, " + type + "]");

        }
      } else if (currentAF != null) {
        if ("time".equals(qName)) {
          //				String pauseStr = attrs.getValue("exclusiveaccessms");
          //				double pause = -1D;
          //				if(pauseStr != null){
          //					pause = Double.parseDouble(pauseStr);
          //					currentAF.totalTime = pause/1000;
          //				}

          String totalStr = attrs.getValue("totalms");
          double total = -1D;
          if (totalStr != null) {
            total = Double.parseDouble(totalStr);
            currentAF.totalTime = total / 1000;
          }

        } else if ("gc".equals(qName)) {
          String type = attrs.getValue("type");
          currentAF.gcType = type;
        } else if ("timesms".equals(qName)) {
          String markStr = attrs.getValue("mark");
          double mark = -1D;
          if (markStr != null) {
            mark = Double.parseDouble(markStr);
            currentAF.gcTimeMark = mark;
          }
          String sweepStr = attrs.getValue("sweep");
          double sweep = -1D;
          if (sweepStr != null) {
            mark = Double.parseDouble(sweepStr);
            currentAF.gcTimeSweep = sweep;
          }
        } else if ("tenured".equals(qName)) {
          currentTenured++;
          String freeStr = attrs.getValue("freebytes");
          int free = -1;
          if (freeStr != null) {
            free = Integer.parseInt(freeStr);
          }
          String totalStr = attrs.getValue("totalbytes");
          int total = -1;
          if (totalStr != null) {
            total = Integer.parseInt(totalStr);
          }

          // For now only care about Total - don't break into SOA and LOA
          if (currentTenured == 1) {
            currentAF.initialFreeBytes = free / 1000;
            currentAF.initialTotalBytes = total / 1000;
          } else if (currentTenured == 2) {
            // ignore
          } else if (currentTenured == 3) {
            currentAF.afterFreeBytes = free / 1000;
            currentAF.afterTotalBytes = total / 1000;
          } else {
            LOG.warning("currentTenured is > 3!");
          }
        } else if ("soa".equals(qName)) {
          String freeStr = attrs.getValue("freebytes");
          int free = -1;
          if (freeStr != null) {
            free = Integer.parseInt(freeStr);
          }
          String totalStr = attrs.getValue("totalbytes");
          int total = -1;
          if (totalStr != null) {
            total = Integer.parseInt(totalStr);
          }

          if (currentTenured == 1) {
            currentAF.initialSOAFreeBytes = free / 1000;
            currentAF.initialSOATotalBytes = total / 1000;
          } else if (currentTenured == 2) {
            // ignore
          } else if (currentTenured == 3) {
            currentAF.afterSOAFreeBytes = free / 1000;
            currentAF.afterSOATotalBytes = total / 1000;
          } else {
            LOG.warning("currentTenured is > 3!");
          }
        } else if ("loa".equals(qName)) {
          String freeStr = attrs.getValue("freebytes");
          int free = -1;
          if (freeStr != null) {
            free = Integer.parseInt(freeStr);
          }
          String totalStr = attrs.getValue("totalbytes");
          int total = -1;
          if (totalStr != null) {
            total = Integer.parseInt(totalStr);
          }

          if (currentTenured == 1) {
            currentAF.initialLOAFreeBytes = free / 1000;
            currentAF.initialLOATotalBytes = total / 1000;
          } else if (currentTenured == 2) {
            // ignore
          } else if (currentTenured == 3) {
            currentAF.afterLOAFreeBytes = free / 1000;
            currentAF.afterLOATotalBytes = total / 1000;
          } else {
            LOG.warning("currentTenured is > 3!");
          }
        }
      }

    } catch (ParseException e) {
      e.printStackTrace();
    }
  }