Skip to content
Snippets Groups Projects
Commit bb36da27 authored by Florian Fittkau's avatar Florian Fittkau
Browse files

refactoring

parent b7ba68a4
No related branches found
No related tags found
No related merge requests found
Showing
with 202 additions and 118 deletions
......@@ -20,11 +20,10 @@
<!-- Other module inherits -->
<!-- Specify the app entry point class. -->
<entry-point class='kieker.monitoring.gwt.client.GWTMonitoring'/>
<entry-point class='kieker.monitoring.gwt.client.Starter'/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
<!-- allow Super Dev Mode -->
<add-linker name="xsiframe"/>
......
package kieker.monitoring.gwt.client;
import kieker.monitoring.gwt.client.monitoring.MetaMonitoringManager;
import kieker.monitoring.gwt.client.monitoring.MonitoringManager;
import kieker.monitoring.gwt.client.test.TestClass1;
import com.google.gwt.core.client.EntryPoint;
......@@ -12,11 +12,11 @@ import com.google.gwt.user.client.ui.RootPanel;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class GWTMonitoring implements EntryPoint {
public class Starter implements EntryPoint {
public void onModuleLoad() {
bindButton();
MetaMonitoringManager.init();
MonitoringManager.init();
}
public void bindButton() {
......
......@@ -2,6 +2,10 @@ package kieker.monitoring.gwt.client.monitoring;
public class AspectWeaver {
public static native void weave() /*-{
$wnd.WRITE_TIME_TRIGGERED = false
$wnd.RECORD_BATCH_SIZE = 1 // increase for normal usage...
function initMonitoring() {
if (typeof String.prototype.startsWith != 'function') {
String.prototype.startsWith = function(str) {
for (var i = 0; i < str.length; i++) {
......@@ -16,11 +20,11 @@ public class AspectWeaver {
$wnd.moduleCacheJSLines = null
$wnd.moduleCacheJSLineLength = -1
$wnd.functionLineMap = {}
$wnd.filenameMap = {}
$wnd.monitoringCache = []
$wnd.classFilenameMap = {}
$wnd.recordBatchStorage = []
$wnd.currentStackDepth = 0
$wnd.traceID = 0
$wnd.traceID = 0 // TODO init from server?
$wnd.orderID = 0
$wnd.lastWrite = 0
......@@ -34,89 +38,99 @@ public class AspectWeaver {
$wnd.jQuery().readSourceMapURL(
'http://localhost:9876/sourcemaps/gwtmonitoring/' + $strongName
+ '_sourcemap.json');
}
function aspectInvoc(invocation) {
// JS source not yet fetched therefore only proceed
if ($wnd.moduleCacheJSLineLength == -1)
return invocation.proceed();
function fetchLineNumber(methodname) {
var linenumber = -1;
if (invocation.method in $wnd.functionLineMap) {
linenumber = $wnd.functionLineMap[invocation.method]
if (methodname in $wnd.functionLineMap) {
linenumber = $wnd.functionLineMap[methodname]
} else {
// var firstL1 = $wnd.performance.now()
var toSeekName = 'function ' + invocation.method;
var toSeekName = 'function ' + methodname;
var toSeekNameLength = toSeekName.length
var lines = $wnd.moduleCacheJSLines
var length = $wnd.moduleCacheJSLineLength
var firstMethodChar = invocation.method[0]
var firstMethodChar = methodname[0]
for (var i = 0; i < length; i++) {
var line = lines[i];
if (line.length >= toSeekNameLength
&& line[9] == firstMethodChar
&& line.startsWith(toSeekName)) {
linenumber = i + 1;
$wnd.functionLineMap[invocation.method] = linenumber;
$wnd.functionLineMap[methodname] = linenumber;
// console.log("lookup of " + toSeekName + " took "
// + ($wnd.performance.now() - firstL1))
break;
}
}
}
return linenumber;
}
var filename = null;
if (linenumber in $wnd.filenameMap) {
filename = $wnd.filenameMap[linenumber]
function fetchClassFilename(linenumber) {
if (linenumber in $wnd.classFilenameMap) {
return $wnd.classFilenameMap[linenumber];
} else {
var filename = $wnd.jQuery().lookupFilename(linenumber)
$wnd.filenameMap[linenumber] = filename
filename = $wnd.jQuery().lookupFilename(linenumber)
$wnd.classFilenameMap[linenumber] = filename
return filename;
}
}
if (!filename.startsWith("kieker/monitoring/gwt/client"))
return invocation.proceed()
function finishTraceIfNecessary() {
// LESS is if we started in the middle of the trace...
if ($wnd.currentStackDepth <= 0) {
// we finished the trace
$wnd.traceID++;
$wnd.orderID = 0;
$wnd.currentStackDepth = 0;
};
}
function aspectInvoc(invocation) {
// JS source not yet fetched therefore only proceed
if ($wnd.moduleCacheJSLineLength == -1)
return invocation.proceed();
// TODO replace method with StringRegistryID and send those records...
var linenumber = fetchLineNumber(invocation.method)
// dont monitor self...
if (filename.startsWith("kieker/monitoring/gwt/client/monitoring"))
var classFilename = fetchClassFilename(linenumber)
if (classFilename.startsWith("kieker/monitoring/gwt/client/monitoring") || !classFilename.startsWith("kieker/monitoring/gwt/client"))
return invocation.proceed()
// BEFORE; should be an record ID
$wnd.monitoringCache.push("BEFORE;" + $wnd.performance.now() + ";" + $wnd.traceID + ";" + $wnd.orderID + ";" + filename + ";" + invocation.method);
$wnd.orderID++;
$wnd.recordBatchStorage.push("1;" + $wnd.performance.now() + ";" + $wnd.traceID + ";" + ($wnd.orderID++) + ";" + classFilename + ";" + invocation.method);
$wnd.currentStackDepth++;
var result = invocation.proceed();
$wnd.currentStackDepth--;
// AFTER; should be an record ID
$wnd.monitoringCache.push("AFTER;" + $wnd.performance.now() + ";" + $wnd.traceID + ";" + $wnd.orderID + ";" + filename + ";" + invocation.method);
$wnd.orderID++;
var afterTimestamp = $wnd.performance.now()
$wnd.recordBatchStorage.push("3;" + afterTimestamp + ";" + $wnd.traceID + ";" + ($wnd.orderID++));
if ($wnd.monitoringCache.length >= 1) { // TODO increase for normal usage
@kieker.monitoring.gwt.client.monitoring.MetaMonitoringManager::sendRecordBundle(Ljava/lang/String;)($wnd.monitoringCache.toString())
$wnd.monitoringCache = [];
if (!$wnd.WRITE_TIME_TRIGGERED) {
if ($wnd.recordBatchStorage.length >= $wnd.RECORD_BATCH_SIZE) {
@kieker.monitoring.gwt.client.monitoring.MonitoringManager::sendRecordBundle(Ljava/lang/String;)($wnd.recordBatchStorage.toString())
$wnd.recordBatchStorage = [];
}
} else {
if (afterTimestamp - $wnd.lastWrite > 1000) {
$wnd.lastWrite = afterTimestamp
@kieker.monitoring.gwt.client.monitoring.MonitoringManager::sendRecordBundle(Ljava/lang/String;)($wnd.recordBatchStorage.toString())
$wnd.recordBatchStorage = [];
}
}
// time triggered:
// if (afterT - $wnd.lastWrite > 1000) {
// $wnd.lastWrite = afterT
// @kieker.monitoring.gwt.client.monitoring.MetaMonitoringManager::sendRecordBundle(Ljava/lang/String;)($wnd.monitoringCache.toString())
// $wnd.monitoringCache = [];
// }
// LESS is if we started in the middle of the trace...
if ($wnd.currentStackDepth <= 0) {
// we finished the trace
$wnd.traceID++;
$wnd.orderID = 0;
$wnd.currentStackDepth = 0;
};
finishTraceIfNecessary();
return result;
}
initMonitoring();
$wnd.jQuery.aop
.around(
{
......
......@@ -4,8 +4,8 @@ import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
public class MetaMonitoringManager {
private static MetaMonitoringServiceAsync metaMonitoringService;
public class MonitoringManager {
private static MonitoringServiceAsync metaMonitoringService;
private static boolean MONITORING_ENABLED = true;
......@@ -16,10 +16,10 @@ public class MetaMonitoringManager {
}
}
private static MetaMonitoringServiceAsync createAsyncService() {
MetaMonitoringServiceAsync metaMonitoringService = GWT.create(MetaMonitoringService.class);
private static MonitoringServiceAsync createAsyncService() {
MonitoringServiceAsync metaMonitoringService = GWT.create(MonitoringService.class);
ServiceDefTarget endpoint = (ServiceDefTarget) metaMonitoringService;
String moduleRelativeURL = GWT.getModuleBaseURL() + "metamonitoring";
String moduleRelativeURL = GWT.getModuleBaseURL() + "monitoring";
endpoint.setServiceEntryPoint(moduleRelativeURL);
return metaMonitoringService;
}
......
......@@ -3,7 +3,7 @@ package kieker.monitoring.gwt.client.monitoring;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
@RemoteServiceRelativePath("metamonitoring")
public interface MetaMonitoringService extends RemoteService {
@RemoteServiceRelativePath("monitoring")
public interface MonitoringService extends RemoteService {
public void sendRecordBundle(String recordBundle);
}
......@@ -2,6 +2,6 @@ package kieker.monitoring.gwt.client.monitoring;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface MetaMonitoringServiceAsync {
public interface MonitoringServiceAsync {
void sendRecordBundle(String recordBundle, AsyncCallback<Void> callback);
}
package kieker.monitoring.gwt.server.monitoring;
public class ExplorVizRecordWriter implements IGWTRecordWriter {
@Override
public void writeBeforeRecord(long timestamp, long traceId, int orderId,
String clazzname, String method) {
System.out.println(timestamp + " " + traceId + " " + orderId + " " + clazzname + " " + method);
}
@Override
public void writeAfterRecord(long timestamp, long traceId, int orderId) {
System.out.println(timestamp + " " + traceId + " " + orderId);
}
}
package kieker.monitoring.gwt.server.monitoring;
public interface IGWTRecordWriter {
public void writeBeforeRecord(long timestamp, long traceId, int orderId, String clazzname, String method);
public void writeAfterRecord(long timestamp, long traceId, int orderId);
}
package kieker.monitoring.gwt.server.monitoring;
public class KiekerRecordWriter implements IGWTRecordWriter {
@Override
public void writeBeforeRecord(long timestamp, long traceId, int orderId,
String clazzname, String method) {
// TODO Auto-generated method stub
}
@Override
public void writeAfterRecord(long timestamp, long traceId, int orderId) {
// TODO Auto-generated method stub
}
}
package kieker.monitoring.gwt.server.monitoring;
import kieker.monitoring.gwt.client.monitoring.MetaMonitoringService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
public class MetaMonitoringServiceImpl extends RemoteServiceServlet implements
MetaMonitoringService {
private static final long serialVersionUID = -1474770740583197159L;
@Override
public void sendRecordBundle(final String recordBundle) {
final String[] splitRecords = recordBundle.split(",");
for (final String record : splitRecords) {
System.out.println(record);
if (record.contains(";")) {
// BEFORE record
final String[] beforeRecordSplit = record.split(";");
} else {
// AFTER record
}
}
}
}
package kieker.monitoring.gwt.server.monitoring;
import kieker.monitoring.gwt.client.monitoring.MonitoringService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
public class MonitoringServiceImpl extends RemoteServiceServlet implements
MonitoringService {
private static final long serialVersionUID = -1474770740583197159L;
IGWTRecordWriter writer = new ExplorVizRecordWriter();
@Override
public void sendRecordBundle(final String recordBundle) {
final String[] splitRecords = recordBundle.split(",");
for (final String record : splitRecords) {
final String[] splitRecord = record.split(";");
// TODO always throw away trace 0?
String recordId = splitRecord[0];
if (recordId.equals("1")) { // BEFORE record
writer.writeBeforeRecord(
convertTimestampToNano(splitRecord[1]),
Long.parseLong(splitRecord[2]),
Integer.parseInt(splitRecord[3]),
convertClassname(splitRecord[4]),
convertMethod(splitRecord[5]));
} else if (recordId.equals("3")) { // AFTER record
writer.writeAfterRecord(
convertTimestampToNano(splitRecord[1]),
Long.parseLong(splitRecord[2]),
Integer.parseInt(splitRecord[3]));
}
}
}
private final long convertTimestampToNano(String timestampInMsec) {
final double timestampInDouble = Double.parseDouble(timestampInMsec);
return Math.round(timestampInDouble * 1000 * 1000);
}
private final String convertClassname(String clazzFilename) {
final String withoutEnding = clazzFilename.substring(0, clazzFilename.indexOf("."));
return withoutEnding.replaceAll("/", ".");
}
private final String convertMethod(String method) {
final String withoutGS = method.substring(0,method.lastIndexOf("_"));
return withoutGS.substring(0,withoutGS.lastIndexOf("_")) + "()";
}
}
......@@ -6,12 +6,12 @@
xmlns="http://java.sun.com/xml/ns/javaee">
<servlet>
<servlet-name>MetaMonitoringService</servlet-name>
<servlet-class>kieker.monitoring.gwt.server.monitoring.MetaMonitoringServiceImpl</servlet-class>
<servlet-name>MonitoringService</servlet-name>
<servlet-class>kieker.monitoring.gwt.server.monitoring.MonitoringServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MetaMonitoringService</servlet-name>
<servlet-name>MonitoringService</servlet-name>
<url-pattern>/gwtmonitoring/metamonitoring</url-pattern>
</servlet-mapping>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment