Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add sample tutorials

  • Loading branch information...
commit 3bbbb4355002360fe1f5dd83780c685c135df153 1 parent 87ae690
norberthu authored
View
5 README.md
@@ -171,6 +171,11 @@ startup. We subsequently ran HeapAudit with "-Ajrockit/.+" and everything
returned back to normal. See [HeapSettings.java](https://github.com/foursquare/heapaudit/blob/master/src/main/java/com/foursquare/heapaudit/HeapSettings.java)
for list of namespaces avoided by default.
+### Tutorials
+
+Check out some of the sample [tutorials](https://github.com/foursquare/heapaudit/blob/master/src/test/java/com/foursquare/heapaudit/tutorials/)
+and play around with the examples!
+
### Dependencies
- [ASM](http://asm.ow2.org/)
View
3  src/main/java/com/foursquare/heapaudit/recorders/README.md
@@ -1,6 +1,7 @@
The recorders sub-directory contains sample recorders which are bundled into the
heaprecorders.jar library and can serve as alternative dynamically injected
-recorders.
+recorders. Sources in this sub-directory are not packed into the heapaudit.jar
+file.
### Injecting custom recorders
View
29 src/test/java/com/foursquare/heapaudit/tutorials/Example.java
@@ -0,0 +1,29 @@
+package com.foursquare.heapaudit.tutorials;
+
+public abstract class Example {
+
+ private static class Foo {
+
+ public float value;
+
+ }
+
+ private static class Bar {
+
+ public boolean value;
+
+ }
+
+ protected static void allocateFoo() {
+
+ Foo f = new Foo();
+
+ }
+
+ protected static void allocateBar() {
+
+ Bar b = new Bar();
+
+ }
+
+}
View
21 src/test/java/com/foursquare/heapaudit/tutorials/example1/Dynamic.java
@@ -0,0 +1,21 @@
+package com.foursquare.heapaudit.tutorials.example1;
+
+import com.foursquare.heapaudit.tutorials.Example;
+
+// The following illustrates using HeapAudit to record allocations by dynamic
+// instrumentation. See https://github.com/foursquare/heapaudit/blob/master/src/test/java/com/foursquare/heapaudit/tutorials/example1/README.md
+// for more information.
+
+public class Dynamic extends Example {
+
+ public static void main(String[] args) {
+
+ System.console().readLine("After injecting HeapAudit, press <enter> to continue...");
+
+ Example.allocateFoo();
+
+ Example.allocateBar();
+
+ }
+
+}
View
18 src/test/java/com/foursquare/heapaudit/tutorials/example1/README.md
@@ -0,0 +1,18 @@
+## Dynamic use case
+
+This example illustrates HeapAudit dynamically instrumenting the target code at
+run time.
+
+After building the package, execute the following from the commandline under
+/target/test-classes/.
+
+ $ java com/foursquare/heapaudit/tutorials/example1/Dynamic
+
+From a different commandline, run the following with the matching process id.
+
+ $ java -jar heapaudit.jar 999 -Icom.foursquare.heapaudit.tutorials.Example@allocateBar.+
+
+In the first commandline, press enter to continue with the allocation.
+
+NOTE: You need to point to the file path for heapaudit.jar with the correct
+version number under /target/.
View
12 src/test/java/com/foursquare/heapaudit/tutorials/example2/README.md
@@ -0,0 +1,12 @@
+## Static use case
+
+This example illustrates HeapAudit statically instrumenting the target code at
+load time.
+
+After building the package, execute the following from the commandline under
+/target/test-classes/.
+
+ $ java -javaagent:heapaudit.jar com/foursquare/heapaudit/tutorials/example2/Static
+
+NOTE: You need to point to the file path for heapaudit.jar with the correct
+version number under /target/.
View
27 src/test/java/com/foursquare/heapaudit/tutorials/example2/Static.java
@@ -0,0 +1,27 @@
+package com.foursquare.heapaudit.tutorials.example2;
+
+import com.foursquare.heapaudit.HeapQuantile;
+import com.foursquare.heapaudit.HeapRecorder;
+import com.foursquare.heapaudit.tutorials.Example;
+
+// The following illustrates using HeapAudit to record allocations by static
+// instrumentation. See https://github.com/foursquare/heapaudit/blob/master/src/test/java/com/foursquare/heapaudit/tutorials/example2/README.md
+// for more information.
+
+public class Static extends Example {
+
+ public static void main(String[] args) {
+
+ allocateFoo();
+
+ HeapQuantile recorder = new HeapQuantile();
+ HeapRecorder.register(recorder, false);
+
+ allocateBar();
+
+ HeapRecorder.unregister(recorder, false);
+ System.out.println(recorder.summarize(false));
+
+ }
+
+}
View
21 src/test/java/com/foursquare/heapaudit/tutorials/example3/Custom.java
@@ -0,0 +1,21 @@
+package com.foursquare.heapaudit.tutorials.example3;
+
+import com.foursquare.heapaudit.tutorials.Example;
+
+// The following illustrates using HeapAudit to record allocations by dynamic
+// instrumentation with a custom recorder. See https://github.com/foursquare/heapaudit/blob/master/src/test/java/com/foursquare/heapaudit/tutorials/example3/README.md
+// for more information.
+
+public class Custom extends Example {
+
+ public static void main(String[] args) {
+
+ System.console().readLine("After injecting HeapAudit, press <enter> to continue...");
+
+ allocateFoo();
+
+ allocateBar();
+
+ }
+
+}
View
18 src/test/java/com/foursquare/heapaudit/tutorials/example3/README.md
@@ -0,0 +1,18 @@
+## Dynamic use case with custom recorder
+
+This example illustrates HeapAudit dynamically instrumenting the target code at
+run time with a custom recorder.
+
+After building the package, execute the following from the commandline under
+/target/test-classes/.
+
+ $ java com/foursquare/heapaudit/tutorials/example3/Custom
+
+From a different commandline, run the following with the matching process id.
+
+ $ java -jar heapaudit.jar 999 -Icom.foursquare.heapaudit.tutorials.Example@allocateBar.+ -Xrecorder=com.foursquare.heapaudit.recorders.HeapTotal@heaprecorders.jar
+
+In the first commandline, press enter to continue with the allocation.
+
+NOTE: You need to point to the file path for heapaudit.jar and heaprecorders.jar
+with the correct version number under /target/.
Please sign in to comment.
Something went wrong with that request. Please try again.