Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

57
LINES

< > BotCompany Repo | #1031759 // InvestigateNonTransientGraph

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (5566L/33K).

sclass InvestigateNonTransientGraph {
  MetaTransformer mt;
  Map back = identityHashMap();
  new MultiSet<O> objectsBySize;
  new MultiMap<Class, O> objectsByClass;
  new MultiSet<S> objectsByDynClass;
  
  *() {
    mt = metaTransformer_collectionAndMap();
    mt.add(new MTSH_nonTransientFields);
    mt.avoidCycles();
    mt.markPointer = (a, b) -> {
      putIfNotThere(back, b, a);
    };
  }
  
  void scan(O root) {
    VStack.Computable v = mt.new visit_vstackComputable(o -> {
      objectsBySize.add(o.getClass(), clampToInt(unsafe_sizeOf(o)));
      objectsByClass.put(o.getClass(), o);
      if (o instanceof DynamicObject)
        objectsByDynClass.add(shortDynClassName(o));
    }, root);
    
    vstackCompute(v);
  }
  
  void printResults() {
    print("Seen objects: " + n2(mt.seen));
    print();
    print("Most popular classes:");
    print(multiSetToLines(multiMapToMultiSet(objectsByClass), 20));
    print();
    print("Total bytes per class:");
    print(multiSetToLines(objectsBySize, 20));
    if (!empty(objectsByDynClass)) {
      print("Popular dynamic classes:");
      print(multiSetToLines(objectsByDynClass, 20));
    }
  }
  
  <A> L<A> biggestOfClass(Class<A> c) {
    ret sortedByCalculatedFieldDesc unsafe_objectSize((Cl<A>) objectsByClass.get(c));
  }
  
  void printBiggestByteArrays() {
    for (var array : takeFirst(2, biggestOfClass(byteArrayType()))) {
      print("Byte array " + n2_l(array));
      O o = array;
      repeat 10 {
        if (o == null) break;
        o = back.get(o);
        print("  <= " + className/*shortenedToStringWithClass*/(o));
      }
    }
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 5 computer(s): bhatertpkbcr, ekrmjmnbrukm, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1031759
Snippet name: InvestigateNonTransientGraph
Eternal ID of this version: #1031759/11
Text MD5: a72fe02af9aa7e2c42bee89fcc97412c
Transpilation MD5: d3798bb1d0c0129fa1919addef47bec2
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-29 08:54:45
Source code size: 1678 bytes / 57 lines
Pitched / IR pitched: No / No
Views / Downloads: 149 / 319
Version history: 10 change(s)
Referenced in: [show references]