Commit 2ea5cbe2 authored by Florian Fittkau's avatar Florian Fittkau

moved large parts to common

parent eb3a95af
......@@ -9,5 +9,6 @@
<attribute name="javadoc_location" value="jar:platform:/resource/monitored-application/lib/disruptor-3.2.0-javadoc.jar!/"/>
</attributes>
</classpathentry>
<classpathentry combineaccessrules="false" kind="src" path="/common-monitoring"/>
<classpathentry kind="output" path="bin"/>
</classpath>
......@@ -41,6 +41,17 @@ public enum MonitoringController { // Singleton (Effective Java #3)
ringBuffer = disruptor.start();
}
// public final ByteArrayEvent getNewMonitoringRecordSlot() {
// final long hiseq = ringBuffer.next();
// final ByteArrayEvent valueEvent = ringBuffer.get(hiseq);
// valueEvent.setSequence(hiseq);
// return valueEvent;
// }
//
// public void sendMonitoringRecord(final ByteArrayEvent record) {
// ringBuffer.publish(record.getSequence());
// }
public final void newMonitoringRecord(final byte[] message, final int length) {
final long hiseq = ringBuffer.next();
final ByteArrayEvent valueEvent = ringBuffer.get(hiseq);
......@@ -66,6 +77,7 @@ public enum MonitoringController { // Singleton (Effective Java #3)
stringReg.put(value, result);
final int regRecordLength = 4 + 4 + 4 + value.length();
// final int byteArrayLength = Math.max(regRecordLength, 32);
final byte[] regRecord = new byte[regRecordLength];
UnsafeBits.putInt(regRecord, 0, 4);
......
package explorviz.hpc_monitoring.byteaccess;
public class Bits {
public static boolean getBoolean(final byte[] b, final int off) {
return b[off] != 0;
}
public static char getChar(final byte[] b, final int off) {
return (char) ((b[off + 1] & 0xFF) + (b[off] << 8));
}
public static short getShort(final byte[] b, final int off) {
return (short) ((b[off + 1] & 0xFF) + (b[off] << 8));
}
public static int getInt(final byte[] b, final int off) {
return ((b[off + 3] & 0xFF)) + ((b[off + 2] & 0xFF) << 8)
+ ((b[off + 1] & 0xFF) << 16) + ((b[off]) << 24);
}
public static float getFloat(final byte[] b, final int off) {
return Float.intBitsToFloat(getInt(b, off));
}
public static long getLong(final byte[] b, final int off) {
return ((b[off + 7] & 0xFFL)) + ((b[off + 6] & 0xFFL) << 8)
+ ((b[off + 5] & 0xFFL) << 16) + ((b[off + 4] & 0xFFL) << 24)
+ ((b[off + 3] & 0xFFL) << 32) + ((b[off + 2] & 0xFFL) << 40)
+ ((b[off + 1] & 0xFFL) << 48) + (((long) b[off]) << 56);
}
public static double getDouble(final byte[] b, final int off) {
return Double.longBitsToDouble(getLong(b, off));
}
public static byte getByte(final byte[] b, final int off) {
return b[off];
}
public static void putBoolean(final byte[] b, final int off,
final boolean val) {
b[off] = (byte) (val ? 1 : 0);
}
public static void putChar(final byte[] b, final int off, final char val) {
b[off + 1] = (byte) (val);
b[off] = (byte) (val >>> 8);
}
public static void putShort(final byte[] b, final int off, final short val) {
b[off + 1] = (byte) (val);
b[off] = (byte) (val >>> 8);
}
public static void putInt(final byte[] b, final int off, final int val) {
b[off + 3] = (byte) (val);
b[off + 2] = (byte) (val >>> 8);
b[off + 1] = (byte) (val >>> 16);
b[off] = (byte) (val >>> 24);
}
public static void putFloat(final byte[] b, final int off, final float val) {
putInt(b, off, Float.floatToIntBits(val));
}
public static void putLong(final byte[] b, final int off, final long val) {
b[off + 7] = (byte) (val);
b[off + 6] = (byte) (val >>> 8);
b[off + 5] = (byte) (val >>> 16);
b[off + 4] = (byte) (val >>> 24);
b[off + 3] = (byte) (val >>> 32);
b[off + 2] = (byte) (val >>> 40);
b[off + 1] = (byte) (val >>> 48);
b[off] = (byte) (val >>> 56);
}
public static void putDouble(final byte[] b, final int off, final double val) {
putLong(b, off, Double.doubleToLongBits(val));
}
public static void putByte(final byte[] b, final int off, final byte val) {
b[off] = val;
}
}
package explorviz.hpc_monitoring.byteaccess;
import java.lang.reflect.Field;
import sun.misc.Unsafe;
public class UnsafeBits {
private static final Unsafe unsafe;
static {
try {
final Field field = Unsafe.class.getDeclaredField("theUnsafe");
field.setAccessible(true);
unsafe = (Unsafe) field.get(null);
}
catch (final Exception e) {
throw new RuntimeException(e);
}
}
private static final long byteArrayOffset = unsafe.arrayBaseOffset(byte[].class);
public static final void putInt(final byte[] buffer, final int pos,
final int value) {
unsafe.putInt(buffer, byteArrayOffset + pos, value);
}
public static final int getInt(final byte[] buffer, final int pos) {
return unsafe.getInt(buffer, byteArrayOffset + pos);
}
public static final void putLong(final byte[] buffer, final int pos,
final long value) {
unsafe.putLong(buffer, byteArrayOffset + pos, value);
}
public static final long getLong(final byte[] buffer, final int pos) {
return unsafe.getLong(buffer, byteArrayOffset + pos);
}
}
\ No newline at end of file
/***************************************************************************
* Copyright 2013 Kieker Project (http://kieker-monitoring.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
package explorviz.hpc_monitoring.configuration;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Properties;
import explorviz.hpc_monitoring.MonitoringController;
/**
* A ConfigurationFactory for kieker.monitoring.
*
* @author Andre van Hoorn, Jan Waller
*
* @since 1.3
*/
public final class ConfigurationFactory implements Keys {
private ConfigurationFactory() {
}
public static final Configuration createSingletonConfiguration() {
final Configuration defaultConfiguration = ConfigurationFactory
.defaultConfiguration();
// Searching for configuration file location passed to JVM
String configurationFile = System
.getProperty(Keys.CUSTOM_PROPERTIES_LOCATION_JVM);
final Configuration loadConfiguration;
if (configurationFile != null) {
loadConfiguration = ConfigurationFactory.loadConfigurationFromFile(
configurationFile, defaultConfiguration);
} else {
// No JVM property; Trying to find configuration file in classpath
configurationFile = Keys.CUSTOM_PROPERTIES_LOCATION_CLASSPATH;
loadConfiguration = ConfigurationFactory
.loadConfigurationFromResource(configurationFile,
defaultConfiguration);
}
// 1.JVM-params -> 2.properties file -> 3.default properties file
return ConfigurationFactory.getSystemPropertiesStartingWith(
Keys.PREFIX, loadConfiguration);
}
public static final Configuration createDefaultConfiguration() {
return new Configuration(ConfigurationFactory.defaultConfiguration());
}
public static final Configuration createConfigurationFromFile(
final String configurationFile) {
return ConfigurationFactory.loadConfigurationFromFile(
configurationFile, ConfigurationFactory.defaultConfiguration());
}
private static final Configuration defaultConfiguration() {
return ConfigurationFactory.loadConfigurationFromResource(
Keys.DEFAULT_PROPERTIES_LOCATION_CLASSPATH, null);
}
private static final Configuration loadConfigurationFromFile(
final String propertiesFn, final Configuration defaultValues) {
final Configuration properties = new Configuration(defaultValues);
InputStream is = null; // NOPMD (null)
try {
try {
is = new FileInputStream(propertiesFn);
} catch (final FileNotFoundException ex) {
// if not found as absolute path try within the classpath
is = MonitoringController.class.getClassLoader()
.getResourceAsStream(propertiesFn);
if (is == null) {
return new Configuration(defaultValues);
}
}
properties.load(is);
return properties;
} catch (final Exception ex) { // NOPMD NOCS (IllegalCatchCheck)
} finally {
if (is != null) {
try {
is.close();
} catch (final IOException ex) {
}
}
}
return new Configuration(defaultValues);
}
private static final Configuration loadConfigurationFromResource(
final String propertiesFn, final Configuration defaultValues) {
final InputStream is = MonitoringController.class.getClassLoader()
.getResourceAsStream(propertiesFn);
if (is != null) {
try {
final Configuration properties = new Configuration(
defaultValues);
properties.load(is);
return properties;
} catch (final Exception ex) { // NOPMD NOCS (IllegalCatchCheck)
} finally {
try {
is.close();
} catch (final IOException ex) {
}
}
}
return new Configuration(defaultValues);
}
private static final Configuration getSystemPropertiesStartingWith(
final String prefix, final Configuration defaultValues) {
final Configuration configuration = new Configuration(defaultValues);
final Properties properties = System.getProperties();
final Enumeration<?> keys = properties.propertyNames();
while (keys.hasMoreElements()) {
final String property = (String) keys.nextElement();
if (property.startsWith(prefix)) {
configuration.setProperty(property,
properties.getProperty(property));
}
}
return configuration;
}
}
/***************************************************************************
* Copyright 2013 Kieker Project (http://kieker-monitoring.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
package explorviz.hpc_monitoring.configuration;
/**
* If this file changes, the default config file has to be adjusted! Ideally it
* would be created using this file! (#151)
*
* @author Andre van Hoorn, Jan Waller
*
* @since 1.3
*/
interface Keys { // NOPMD NOCS (static list)
public static final String PREFIX = "explorviz.hpc_monitoring.";
public static final String CUSTOM_PROPERTIES_LOCATION_CLASSPATH = "META-INF/"
+ PREFIX + "properties";
public static final String DEFAULT_PROPERTIES_LOCATION_CLASSPATH = "META-INF/"
+ PREFIX + "default.properties";
public static final String CUSTOM_PROPERTIES_LOCATION_JVM = PREFIX
+ "configuration";
}
package explorviz.hpc_monitoring.probe;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import explorviz.hpc_monitoring.MonitoringController;
import explorviz.hpc_monitoring.TraceRegistry;
import explorviz.hpc_monitoring.byteaccess.UnsafeBits;
import explorviz.hpc_monitoring.record.events.normal.BeforeOperationEvent;
@Aspect
public abstract class AbstractAspect {
private static final MonitoringController CTRLINST = MonitoringController.INSTANCE;
private static final TraceRegistry TRACEREGISTRY = TraceRegistry.INSTANCE;
/**
* The pointcut for the monitored operations. Inheriting classes should
* extend the pointcut in order to find the correct executions of the
* methods (e.g. all
* methods or only methods with specific annotations).
*/
@Pointcut
public abstract void monitoredOperation();
@Around("monitoredOperation()")
public Object operation(final ProceedingJoinPoint thisJoinPoint)
throws Throwable {
// if (!CTRLINST.isProbeActivated(signature)) { // TODO
// return thisJoinPoint.proceed();
// }
// TODO static methods and constructor calls
byte[] trace = TRACEREGISTRY.getTrace();
final boolean newTrace = trace == null;
if (newTrace) {
trace = TRACEREGISTRY.registerTrace();
CTRLINST.newMonitoringRecord(trace, 32);
}
final long traceId = UnsafeBits.getLong(trace, 4);
// final String clazz = thisObject.getClass().getName(); TODO needed?
final int signatureId = CTRLINST.getIdForSignature(thisJoinPoint
.getSignature());
final byte[] beforeEvent = new byte[28];
UnsafeBits.putInt(beforeEvent, 0, 1);
UnsafeBits.putLong(beforeEvent, 4, System.nanoTime());
UnsafeBits.putLong(beforeEvent, 12, traceId);
final int nextBeforeOrderId = UnsafeBits.getInt(trace, 32);
UnsafeBits.putInt(trace, 32, nextBeforeOrderId + 1);
UnsafeBits.putInt(beforeEvent, 20, nextBeforeOrderId);
UnsafeBits.putInt(beforeEvent, 24, signatureId);
CTRLINST.newMonitoringRecord(beforeEvent, 28);
final Object retval;
try {
retval = thisJoinPoint.proceed();
}
catch (final Throwable th) {
final byte[] afterFailedEvent = new byte[32];
UnsafeBits.putInt(afterFailedEvent, 0, 2);
UnsafeBits.putLong(afterFailedEvent, 4, System.nanoTime());
UnsafeBits.putLong(afterFailedEvent, 12, traceId);
final int nextAfterFailOrderId = UnsafeBits.getInt(trace, 32);
UnsafeBits.putInt(trace, 32, nextAfterFailOrderId + 1);
UnsafeBits.putInt(afterFailedEvent, 20, nextAfterFailOrderId);
UnsafeBits.putInt(afterFailedEvent, 24, signatureId);
final int errorId = CTRLINST.getIdForString(th.toString());
UnsafeBits.putInt(afterFailedEvent, 28, errorId);
CTRLINST.newMonitoringRecord(afterFailedEvent, 32);
throw th;
}
finally {
if (newTrace) { // close the trace
TRACEREGISTRY.unregisterTrace();
}
}
// measure after successful execution
final byte[] afterEvent = new byte[28];
UnsafeBits.putInt(afterEvent, 0, 3);
UnsafeBits.putLong(afterEvent, 4, System.nanoTime());
UnsafeBits.putLong(afterEvent, 12, traceId);
final int nextAfterOrderId = UnsafeBits.getInt(trace, 32);
UnsafeBits.putInt(trace, 32, nextAfterOrderId + 1);
UnsafeBits.putInt(afterEvent, 20, nextAfterOrderId);
UnsafeBits.putInt(afterEvent, 24, signatureId);
CTRLINST.newMonitoringRecord(afterEvent, 28);
return retval;
}
private static final MonitoringController CTRLINST = MonitoringController.INSTANCE;
private static final TraceRegistry TRACEREGISTRY = TraceRegistry.INSTANCE;
/**
* The pointcut for the monitored operations. Inheriting classes should
* extend the pointcut in order to find the correct executions of the
* methods (e.g. all methods or only methods with specific annotations).
*/
@Pointcut
public abstract void monitoredOperation();
@Around("monitoredOperation()")
public Object operation(final ProceedingJoinPoint thisJoinPoint)
throws Throwable {
// if (!CTRLINST.isProbeActivated(signature)) { // TODO
// return thisJoinPoint.proceed();
// }
// TODO static methods and constructor calls
byte[] trace = TRACEREGISTRY.getTrace();
final boolean newTrace = trace == null;
if (newTrace) {
trace = TRACEREGISTRY.registerTrace();
CTRLINST.newMonitoringRecord(trace, 32);
}
final long traceId = UnsafeBits.getLong(trace, 4);
// final String clazz = thisObject.getClass().getName(); TODO needed?
final int signatureId = CTRLINST.getIdForSignature(thisJoinPoint
.getSignature());
final byte[] beforeEvent = new byte[BeforeOperationEvent.BYTE_LENGTH];
UnsafeBits.putInt(beforeEvent, 0, 1);
UnsafeBits.putLong(beforeEvent, 4, System.nanoTime());
UnsafeBits.putLong(beforeEvent, 12, traceId);
final int nextBeforeOrderId = UnsafeBits.getInt(trace, 32);
UnsafeBits.putInt(trace, 32, nextBeforeOrderId + 1);
UnsafeBits.putInt(beforeEvent, 20, nextBeforeOrderId);
UnsafeBits.putInt(beforeEvent, 24, signatureId);
CTRLINST.newMonitoringRecord(beforeEvent, 28);
final Object retval;
try {
retval = thisJoinPoint.proceed();
} catch (final Throwable th) {
final byte[] afterFailedEvent = new byte[32];
UnsafeBits.putInt(afterFailedEvent, 0, 2);
UnsafeBits.putLong(afterFailedEvent, 4, System.nanoTime());
UnsafeBits.putLong(afterFailedEvent, 12, traceId);
final int nextAfterFailOrderId = UnsafeBits.getInt(trace, 32);
UnsafeBits.putInt(trace, 32, nextAfterFailOrderId + 1);
UnsafeBits.putInt(afterFailedEvent, 20, nextAfterFailOrderId);
UnsafeBits.putInt(afterFailedEvent, 24, signatureId);
final int errorId = CTRLINST.getIdForString(th.toString());
UnsafeBits.putInt(afterFailedEvent, 28, errorId);
CTRLINST.newMonitoringRecord(afterFailedEvent, 32);
throw th;
} finally {
if (newTrace) { // close the trace
TRACEREGISTRY.unregisterTrace();
}
}
// measure after successful execution
final byte[] afterEvent = new byte[28];
UnsafeBits.putInt(afterEvent, 0, 3);
UnsafeBits.putLong(afterEvent, 4, System.nanoTime());
UnsafeBits.putLong(afterEvent, 12, traceId);
final int nextAfterOrderId = UnsafeBits.getInt(trace, 32);
UnsafeBits.putInt(trace, 32, nextAfterOrderId + 1);
UnsafeBits.putInt(afterEvent, 20, nextAfterOrderId);
UnsafeBits.putInt(afterEvent, 24, signatureId);
CTRLINST.newMonitoringRecord(afterEvent, 28);
return retval;
}
}
......@@ -4,33 +4,41 @@ import com.lmax.disruptor.EventFactory;
/**
* WARNING: This is a mutable object which will be recycled by the RingBuffer.
* You must take a copy of data it holds
* before the framework recycles it.
* You must take a copy of data it holds before the framework recycles it.
*/
public final class ByteArrayEvent {
private byte[] value;
private int length;
public final byte[] getValue() {
return value;
}
public void setValue(final byte[] value) {
this.value = value;
}
public final int getLength() {
return length;
}
public void setLength(final int length) {
this.length = length;
}
public final static EventFactory<ByteArrayEvent> EVENT_FACTORY = new EventFactory<ByteArrayEvent>() {
@Override
public ByteArrayEvent newInstance() {
return new ByteArrayEvent();
}
};
private byte[] value = new byte[32];
private int length;
private long sequence;
public final byte[] getValue() {
return value;
}
public void setValue(final byte[] value) {
this.value = value;
}
public final int getLength() {
return length;
}
public void setLength(final int length) {
this.length = length;
}
public long getSequence() {
return sequence;
}
public void setSequence(final long sequence) {
this.sequence = sequence;
}
public final static EventFactory<ByteArrayEvent> EVENT_FACTORY = new EventFactory<ByteArrayEvent>() {
@Override
public ByteArrayEvent newInstance() {
return new ByteArrayEvent();
}
};
}
\ No newline at end of file
......@@ -9,8 +9,10 @@ import java.nio.channels.SocketChannel;
import com.lmax.disruptor.EventHandler;
import explorviz.hpc_monitoring.filter.counting.CountingThroughputFilter;
public class TCPWriter implements EventHandler<ByteArrayEvent> {
private static final int MESSAGE_BUFFER_SIZE = 65536 * 2;
private static final int MESSAGE_BUFFER_SIZE = 65536;
private URL providerURL;
private URL loadBalancerURL;
......@@ -20,6 +22,7 @@ public class TCPWriter implements EventHandler<ByteArrayEvent> {
private SocketChannel socketChannel;
private ByteBuffer buffer;
private CountingThroughputFilter counter;
public TCPWriter(final String hostname, final int port) {
try {
......@@ -31,6 +34,7 @@ public class TCPWriter implements EventHandler<ByteArrayEvent> {
loadBalancerWaitTimeInNs = 0;
loadBalancerURL = null;
counter = new CountingThroughputFilter("Records per second from: ");
buffer = ByteBuffer.allocateDirect(MESSAGE_BUFFER_SIZE);
try {
......@@ -85,7 +89,10 @@ public class TCPWriter implements EventHandler<ByteArrayEvent> {
@Override
public void onEvent(final ByteArrayEvent event, final long sequence,
final boolean endOfBatch) throws Exception {
sendMessage(event.getValue(), event.getLength(), endOfBatch);
if (socketChannel.isConnected()) {
sendMessage(event.getValue(), event.getLength(), endOfBatch);
counter.inputObjects(event);
}
}
private final void sendMessage(final byte[] message, final int length,
......@@ -106,6 +113,7 @@ public class TCPWriter implements EventHandler<ByteArrayEvent> {
}
} catch (final IOException e) {
e.printStackTrace();
disconnect();
}
}
......
......@@ -2,8 +2,11 @@ package testpackage;
public class TestClass {
public void testMethod() {
TestClass2 testClass2 = new TestClass2();
testClass2.testMethod2();
}
static public void testMethod(final int i) {
// TestClass2 testClass2 = new TestClass2();
// testClass2.testMethod2();
if (i > 0) {
testMethod(i - 1);
}
}
}
......@@ -2,11 +2,19 @@ package testpackage;
public class TestStart {
public static void main(final String[] args) {
for (int i = 0; i < 20000000; i++) {
final TestClass testClass = new TestClass();
testClass.testMethod();
}
}
public static void main(final String[] args) {
for (int i = 0; i < 2; i++) {
new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 400000000; i++) {
// final TestClass testClass = new TestClass();
TestClass.testMethod(30);
}
}
}).run();
}
}
}
Markdown is supported
0%