Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mesureBytes #3

Open
GoogleCodeExporter opened this issue Mar 14, 2015 · 1 comment
Open

mesureBytes #3

GoogleCodeExporter opened this issue Mar 14, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

Hi

I am doing the following

long totalMemory = Runtime.getRuntime().totalMemory();
MyObject = createMyObject(args);
memoryGuessed = Runtime.getRuntime().totalMemory() - totalMemory;

Footprint footprint = ObjectGraphMeasurer.measure(appSession);
log.info("footprint.toString()
      + " memory:" + MemoryMeasurer.measureBytes(appSession) 
      + " memoryGuessed:" + memoryGuessed
      );

And the result is 
footprint:Footprint{Objects=70992, References=194939, Primitives=[int x 63043, 
long x 452, char x 437906, byte x 78594, boolean x 12100, float x 2331]} 
memory:2821976 memoryGuessed:327680

I am using:
Ubuntu 12.04.2 LTS, Precise Pangolin
Linux ubuntu 3.2.0-43-generic-pae #68-Ubuntu SMP Wed May 15 03:55:10 UTC 2013 
i686 i686 i386 GNU/Linux

Why is memory x8 greater than memoryGuessed? Could it be that memory is bits 
and not bytes? Am I missing something? Thank you for your help!

Original issue reported on code.google.com by [email protected] on 23 May 2013 at 6:56

@GoogleCodeExporter
Copy link
Author

(Assuming the second line is "MyObject appSession = ...")

Perhaps appSession points to objects that existed before the instantiation of 
that. Are you sure that you constructed everything beneath it, after measuring 
totalMemory()?

Anyway, to validate the computation, you can always use 
ObjectExplorer.exploreObject(appSession, new ObjectVisitor<Void>() {
  public Traversal visit(Chain chain) {
    println(chain); 
    return Traversal.EXPLORE;
  }
  ..
});

Though this will probably print a lot of paths. 

And to make sure it avoids cycles, you'd probably try something this instead:

final Predicate<Chain> atMostOnce = new ObjectExplorer.AtMostOncePredicate();
ObjectExplorer.exploreObject(appSession, new ObjectVisitor<Void>() {
  public Traversal visit(Chain chain) {
    println(chain); 
    return atMostOnce.apply(chain) ? Traversal.EXPLORE : Traversal.SKIP;
  }
  ..
});

The library is a bit raw, I know, sorry about that

Original comment by jim.andreou on 26 May 2013 at 3:48

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant