Search in sources :

Example 16 with ITmfFilter

use of org.eclipse.tracecompass.tmf.core.filter.ITmfFilter in project tracecompass by tracecompass.

the class ColorSettingsManager method getColorSetting.

/**
 * Gets the color settings that matches the filter for given event.
 *
 * @param event
 *            The event to check
 *
 * @return color settings defined for filter if found else default color
 *         settings
 */
public static ColorSetting getColorSetting(ITmfEvent event) {
    for (int i = 0; i < fColorSettings.length; i++) {
        ColorSetting colorSetting = fColorSettings[i];
        ITmfFilter filter = colorSetting.getFilter();
        if (filter != null && filter.matches(event)) {
            return colorSetting;
        }
    }
    return DEFAULT_COLOR_SETTING;
}
Also used : ITmfFilter(org.eclipse.tracecompass.tmf.core.filter.ITmfFilter)

Example 17 with ITmfFilter

use of org.eclipse.tracecompass.tmf.core.filter.ITmfFilter in project tracecompass by tracecompass.

the class TmfFilterHelperTest method testInputRegexNot.

/**
 * Test a negative regex on an && regex
 */
@Test
public void testInputRegexNot() {
    String regex = "!(" + FIELD1_NAME + " matches .*afield.* && " + FIELD2_NAME + " present)";
    ITmfFilter filter = getFilter(regex);
    ITmfEventAspect<@NonNull Object> aspectF1 = TmfBaseAspects.getContentsAspect().forField(FIELD1_NAME);
    ITmfEventAspect<@NonNull Object> aspectF2 = TmfBaseAspects.getContentsAspect().forField(FIELD2_NAME);
    // verify the main root node
    assertTrue(filter instanceof TmfFilterRootNode);
    TmfFilterRootNode node = (TmfFilterRootNode) filter;
    assertEquals(1, node.getChildrenCount());
    ITmfFilterTreeNode child = node.getChild(0);
    assertTrue(child instanceof TmfFilterAndNode);
    TmfFilterAndNode andNode = (TmfFilterAndNode) child;
    assertEquals(2, andNode.getChildrenCount());
    // Verify first child, a matches node
    child = andNode.getChild(0);
    assertTrue(child instanceof TmfFilterMatchesNode);
    TmfFilterMatchesNode equalsNode = (TmfFilterMatchesNode) child;
    assertEquals(aspectF1, equalsNode.getEventAspect());
    assertEquals(".*afield.*", equalsNode.getRegex());
    // Verify second child the present node
    child = andNode.getChild(1);
    assertTrue(child instanceof TmfFilterMatchesNode);
    equalsNode = (TmfFilterMatchesNode) child;
    assertEquals(aspectF2, equalsNode.getEventAspect());
    assertEquals(".*", equalsNode.getRegex());
    // Test expected behavior on events
    assertTrue(filter.matches(fEvent1));
    assertTrue(filter.matches(fEvent2));
    assertFalse(filter.matches(fEvent3));
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) ITmfFilter(org.eclipse.tracecompass.tmf.core.filter.ITmfFilter) TmfFilterAndNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode) TmfFilterMatchesNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode) TmfFilterRootNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode) Test(org.junit.Test)

Example 18 with ITmfFilter

use of org.eclipse.tracecompass.tmf.core.filter.ITmfFilter in project tracecompass by tracecompass.

the class TmfFilterHelperTest method getFilter.

private static ITmfFilter getFilter(String regex) {
    ITmfTrace trace = STUB_TRACE;
    assertNotNull(trace);
    ITmfFilter filter = TmfFilterHelper.buildFilterFromRegex(Collections.singleton(regex), trace);
    assertNotNull(filter);
    return filter;
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) ITmfFilter(org.eclipse.tracecompass.tmf.core.filter.ITmfFilter)

Example 19 with ITmfFilter

use of org.eclipse.tracecompass.tmf.core.filter.ITmfFilter in project tracecompass by tracecompass.

the class TmfFilterHelperTest method testInputRegexAspect.

/**
 * Test a regex whose parameter corresponds to an aspect name
 */
@Test
public void testInputRegexAspect() {
    ITmfEventAspect<@NonNull String> eventTypeAspect = TmfBaseAspects.getEventTypeAspect();
    String regex = "\"" + eventTypeAspect.getName() + "\" == " + EVENT_NAME1;
    ITmfFilter filter = getFilter(regex);
    // verify the main root node
    assertTrue(filter instanceof TmfFilterRootNode);
    TmfFilterRootNode node = (TmfFilterRootNode) filter;
    assertEquals(1, node.getChildrenCount());
    ITmfFilterTreeNode child = node.getChild(0);
    assertTrue(child instanceof TmfFilterEqualsNode);
    // verify the equals node
    TmfFilterEqualsNode equalsNode = (TmfFilterEqualsNode) child;
    assertEquals(eventTypeAspect, equalsNode.getEventAspect());
    assertEquals(EVENT_NAME1, equalsNode.getValue());
    // Test expected behavior on events
    assertTrue(filter.matches(fEvent1));
    assertFalse(filter.matches(fEvent2));
    assertFalse(filter.matches(fEvent3));
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) ITmfFilter(org.eclipse.tracecompass.tmf.core.filter.ITmfFilter) TmfFilterEqualsNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode) TmfFilterRootNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode) Test(org.junit.Test)

Example 20 with ITmfFilter

use of org.eclipse.tracecompass.tmf.core.filter.ITmfFilter in project tracecompass by tracecompass.

the class TmfFilterHelperTest method testInputRegexAnd.

/**
 * Test a regex with &&
 */
@Test
public void testInputRegexAnd() {
    String regex = FIELD1_NAME + " matches .*afield.* && " + FIELD2_NAME + " present";
    ITmfFilter filter = getFilter(regex);
    ITmfEventAspect<@NonNull Object> aspectF1 = TmfBaseAspects.getContentsAspect().forField(FIELD1_NAME);
    ITmfEventAspect<@NonNull Object> aspectF2 = TmfBaseAspects.getContentsAspect().forField(FIELD2_NAME);
    // verify the main root node
    assertTrue(filter instanceof TmfFilterRootNode);
    TmfFilterRootNode node = (TmfFilterRootNode) filter;
    assertEquals(1, node.getChildrenCount());
    ITmfFilterTreeNode child = node.getChild(0);
    assertTrue(child instanceof TmfFilterAndNode);
    TmfFilterAndNode andNode = (TmfFilterAndNode) child;
    assertEquals(2, andNode.getChildrenCount());
    // Verify first child, a matches node
    child = andNode.getChild(0);
    assertTrue(child instanceof TmfFilterMatchesNode);
    TmfFilterMatchesNode equalsNode = (TmfFilterMatchesNode) child;
    assertEquals(aspectF1, equalsNode.getEventAspect());
    assertEquals(".*afield.*", equalsNode.getRegex());
    // Verify second child the present node
    child = andNode.getChild(1);
    assertTrue(child instanceof TmfFilterMatchesNode);
    equalsNode = (TmfFilterMatchesNode) child;
    assertEquals(aspectF2, equalsNode.getEventAspect());
    assertEquals(".*", equalsNode.getRegex());
    // Test expected behavior on events
    assertFalse(filter.matches(fEvent1));
    assertFalse(filter.matches(fEvent2));
    assertTrue(filter.matches(fEvent3));
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) ITmfFilter(org.eclipse.tracecompass.tmf.core.filter.ITmfFilter) TmfFilterAndNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode) TmfFilterMatchesNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode) TmfFilterRootNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode) Test(org.junit.Test)

Aggregations

ITmfFilter (org.eclipse.tracecompass.tmf.core.filter.ITmfFilter)23 ITmfFilterTreeNode (org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode)11 TmfFilterRootNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode)10 Test (org.junit.Test)10 TmfFilterMatchesNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode)6 ArrayList (java.util.ArrayList)4 ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)4 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)4 TmfEventTableColumn (org.eclipse.tracecompass.tmf.ui.viewers.events.columns.TmfEventTableColumn)4 TableColumn (org.eclipse.swt.widgets.TableColumn)3 TmfCollapseFilter (org.eclipse.tracecompass.internal.tmf.core.filter.TmfCollapseFilter)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 IMarker (org.eclipse.core.resources.IMarker)2 CoreException (org.eclipse.core.runtime.CoreException)2 Nullable (org.eclipse.jdt.annotation.Nullable)2 Point (org.eclipse.swt.graphics.Point)2 TmfFilterAndNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode)2 ITmfEventRequest (org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest)2 TmfEventRequest (org.eclipse.tracecompass.tmf.core.request.TmfEventRequest)2