Skip to content

Commit

Permalink
Added object allocation instrumentation for Column
Browse files Browse the repository at this point in the history
  - Modified CassandraDaemon to create allocation sampler before
    it starts the server;
  - Added allocations.jar to lib/
  • Loading branch information
aryanet authored and Arya Goudarzi committed Aug 14, 2013
1 parent 7d4380d commit 3c7a9dd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Binary file added lib/allocation.jar
Binary file not shown.
23 changes: 23 additions & 0 deletions src/java/org/apache/cassandra/service/CassandraDaemon.java
Expand Up @@ -19,6 +19,7 @@

import java.io.File;
import java.io.IOException;
import java.lang.instrument.UnmodifiableClassException;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
Expand All @@ -45,6 +46,9 @@
import org.apache.cassandra.utils.CLibrary;
import org.apache.cassandra.utils.Mx4jTool;

import com.google.monitoring.runtime.instrumentation.ConstructorCallback;
import com.google.monitoring.runtime.instrumentation.ConstructorInstrumenter;

/**
* The <code>CassandraDaemon</code> is an abstraction for a Cassandra daemon
* service, which defines not only a way to activate and deactivate it, but also
Expand Down Expand Up @@ -453,9 +457,28 @@ public static void stop(String[] args)

public static void main(String[] args)
{
instrumentAllocations();
instance.activate();
}

/*
* @see: https://code.google.com/p/java-allocation-instrumenter/wiki/GettingStarted
*/
private static void instrumentAllocations() {
try {
ConstructorInstrumenter.instrumentClass(
Column.class, new ConstructorCallback<Column>() {
@Override public void sample(Column c) {
if ((Math.random() * 10000) > 9998) {
logger.info("Allocated a column", new Exception("Sample stacktrace"));
}
}
});
} catch (UnmodifiableClassException e) {
System.out.println("Class cannot be modified");
}
}

public interface Server
{
/**
Expand Down

0 comments on commit 3c7a9dd

Please sign in to comment.