From 588545d8125533b71e73f32a36227d808bd914f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20M=C3=BCller?= Date: Mon, 31 Aug 2020 15:09:59 +0200 Subject: [PATCH 1/5] remove blank line --- .../contrib/plugin/kieker/api/model/CallsDescriptor.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/jqassistant/contrib/plugin/kieker/api/model/CallsDescriptor.java b/src/main/java/org/jqassistant/contrib/plugin/kieker/api/model/CallsDescriptor.java index 7a96362..d97d12c 100644 --- a/src/main/java/org/jqassistant/contrib/plugin/kieker/api/model/CallsDescriptor.java +++ b/src/main/java/org/jqassistant/contrib/plugin/kieker/api/model/CallsDescriptor.java @@ -11,5 +11,4 @@ public interface CallsDescriptor extends Descriptor, WeightDescriptor { @Relation.Incoming MethodDescriptor getCaller(); - } From cff7982ebb83fe4e861c90c8a9970eb6296809ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20M=C3=BCller?= Date: Mon, 31 Aug 2020 15:11:33 +0200 Subject: [PATCH 2/5] remove TraceDescriptor --- .../kieker/api/model/RecordDescriptor.java | 2 +- .../kieker/api/model/TraceDescriptor.java | 37 ------------- .../kieker/impl/scanner/KiekerHelper.java | 54 ++++++------------- .../impl/scanner/KiekerRecordReceiver.java | 3 -- .../resources/META-INF/jqassistant-plugin.xml | 1 - 5 files changed, 18 insertions(+), 79 deletions(-) delete mode 100644 src/main/java/org/jqassistant/contrib/plugin/kieker/api/model/TraceDescriptor.java diff --git a/src/main/java/org/jqassistant/contrib/plugin/kieker/api/model/RecordDescriptor.java b/src/main/java/org/jqassistant/contrib/plugin/kieker/api/model/RecordDescriptor.java index 37093fa..7e70664 100644 --- a/src/main/java/org/jqassistant/contrib/plugin/kieker/api/model/RecordDescriptor.java +++ b/src/main/java/org/jqassistant/contrib/plugin/kieker/api/model/RecordDescriptor.java @@ -15,7 +15,7 @@ public interface RecordDescriptor extends KiekerDescriptor, DirectoryDescriptor { @Relation("CONTAINS") - List getTraces(); + List getMethods(); @Relation("CONTAINS") List getMeasurements(); diff --git a/src/main/java/org/jqassistant/contrib/plugin/kieker/api/model/TraceDescriptor.java b/src/main/java/org/jqassistant/contrib/plugin/kieker/api/model/TraceDescriptor.java deleted file mode 100644 index 49d3acf..0000000 --- a/src/main/java/org/jqassistant/contrib/plugin/kieker/api/model/TraceDescriptor.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.jqassistant.contrib.plugin.kieker.api.model; - -import com.buschmais.jqassistant.plugin.common.api.model.NamedDescriptor; -import com.buschmais.xo.neo4j.api.annotation.Label; -import com.buschmais.xo.neo4j.api.annotation.Relation; - -import java.util.List; - -/** - * Defines the node for a Trace of a record. - */ -@Label("Trace") -public interface TraceDescriptor extends NamedDescriptor, KiekerDescriptor { - - @Relation("CONTAINS") - List getMethods(); - - void setLoggingTimestamp(long timestamp); - - long getLoggingTimestamp(); - - void setTraceId(long traceId); - - long getTraceId(); - - void setThreadId(long threadId); - - long getThreadId(); - - void setSessionId(String sessionId); - - String getSessionId(); - - void setHostname(String hostname); - - String getHostname(); -} diff --git a/src/main/java/org/jqassistant/contrib/plugin/kieker/impl/scanner/KiekerHelper.java b/src/main/java/org/jqassistant/contrib/plugin/kieker/impl/scanner/KiekerHelper.java index b6e2bb1..ff9c401 100644 --- a/src/main/java/org/jqassistant/contrib/plugin/kieker/impl/scanner/KiekerHelper.java +++ b/src/main/java/org/jqassistant/contrib/plugin/kieker/impl/scanner/KiekerHelper.java @@ -4,7 +4,6 @@ import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; import kieker.common.record.IMonitoringRecord; -import kieker.common.record.flow.trace.TraceMetadata; import kieker.common.record.flow.trace.operation.AbstractOperationEvent; import kieker.common.record.flow.trace.operation.AfterOperationEvent; import kieker.common.record.flow.trace.operation.BeforeOperationEvent; @@ -36,7 +35,6 @@ public class KiekerHelper { private RecordDescriptor recordDescriptor; private Cache methodDescriptorCache; private Cache callsDescriptorCache; - private Map traceCache; private Map> timestampCache; private final String REGEX_FOR_METHOD_NAME = "([a-zA-Z0-9_]+) *\\("; @@ -45,7 +43,6 @@ public KiekerHelper(ScannerContext scannerContext, RecordDescriptor recordDescri this.recordDescriptor = recordDescriptor; this.methodDescriptorCache = Caffeine.newBuilder().maximumSize(100000).build(); this.callsDescriptorCache = Caffeine.newBuilder().maximumSize(10000000).build(); - this.traceCache = new HashMap<>(); this.timestampCache = new HashMap<>(); } @@ -60,17 +57,6 @@ void createRecord(KiekerMetadataRecord record) { recordDescriptor.setNumberOfRecords(record.getNumberOfRecords()); } - void createTrace(TraceMetadata trace) { - TraceDescriptor traceDescriptor = scannerContext.getStore().create(TraceDescriptor.class); - traceDescriptor.setLoggingTimestamp(trace.getLoggingTimestamp()); - traceDescriptor.setTraceId(trace.getTraceId()); - traceDescriptor.setThreadId(trace.getThreadId()); - traceDescriptor.setSessionId(trace.getSessionId()); - traceDescriptor.setHostname(trace.getHostname()); - recordDescriptor.getTraces().add(traceDescriptor); - traceCache.put(trace.getTraceId(), traceDescriptor); - } - void createEvent(AbstractOperationEvent event) { if (event instanceof BeforeOperationEvent || event instanceof AfterOperationEvent) { if (event instanceof BeforeOperationEvent) { @@ -83,10 +69,6 @@ void createEvent(AbstractOperationEvent event) { BeforeOperationEvent beforeOperationEvent = popFromTimestampStack(methodDescriptor.getSignature()); if (beforeOperationEvent != null) { methodDescriptor.setDuration(methodDescriptor.getDuration() + (event.getTimestamp() - beforeOperationEvent.getTimestamp())); - // add method to trace if not already done - if (!getTraceDescriptor(event).getMethods().contains(methodDescriptor)) { - getTraceDescriptor(event).getMethods().add(methodDescriptor); - } } else { LOGGER.warn("BeforeOperationEvent for method " + methodDescriptor.getSignature() + " missing."); } @@ -96,12 +78,14 @@ void createEvent(AbstractOperationEvent event) { CallOperationEvent callOperationEvent = (CallOperationEvent) event; MethodDescriptor caller = getMethodDescriptor(callOperationEvent.getCallerClassSignature(), callOperationEvent.getCallerOperationSignature()); MethodDescriptor callee = getMethodDescriptor(callOperationEvent.getCalleeClassSignature(), callOperationEvent.getCalleeOperationSignature()); + // update number of incoming and outgoing calls + if (callOperationEvent.getOrderIndex() == 1) { + caller.setIncomingCalls(caller.getIncomingCalls() + 1); + } + caller.setOutgoingCalls(caller.getOutgoingCalls() + 1); + callee.setIncomingCalls(callee.getIncomingCalls() + 1); // add call addCall(caller, callee); - // add caller to trace if not already done - if (!getTraceDescriptor(event).getMethods().contains(caller)) { - getTraceDescriptor(event).getMethods().add(caller); - } } } @@ -127,27 +111,19 @@ private synchronized BeforeOperationEvent popFromTimestampStack(String signature } } - private TraceDescriptor getTraceDescriptor(AbstractOperationEvent event) { - TraceDescriptor traceDescriptor; - if (traceCache.containsKey(event.getTraceId())) { - traceDescriptor = traceCache.get(event.getTraceId()); - } else { - traceDescriptor = scannerContext.getStore().create(TraceDescriptor.class); - traceDescriptor.setTraceId(event.getTraceId()); - recordDescriptor.getTraces().add(traceDescriptor); - traceCache.put(event.getTraceId(), traceDescriptor); - } - return traceDescriptor; - } - private MethodDescriptor getMethodDescriptor(String fqn, String signature) { return methodDescriptorCache.get(MethodDescriptorKey.builder().type(fqn).signature(signature).build(), methodDescriptorKey -> { Map params = new HashMap<>(); params.put("fqn", fqn); params.put("typeName", fqn.substring(fqn.lastIndexOf(".") + 1)); params.put("signature", signature); - params.put("methodName", getMethodNameFromSignature(signature)); - return scannerContext.getStore().executeQuery("MERGE (t:Kieker:Type{fqn:$fqn}) ON CREATE SET t.name=$typeName MERGE (t)-[:DECLARES]->(m:Kieker:Method{signature:$signature,name:$methodName}) RETURN m", params).getSingleResult().get("m", MethodDescriptor.class); + // exclude encoded signature as no method name can be created + if (signature.endsWith(")")) { + params.put("methodName", getMethodNameFromSignature(signature)); + return scannerContext.getStore().executeQuery("MERGE (t:Kieker:Type{fqn:$fqn}) ON CREATE SET t.name=$typeName MERGE (t)-[:DECLARES]->(m:Kieker:Method{signature:$signature,name:$methodName}) RETURN m", params).getSingleResult().get("m", MethodDescriptor.class); + } else { + return scannerContext.getStore().executeQuery("MERGE (t:Kieker:Type{fqn:$fqn}) ON CREATE SET t.name=$typeName MERGE (t)-[:DECLARES]->(m:Kieker:Method{signature:$signature}) RETURN m", params).getSingleResult().get("m", MethodDescriptor.class); + } }); } @@ -276,4 +252,8 @@ private static class CallsDescriptorKey { private MethodDescriptor callee; } + + public void addMethodsToRecord() { + recordDescriptor.getMethods().addAll(methodDescriptorCache.asMap().values()); + } } diff --git a/src/main/java/org/jqassistant/contrib/plugin/kieker/impl/scanner/KiekerRecordReceiver.java b/src/main/java/org/jqassistant/contrib/plugin/kieker/impl/scanner/KiekerRecordReceiver.java index 164f42c..80e6a10 100644 --- a/src/main/java/org/jqassistant/contrib/plugin/kieker/impl/scanner/KiekerRecordReceiver.java +++ b/src/main/java/org/jqassistant/contrib/plugin/kieker/impl/scanner/KiekerRecordReceiver.java @@ -2,7 +2,6 @@ import kieker.analysis.plugin.reader.util.IMonitoringRecordReceiver; import kieker.common.record.IMonitoringRecord; -import kieker.common.record.flow.trace.TraceMetadata; import kieker.common.record.flow.trace.operation.AbstractOperationEvent; import kieker.common.record.misc.KiekerMetadataRecord; import kieker.common.record.system.*; @@ -34,8 +33,6 @@ public KiekerRecordReceiver(KiekerHelper kiekerHelper) { public boolean newMonitoringRecord(IMonitoringRecord iMonitoringRecord) { if (iMonitoringRecord instanceof KiekerMetadataRecord) { kiekerHelper.createRecord((KiekerMetadataRecord) iMonitoringRecord); - } else if (iMonitoringRecord instanceof TraceMetadata) { - kiekerHelper.createTrace((TraceMetadata) iMonitoringRecord); } else if (iMonitoringRecord instanceof AbstractOperationEvent) { kiekerHelper.createEvent((AbstractOperationEvent) iMonitoringRecord); } else if (iMonitoringRecord instanceof CPUUtilizationRecord || iMonitoringRecord instanceof DiskUsageRecord || diff --git a/src/main/resources/META-INF/jqassistant-plugin.xml b/src/main/resources/META-INF/jqassistant-plugin.xml index b82b6e8..f9ad65b 100644 --- a/src/main/resources/META-INF/jqassistant-plugin.xml +++ b/src/main/resources/META-INF/jqassistant-plugin.xml @@ -3,7 +3,6 @@ Provides a scanner for Kieker files. org.jqassistant.contrib.plugin.kieker.api.model.MethodDescriptor - org.jqassistant.contrib.plugin.kieker.api.model.TraceDescriptor org.jqassistant.contrib.plugin.kieker.api.model.TypeDescriptor org.jqassistant.contrib.plugin.kieker.api.model.RecordDescriptor org.jqassistant.contrib.plugin.kieker.api.model.CallsDescriptor From e3fb3c5ab0f94609ffdd21e9e9e328ad93d1d096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20M=C3=BCller?= Date: Mon, 31 Aug 2020 15:12:07 +0200 Subject: [PATCH 3/5] add methods to record --- .../kieker/impl/scanner/KiekerDirectoryScannerPlugin.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jqassistant/contrib/plugin/kieker/impl/scanner/KiekerDirectoryScannerPlugin.java b/src/main/java/org/jqassistant/contrib/plugin/kieker/impl/scanner/KiekerDirectoryScannerPlugin.java index e242f72..7f147a1 100644 --- a/src/main/java/org/jqassistant/contrib/plugin/kieker/impl/scanner/KiekerDirectoryScannerPlugin.java +++ b/src/main/java/org/jqassistant/contrib/plugin/kieker/impl/scanner/KiekerDirectoryScannerPlugin.java @@ -50,13 +50,17 @@ protected RecordDescriptor getContainerDescriptor(File container, ScannerContext final RecordDescriptor recordDescriptor = scannerContext.getStore().addDescriptorType(directoryDescriptor, RecordDescriptor.class); // Set record receiver that maps read records to corresponding descriptors - KiekerRecordReceiver kiekerRecordReceiver = new KiekerRecordReceiver(new KiekerHelper(scannerContext, recordDescriptor)); + KiekerHelper kiekerHelper = new KiekerHelper(scannerContext, recordDescriptor); + KiekerRecordReceiver kiekerRecordReceiver = new KiekerRecordReceiver(kiekerHelper); // Set filesystem directory reader (reads *.map, *.dat, *.bin, *.xz files in a directory) // Todo use another reader FSDirectoryReader fsDirectoryReader = new FSDirectoryReader(container, kiekerRecordReceiver, true); fsDirectoryReader.run(); + // add all methods to record + kiekerHelper.addMethodsToRecord(); + return recordDescriptor; } @@ -70,7 +74,6 @@ protected RecordDescriptor getContainerDescriptor(File container, ScannerContext */ @Override protected void enterContainer(File container, RecordDescriptor containerDescriptor, ScannerContext scannerContext) throws IOException { - } /** @@ -82,6 +85,5 @@ protected void enterContainer(File container, RecordDescriptor containerDescript */ @Override protected void leaveContainer(File container, RecordDescriptor containerDescriptor, ScannerContext scannerContext) throws IOException { - } } From 280ea2a0fabd6e37b0c9f54125cdac77dda359ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20M=C3=BCller?= Date: Mon, 31 Aug 2020 15:44:43 +0200 Subject: [PATCH 4/5] remove trace from tests --- .../contrib/plugin/kieker/test/RecordIT.java | 3 - .../contrib/plugin/kieker/test/TraceIT.java | 55 ------------------- 2 files changed, 58 deletions(-) delete mode 100644 src/test/java/org/jqassistant/contrib/plugin/kieker/test/TraceIT.java diff --git a/src/test/java/org/jqassistant/contrib/plugin/kieker/test/RecordIT.java b/src/test/java/org/jqassistant/contrib/plugin/kieker/test/RecordIT.java index d1d380b..eed7045 100644 --- a/src/test/java/org/jqassistant/contrib/plugin/kieker/test/RecordIT.java +++ b/src/test/java/org/jqassistant/contrib/plugin/kieker/test/RecordIT.java @@ -17,9 +17,6 @@ public void testRecord() { File directory = new File(TEST_DIRECTORY_PATH); store.beginTransaction(); getScanner().scan(directory, TEST_DIRECTORY_PATH, DefaultScope.NONE); - TestResult testResult = query("MATCH (:Record)-[:CONTAINS]->(t:Trace) RETURN t"); - // one record with two traces - assertThat(testResult.getColumn("t").size(), equalTo(2)); // test property values TestResult testResultProperties = query( diff --git a/src/test/java/org/jqassistant/contrib/plugin/kieker/test/TraceIT.java b/src/test/java/org/jqassistant/contrib/plugin/kieker/test/TraceIT.java deleted file mode 100644 index 66b8fa8..0000000 --- a/src/test/java/org/jqassistant/contrib/plugin/kieker/test/TraceIT.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.jqassistant.contrib.plugin.kieker.test; - -import com.buschmais.jqassistant.core.scanner.api.DefaultScope; -import com.buschmais.jqassistant.plugin.common.test.AbstractPluginIT; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -import java.io.File; - -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.MatcherAssert.assertThat; - -public class TraceIT extends AbstractPluginIT { - - @Test - @Disabled - public void testTrace() { - final String TEST_DIRECTORY_PATH = "src/test/resources/bookstore"; - File directory = new File(TEST_DIRECTORY_PATH); - store.beginTransaction(); - getScanner().scan(directory, TEST_DIRECTORY_PATH, DefaultScope.NONE); - - TestResult testResultBeforeOperation = query("MATCH (:Trace)-[:CONTAINS]->(b:BeforeOperation) RETURN b"); - // Overall the record contains 5 AfterOperationEvents - assertThat(testResultBeforeOperation.getColumn("b").size(), equalTo(5)); - - TestResult testResultAfterOperation = query("MATCH (:Trace)-[:CONTAINS]->(a:AfterOperation) RETURN a"); - // Overall the record contains 5 AfterOperationEvents - assertThat(testResultAfterOperation.getColumn("a").size(), equalTo(5)); - - // Number of Before- and AfterOperationEvents has to be the same. - Integer aSize = testResultAfterOperation.getColumn("a").size(); - assertThat(testResultBeforeOperation.getColumn("b").size(), equalTo(aSize)); - - // test property values - TestResult testResultProperties = query( - "MATCH (n:Trace) Where n.threadId=1 RETURN n.threadId, n.traceId, n.hostname, n.parentOrderId, n.sessionId, n.parentTraceId, n.loggingTimestamp"); - // threadId is "1" - assertThat(testResultProperties.getColumn("n.threadId").get(0).toString(), equalTo("1")); - // traceId is "3881283897249497088" - assertThat(testResultProperties.getColumn("n.traceId").get(0).toString(), equalTo("3881283897249497088")); - // hostname is "" - assertThat(testResultProperties.getColumn("n.hostname").get(0).toString(), equalTo("SE")); - // parentOrderId is "-1" - assertThat(testResultProperties.getColumn("n.parentOrderId").get(0).toString(), equalTo("-1")); - // sessionId is "" - assertThat(testResultProperties.getColumn("n.sessionId").get(0).toString(), equalTo("")); - // parentTraceId is "3881283897249497088" - assertThat(testResultProperties.getColumn("n.parentTraceId").get(0).toString(), equalTo("3881283897249497088")); - // loggingTimestamp is "1412763178834633375" - assertThat(testResultProperties.getColumn("n.loggingTimestamp").get(0).toString(), - equalTo("1412763178834633375")); - store.commitTransaction(); - } -} From f4cfe943cb7c82277e08753be8bcdbefba22560d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20M=C3=BCller?= Date: Mon, 31 Aug 2020 15:47:27 +0200 Subject: [PATCH 5/5] remove event from test --- .../org/jqassistant/contrib/plugin/kieker/test/MethodIT.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/java/org/jqassistant/contrib/plugin/kieker/test/MethodIT.java b/src/test/java/org/jqassistant/contrib/plugin/kieker/test/MethodIT.java index f113027..b9b8403 100644 --- a/src/test/java/org/jqassistant/contrib/plugin/kieker/test/MethodIT.java +++ b/src/test/java/org/jqassistant/contrib/plugin/kieker/test/MethodIT.java @@ -29,8 +29,6 @@ public void testMethod() { // kieker.examples.monitoring.aspectj.Bookstore.searchBook()" assertThat(testResultProperties.getColumn("m.signature").get(0).toString(), equalTo("public void kieker.examples.monitoring.aspectj.Bookstore.searchBook()")); - // two events have this function -> 1 After- plus 1 BeforeOperationEvent - assertThat(testResultProperties.getColumn("m.signature").size(), equalTo(1)); store.commitTransaction(); } }