Added the Java Agent Example
This commit is contained in:
parent
5aa4950b33
commit
40a70e44ac
|
@ -0,0 +1,11 @@
|
|||
package com.baeldung.objectsize;
|
||||
|
||||
public class InstrumentedSize {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String ds = "Data Structures";
|
||||
Course course = new Course(ds);
|
||||
|
||||
System.out.println(ObjectSizeCalculator.sizeOf(course));
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
Premain-Class: com.baeldung.objectsize.ObjectSizeCalculator
|
|
@ -0,0 +1,16 @@
|
|||
package com.baeldung.objectsize;
|
||||
|
||||
import java.lang.instrument.Instrumentation;
|
||||
|
||||
public class ObjectSizeCalculator {
|
||||
|
||||
private static Instrumentation instrumentation;
|
||||
|
||||
public static void premain(String args, Instrumentation inst) {
|
||||
instrumentation = inst;
|
||||
}
|
||||
|
||||
public static long sizeOf(Object o) {
|
||||
return instrumentation.getObjectSize(o);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue