Exemplo n.º 1
0
    Stats(
        LinkedList<HeapSnapshot> oldsnaps1,
        LinkedList<HeapSnapshot> oldsnaps2,
        LinkedList<HeapSnapshot> newsnaps,
        String targetClass) {
      int sameNumFields = 0;
      for (int i = 0; i < oldsnaps1.size(); i++) {
        numSnapshots++;
        System.out.println("i = " + i);
        this.targetClass = targetClass;
        LinkedList<String> classes = oldsnaps1.get(i).getClasses();
        if (classes.size() > numClasses) numClasses = classes.size();
        for (String cl : classes) {
          if (cl.equals("java.lang.Object")) continue;
          System.out.println("cl = " + cl);
          int oldObjCount = oldsnaps1.get(i).countObjectsOfClass(cl);
          int newObjCount = newsnaps.get(i).countObjectsOfClass(cl);
          ExpandedObject obj = oldsnaps1.get(i).getFirstObjectOfClass(cl);
          numObjects += oldObjCount;
          if (oldObjCount != 0 && obj != null && oldObjCount == newObjCount) {
            int fields = obj.getFields().size();
            if (fields > 0) {
              sameNumClasses++;
              sameNumObjects += oldObjCount;
              sameNumFields += fields;
            }
          }

          if (cl.equals(targetClass)) {
            if (fieldsInTargetClass == 0 && obj != null)
              fieldsInTargetClass = obj.getFields().size();
            objectsOfTargetClass += oldObjCount;
          }
        }
      }
      avgFieldsPerSameNumObject = ((double) sameNumFields) / ((double) sameNumClasses);
      sameNumClasses /= numSnapshots;
    }
Exemplo n.º 2
0
  static ExpandedObject findMinDiff(ExpandedObject o1, List<ExpandedObject> other) {
    ExpandedObject minObj = null;
    int minDiff = Integer.MAX_VALUE;

    for (ExpandedObject o2 : other) {
      int diff = o1.diff(o2);
      if (diff < minDiff) {
        minDiff = diff;
        minObj = o2;
      }
    }

    return minObj;
  }