From 832364f2dbcdfa6ac32cf350af17adc2c46aeda0 Mon Sep 17 00:00:00 2001 From: danthe1st Date: Tue, 3 Sep 2024 14:56:57 +0200 Subject: [PATCH] improve JFR custom events --- .../FilterMutualExclusionConstraintsEvent.java | 13 +++++++++++++ .../arebac/gpeval/ForwardCheckingEvent.java | 15 +++++++++++++++ .../io/github/danthe1st/arebac/gpeval/GPEval.java | 13 ++++++++++--- .../arebac/jfr/events/FindEdgesEvent.java | 8 ++++---- .../arebac/jfr/events/FindNodeEvent.java | 2 +- .../arebac/jfr/events/GetAttributeEvent.java | 8 ++++---- 6 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 arebac-core/src/main/java/io/github/danthe1st/arebac/gpeval/FilterMutualExclusionConstraintsEvent.java diff --git a/arebac-core/src/main/java/io/github/danthe1st/arebac/gpeval/FilterMutualExclusionConstraintsEvent.java b/arebac-core/src/main/java/io/github/danthe1st/arebac/gpeval/FilterMutualExclusionConstraintsEvent.java new file mode 100644 index 0000000..80a569d --- /dev/null +++ b/arebac-core/src/main/java/io/github/danthe1st/arebac/gpeval/FilterMutualExclusionConstraintsEvent.java @@ -0,0 +1,13 @@ +package io.github.danthe1st.arebac.gpeval; + +import jdk.jfr.Category; +import jdk.jfr.Description; +import jdk.jfr.Event; +import jdk.jfr.Name; + +@Name("io.github.danthe1st.arebac.gpeval.FilterMutualExclusionConstraintEvent") +@Description("filtering mutual exclusion constraints") +@Category("AReBAC") +class FilterMutualExclusionConstraintsEvent extends Event { + +} diff --git a/arebac-core/src/main/java/io/github/danthe1st/arebac/gpeval/ForwardCheckingEvent.java b/arebac-core/src/main/java/io/github/danthe1st/arebac/gpeval/ForwardCheckingEvent.java index 8859bb1..7de077e 100644 --- a/arebac-core/src/main/java/io/github/danthe1st/arebac/gpeval/ForwardCheckingEvent.java +++ b/arebac-core/src/main/java/io/github/danthe1st/arebac/gpeval/ForwardCheckingEvent.java @@ -10,4 +10,19 @@ @Category("AReBAC") class ForwardCheckingEvent extends Event { + @Name("valid neighbors") + @Description("the amount of neighbors processed that satisfy edge/attribute requirements") + private int validNeighborsProcessed; + + @Name("total neighbors") + @Description("the total amount of neighbors where edge/attribute requirements were checked") + private int neighborsTotal; + + void addNeighborsProcessed(int neighbors) { + this.validNeighborsProcessed += neighbors; + } + + void addNeighborsTotal(int neighbors) { + this.neighborsTotal += neighbors; + } } diff --git a/arebac-core/src/main/java/io/github/danthe1st/arebac/gpeval/GPEval.java b/arebac-core/src/main/java/io/github/danthe1st/arebac/gpeval/GPEval.java index dbe562f..3f77b6d 100644 --- a/arebac-core/src/main/java/io/github/danthe1st/arebac/gpeval/GPEval.java +++ b/arebac-core/src/main/java/io/github/danthe1st/arebac/gpeval/GPEval.java @@ -247,10 +247,12 @@ private GPNode pickNextNode() { } private void filterMutualExclusionConstraints(Set candidatesForNode, Set exclusionConstraints, Set incomingConflicts) { + FilterMutualExclusionConstraintsEvent event = new FilterMutualExclusionConstraintsEvent(); + event.begin(); for(Iterator it = candidatesForNode.iterator(); it.hasNext();){ filterMutualExclusionConstraintWithSpecificCandidate(exclusionConstraints, incomingConflicts, it); } - + event.commit(); } private void filterMutualExclusionConstraintWithSpecificCandidate(Set exclusionConstraints, Set incomingConflicts, Iterator it) { @@ -267,11 +269,13 @@ private void filterMutualExclusionConstraintWithSpecificCandidate(Set ex private boolean forwardChecking(GPNode currentNode, Map> incomingConflicts, Set outgoingConflicts) { ForwardCheckingEvent forwardCheckingEvent = new ForwardCheckingEvent(); forwardCheckingEvent.begin(); + List relevantEdges = getRelevantEdges(currentNode); for(RelevantEdge relevantEdge : relevantEdges){ GPNode otherNode = relevantEdge.otherNode(); if(!assignments.containsKey(otherNode)){ - List neighbors = getNeighborsSatisfyingEdgeAndAttributeRequirements(currentNode, relevantEdge); + List neighbors = getNeighborsSatisfyingEdgeAndAttributeRequirements(currentNode, relevantEdge, forwardCheckingEvent); + forwardCheckingEvent.addNeighborsProcessed(neighbors.size()); Set otherNodeCandidates = candidates.get(otherNode); assert otherNodeCandidates == null || !otherNodeCandidates.isEmpty();// I think this shouldn't happen, null is written as empty in the paper Set otherNodeIncomingConflicts = incomingConflicts.computeIfAbsent(otherNode, n -> new HashSet<>()); @@ -297,7 +301,7 @@ private boolean forwardChecking(GPNode currentNode, Map> inc return true; } - private List getNeighborsSatisfyingEdgeAndAttributeRequirements(GPNode currentNode, RelevantEdge relevantEdge) { + private List getNeighborsSatisfyingEdgeAndAttributeRequirements(GPNode currentNode, RelevantEdge relevantEdge, ForwardCheckingEvent forwardCheckingEvent) { N currentNodeInDB = assignments.get(currentNode); Collection graphEdges; Function neighborFinder; @@ -316,6 +320,9 @@ private List getNeighborsSatisfyingEdgeAndAttributeRequirements(GPNode curren neighborsSatisfyingRequirements.add(neighbor); } } + + forwardCheckingEvent.addNeighborsTotal(graphEdges.size()); + return neighborsSatisfyingRequirements; } diff --git a/arebac-jfr/src/main/java/io/github/danthe1st/arebac/jfr/events/FindEdgesEvent.java b/arebac-jfr/src/main/java/io/github/danthe1st/arebac/jfr/events/FindEdgesEvent.java index b14a282..1f4cbff 100644 --- a/arebac-jfr/src/main/java/io/github/danthe1st/arebac/jfr/events/FindEdgesEvent.java +++ b/arebac-jfr/src/main/java/io/github/danthe1st/arebac/jfr/events/FindEdgesEvent.java @@ -15,16 +15,16 @@ public class FindEdgesEvent extends Event { static final String NAME = "io.github.danthe1st.arebac.jfr.events.FindEdgesEvent"; @Label("node ID") - String nodeId; + private String nodeId; @Label("outgoing") - boolean outgoing; + private boolean outgoing; @Label("incoming") - boolean incoming; + private boolean incoming; @Label("foundEdgesCount") - int foundEdgesCount; + private int foundEdgesCount; public FindEdgesEvent(String nodeId, Direction direction) { this.nodeId = nodeId; diff --git a/arebac-jfr/src/main/java/io/github/danthe1st/arebac/jfr/events/FindNodeEvent.java b/arebac-jfr/src/main/java/io/github/danthe1st/arebac/jfr/events/FindNodeEvent.java index 9d218e8..1e943fc 100644 --- a/arebac-jfr/src/main/java/io/github/danthe1st/arebac/jfr/events/FindNodeEvent.java +++ b/arebac-jfr/src/main/java/io/github/danthe1st/arebac/jfr/events/FindNodeEvent.java @@ -13,7 +13,7 @@ public class FindNodeEvent extends Event { static final String NAME = "io.github.danthe1st.arebac.jfr.events.FindNodeEvent"; @Label("node ID") - String nodeId; + private String nodeId; public FindNodeEvent(String nodeId) { this.nodeId = nodeId; diff --git a/arebac-jfr/src/main/java/io/github/danthe1st/arebac/jfr/events/GetAttributeEvent.java b/arebac-jfr/src/main/java/io/github/danthe1st/arebac/jfr/events/GetAttributeEvent.java index 68ab16e..30f3b30 100644 --- a/arebac-jfr/src/main/java/io/github/danthe1st/arebac/jfr/events/GetAttributeEvent.java +++ b/arebac-jfr/src/main/java/io/github/danthe1st/arebac/jfr/events/GetAttributeEvent.java @@ -16,17 +16,17 @@ public class GetAttributeEvent extends Event { @Label("element ID") @Description("ID of the node or edge") - String elementId; + private String elementId; @Label("attribute name") - String attributeName; + private String attributeName; @Label("element is node") @Description("true iff this event represents getting the attribute of a node") - boolean isNode; + private boolean isNode; @Label("element is edge") @Description("true iff this event represents getting the attribute of a edge") - boolean isEdge; + private boolean isEdge; public GetAttributeEvent(String elementId, String attributeName, ElementType type) { this.elementId = elementId;