doc: Update event matching developer documentation
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Tue, 18 Oct 2016 13:52:22 +0000 (09:52 -0400)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Thu, 20 Oct 2016 13:20:46 +0000 (09:20 -0400)
It has been outdated for a while now.

Change-Id: I5f5de85e8048a81457fae95ed5198f04b65ddf87
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/83439
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
doc/org.eclipse.tracecompass.doc.dev/doc/Developer-Guide.mediawiki

index 4e1772f6b9265e643a8d1e1571720f9f6cbebe18..062b673e5ad3d3ec0eb8f7c30f8df06fad252b87 100644 (file)
@@ -2987,13 +2987,11 @@ Here's a description of the major parts involved in event matching.  These class
 
 === ITmfEventMatching interface and derived classes ===
 
-This interface and its default abstract implementation '''TmfEventMatching''' control the event matching itself. Their only public method is ''matchEvents''. The class needs to manage how to setup the traces, and any initialization or finalization procedures.
+This interface controls the event matching itself. Their only public method is ''matchEvents''. The implementing classes needs to manage how to setup the traces, and any initialization or finalization procedures.
 
-The abstract class generates an event request for each trace from which events are matched and waits for the request to complete before calling the one from another trace. The ''handleData'' method from the request calls the ''matchEvent'' method that needs to be implemented in children classes.
+The is one concrete implementation of this interface: '''TmfEventMatching'''. It makes a request on the traces and match events where a ''cause'' event can be uniquely matched with a ''effect'' event. It creates a '''TmfEventDependency''' between the source and destination events. The dependency is added to the processing unit.
 
-Class '''TmfNetworkEventMatching''' is a concrete implementation of this interface. It applies to all use cases where a ''in'' event can be matched with a ''out' event (''in'' and ''out'' can be the same event, with different data). It creates a '''TmfEventDependency''' between the source and destination events. The dependency is added to the processing unit.
-
-To match events requiring other mechanisms (for instance, a series of events can be matched with another series of events), one would need to implement another class either extending '''TmfEventMatching''' or implementing '''ITmfEventMatching'''. It would most probably also require a new '''ITmfMatchEventDefinition''' implementation.
+To match events requiring other mechanisms (for instance, a series of events can be matched with another series of events), one would need to add another class either implementing '''ITmfEventMatching'''. It would most probably also require a new '''ITmfMatchEventDefinition''' implementation.
 
 === ITmfMatchEventDefinition interface and its derived classes ===
 
@@ -3003,12 +3001,16 @@ The '''canMatchTrace''' method will tell if a definition is compatible with a gi
 
 The '''getEventKey''' method will return a key for an event that uniquely identifies this event and will match the key from another event.
 
-Typically, there would be a match definition abstract class/interface per event matching type.
-
-The interface '''ITmfNetworkMatchDefinition''' adds the ''getDirection'' method to indicate whether this event is a ''in'' or ''out'' event to be matched with one from the opposite direction.
+The '''getDirection''' method indicates whether this event is a ''cause'' or ''effect'' event to be matched with one from the opposite direction.
 
 As examples, two concrete network match definitions have been implemented in the ''org.eclipse.tracecompass.internal.lttng2.kernel.core.event.matching'' package for two compatible methods of matching TCP packets (See the Trace Compass User Guide on ''trace synchronization'' for information on those matching methods). Each one tells which events need to be present in the metadata of a CTF trace for this matching method to be applicable. It also returns the field values from each event that will uniquely match 2 events together.
 
+Each '''IMatchEventDefinition''' needs to be registered to the '''TmfEventMatching''' class using the following code for example
+
+<pre>
+TmfEventMatching.registerMatchObject(new TcpEventMatching());
+</pre>
+
 === IMatchProcessingUnit interface and derived classes ===
 
 While matching events is an exercise in itself, it's what to do with the match that really makes this functionality interesting. This is the job of the '''IMatchProcessingUnit''' interface.
@@ -3056,7 +3058,7 @@ class MyAnalysis extends TmfAbstractAnalysisModule {
         };
 
         ITmfTrace[] traces = { getTrace() };
-        tcpMatching = new TmfNetworkEventMatching(traces, matchProcessing);
+        tcpMatching = new TmfEventMatching(traces, matchProcessing);
         tcpMatching.initMatching();
 
         MyEventRequest request = new MyEventRequest(this, i);
@@ -3096,7 +3098,7 @@ class MyEventRequest extends TmfEventRequest {
 }
 </pre>
 
-=== Match network events from UST traces ===
+=== Match events from UST traces ===
 
 Suppose a client-server application is instrumented using LTTng-UST. Traces are collected on the server and some clients on different machines. The traces can be synchronized using network event matching.
 
@@ -3131,15 +3133,45 @@ The following metadata describes the events:
 One would need to write an event match definition for those 2 events as follows:
 
 <pre>
-public class MyAppUstEventMatching implements ITmfNetworkMatchDefinition {
+public class MyAppUstEventMatching implements ITmfMatchEventDefinition {
+
+    public class MyEventMatchingKey implements IEventMatchingKey {
+
+        private static final HashFunction HF = checkNotNull(Hashing.goodFastHash(32));
+        private final int fTo;
+        private final long fId;
+
+        public MyEventMatchingKey(int to, long id) {
+            fTo = to;
+            fId = id;
+        }
+
+        @Override
+        public int hashCode() {
+            return HF.newHasher()
+                .putInt(fTo)
+                .putLong(fId).hash().asInt();
+        }
+
+        @Override
+        public boolean equals(@Nullable Object o) {
+            if (o instanceof MyEventMatchingKey) {
+                MyEventMatchingKey key = (MyEventMatchingKey) o;
+                return (key.fTo == fTo &&
+                    key.fId == fId);
+            }
+            return false;
+        }
+    }
+
 
     @Override
     public Direction getDirection(ITmfEvent event) {
         String evname = event.getType().getName();
         if (evname.equals("myapp:receive")) {
-            return Direction.IN;
+            return Direction.EFFECT;
         } else if (evname.equals("myapp:send")) {
-            return Direction.OUT;
+            return Direction.CAUSE;
         }
         return null;
     }
@@ -3161,30 +3193,27 @@ public class MyAppUstEventMatching implements ITmfNetworkMatchDefinition {
 
     @Override
     public boolean canMatchTrace(ITmfTrace trace) {
-        if (!(trace instanceof CtfTmfTrace)) {
+        Set<String> events = ImmutableSet.of("myapp:receive", "myapp:send");
+        if (!(trace instanceof ITmfTraceWithPreDefinedEvents)) {
             return false;
         }
-        CtfTmfTrace ktrace = (CtfTmfTrace) trace;
-        String[] events = { "myapp:receive", "myapp:send" };
-        return ktrace.hasAtLeastOneOfEvents(events);
-    }
+        ITmfTraceWithPreDefinedEvents ktrace = (ITmfTraceWithPreDefinedEvents) trace;
 
-    @Override
-    public MatchingType[] getApplicableMatchingTypes() {
-        MatchingType[] types = { MatchingType.NETWORK };
-        return types;
+        Set<String> traceEvents = TmfEventTypeCollectionHelper.getEventName(ktrace.getContainedEventTypes());
+        traceEvents.retainAll(events);
+        return !traceEvents.isEmpty();
     }
 
 }
 </pre>
 
-Somewhere in code that will be executed at the start of the plugin (like in the Activator), the following code will have to be run:
+The following code will have to be run before the trace synchronization takes place, for example in the Activator of the plugin:
 
 <pre>
 TmfEventMatching.registerMatchObject(new MyAppUstEventMatching());
 </pre>
 
-Now, only adding the traces in an experiment and clicking the '''Synchronize traces''' menu element would synchronize the traces using the new definition for event matching.
+Now, only adding the traces in an experiment and clicking the '''Synchronize traces''' menu item will synchronize the traces using the new definition for event matching.
 
 == Trace synchronization ==
 
@@ -3211,9 +3240,12 @@ Timestamp transforms are the formulae used to transform the timestamps from a tr
 
 The following classes implement this interface:
 
-* '''TmfTimestampTransform''': default transform. It cannot be instantiated, it has a single static object TmfTimestampTransform.IDENTITY, which returns the original timestamp.
+* '''TmfTimestampTransform''': default transform. It cannot be instantiated, it has a single static object ''TmfTimestampTransform.IDENTITY'', which returns the original timestamp.
+* '''TmfConstantTransform''': simply applies an offset to the timestamp, so the formula would be: ''f(t) = t + c'' where ''c'' is the offset to apply.
 * '''TmfTimestampTransformLinear''': transforms the timestamp using a linear formula: ''f(t) = at + b'', where ''a'' and ''b'' are computed by the synchronization algorithm.
 
+These classes are not accessible directly, to create any timestamp transform, one needs to use one of the methods from the '''TimestampTransformFactory''' utility class.
+
 One could extend the interface for other timestamp transforms, for instance to have a transform where the formula would change over the course of the trace.
 
 == Todo ==
@@ -3221,8 +3253,7 @@ One could extend the interface for other timestamp transforms, for instance to h
 Here's a list of features not yet implemented that would enhance trace synchronization and event matching:
 
 * Ability to select a synchronization algorithm
-* Implement a better way to select the reference trace instead of arbitrarily taking the first in alphabetical order (for instance, the minimum spanning tree algorithm by Masoume Jabbarifar (article on the subject not published yet))
-* Ability to join traces from the same host so that even if one of the traces is not synchronized with the reference trace, it will take the same timestamp transform as the one on the same machine.
+* Implement the minimum spanning tree algorithm by Masoume Jabbarifar (article on the subject not published yet) to automatically select the best reference trace
 * Instead of having the timestamp transforms per trace, have the timestamp transform as part of an experiment context, so that the trace's specific analysis, like the state system, are in the original trace, but are transformed only when needed for an experiment analysis.
 * Add more views to display the synchronization information (only textual statistics are available for now)
 
This page took 0.029114 seconds and 5 git commands to generate.