Search in sources :

Example 16 with ISegment

use of org.eclipse.tracecompass.segmentstore.core.ISegment in project tracecompass by tracecompass.

the class SegmentTableTest method decrementingTest.

/**
 * Test a decrementing data structure.
 * <p>
 * Create segments that are progressively shorter and start sooner,
 * effectively the inverse sorted {@link #climbTest()} datastructure. Test
 * that the "duration" column sorts well
 */
@Test
public void decrementingTest() {
    ISegmentStore<@NonNull ISegment> fixture = SegmentStoreFactory.createSegmentStore();
    for (int i = 100; i >= 0; i--) {
        fixture.add(createSegment(i, 2 * i));
    }
    assertNotNull(getTable());
    getTable().updateModel(fixture);
    SWTBotTable tableBot = new SWTBotTable(getTable().getTableViewer().getTable());
    fBot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "0", 0, 2));
    tableBot.header("Duration").click();
    fBot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "0", 0, 2));
    tableBot.header("Duration").click();
    fBot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "100", 0, 2));
}
Also used : SWTBotTable(org.eclipse.swtbot.swt.finder.widgets.SWTBotTable) ISegment(org.eclipse.tracecompass.segmentstore.core.ISegment) Test(org.junit.Test)

Example 17 with ISegment

use of org.eclipse.tracecompass.segmentstore.core.ISegment in project tracecompass by tracecompass.

the class SegmentTableTest method gaussianNoiseTest.

/**
 * Test table with segments that have durations spread into a gaussian
 * (normal) distribution
 * <p>
 * Test table with a gaussian distribution of segments. Duration sort is
 * tested.
 */
@Test
public void gaussianNoiseTest() {
    Random rnd = new Random();
    rnd.setSeed(1234);
    ISegmentStore<@NonNull ISegment> fixture = SegmentStoreFactory.createSegmentStore();
    for (int i = 1; i <= 1000000; i++) {
        int start = Math.abs(rnd.nextInt(100000000));
        final int delta = Math.abs(rnd.nextInt(1000));
        int end = start + delta * delta;
        fixture.add(createSegment(start, end));
    }
    assertNotNull(getTable());
    getTable().updateModel(fixture);
    SWTBotTable tableBot = new SWTBotTable(getTable().getTableViewer().getTable());
    fBot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "23,409", 0, 2));
    tableBot.header("Duration").click();
    fBot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "0", 0, 2));
    tableBot.header("Duration").click();
    fBot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "998,001", 0, 2));
}
Also used : Random(java.util.Random) SWTBotTable(org.eclipse.swtbot.swt.finder.widgets.SWTBotTable) ISegment(org.eclipse.tracecompass.segmentstore.core.ISegment) Test(org.junit.Test)

Example 18 with ISegment

use of org.eclipse.tracecompass.segmentstore.core.ISegment in project tracecompass by tracecompass.

the class SegmentTableTest method testWriteToTsv.

/**
 * Test creating a tsv
 *
 * @throws NoSuchMethodException
 *             Error creating the tsv
 * @throws IOException
 *             no such file or the file is locked.
 */
@Test
public void testWriteToTsv() throws NoSuchMethodException, IOException {
    ISegmentStore<@NonNull ISegment> fixture = SegmentStoreFactory.createSegmentStore();
    for (int i = 1; i <= 20; i++) {
        int start = i;
        final int delta = i;
        int end = start + delta * delta;
        fixture.add(createSegment(start, end));
    }
    assertNotNull(getTable());
    getTable().updateModel(fixture);
    SWTBotTable tableBot = new SWTBotTable(getTable().getTableViewer().getTable());
    fBot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "1", 0, 2));
    SWTWorkbenchBot swtWorkbenchBot = new SWTWorkbenchBot();
    SWTBotView viewBot = swtWorkbenchBot.viewById(getTableView().getSite().getId());
    String[] lines = extractTsv(viewBot);
    testTsv(lines);
    List<String> actionResult = Arrays.asList(lines);
    String absolutePath = TmfTraceManager.getTemporaryDirPath() + File.separator + "syscallLatencyTest.testWriteToTsv.tsv";
    TmfFileDialogFactory.setOverrideFiles(absolutePath);
    SWTBotMenu menuBot = viewBot.viewMenu().menu("Export to TSV...");
    try {
        assertTrue(menuBot.isEnabled());
        assertTrue(menuBot.isVisible());
        menuBot.click();
        try (BufferedReader br = new BufferedReader(new FileReader(absolutePath))) {
            List<String> actual = br.lines().collect(Collectors.toList());
            assertEquals("Both reads", actionResult, actual);
        }
    } finally {
        new File(absolutePath).delete();
    }
}
Also used : SWTWorkbenchBot(org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot) SWTBotTable(org.eclipse.swtbot.swt.finder.widgets.SWTBotTable) SWTBotMenu(org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu) SWTBotView(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView) BufferedReader(java.io.BufferedReader) ISegment(org.eclipse.tracecompass.segmentstore.core.ISegment) FileReader(java.io.FileReader) File(java.io.File) Test(org.junit.Test)

Example 19 with ISegment

use of org.eclipse.tracecompass.segmentstore.core.ISegment in project tracecompass by tracecompass.

the class SegmentTableTest method smallTest.

/**
 * Test small table
 * <p>
 * Test table with 2 segments. Duration sort is tested.
 */
@Test
public void smallTest() {
    ISegmentStore<@NonNull ISegment> fixture = SegmentStoreFactory.createSegmentStore();
    for (int i = 1; i >= 0; i--) {
        fixture.add(createSegment(i, 2 * i));
    }
    assertNotNull(getTable());
    getTable().updateModel(fixture);
    SWTBotTable tableBot = new SWTBotTable(getTable().getTableViewer().getTable());
    fBot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "0", 0, 2));
    tableBot.header("Duration").click();
    fBot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "0", 0, 2));
    tableBot.header("Duration").click();
    fBot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "1", 0, 2));
}
Also used : SWTBotTable(org.eclipse.swtbot.swt.finder.widgets.SWTBotTable) ISegment(org.eclipse.tracecompass.segmentstore.core.ISegment) Test(org.junit.Test)

Example 20 with ISegment

use of org.eclipse.tracecompass.segmentstore.core.ISegment in project tracecompass by tracecompass.

the class AbstractSegmentStoreDensityViewer method updateDisplay.

private synchronized void updateDisplay(String name, Iterable<ISegment> data) {
    ISeries<Integer> series = fSeriesType.equals(Type.BAR) ? createSeries() : createAreaSeries(name);
    int barWidth = 4;
    int preWidth = fOverrideNbPoints == 0 ? fChart.getPlotArea().getSize().x / barWidth : fOverrideNbPoints;
    if (!fSeriesType.equals(Type.BAR)) {
        preWidth += 2;
    }
    final int width = preWidth;
    double[] xOrigSeries = new double[width];
    double[] yOrigSeries = new double[width];
    // Set a positive value that is greater than 0 and less than 1.0
    Arrays.fill(yOrigSeries, Double.MIN_VALUE);
    Optional<ISegment> maxSegment = StreamSupport.stream(data.spliterator(), false).max(SegmentComparators.INTERVAL_LENGTH_COMPARATOR);
    long maxLength = Long.MIN_VALUE;
    if (maxSegment.isPresent()) {
        maxLength = maxSegment.get().getLength();
    } else {
        for (ISegment segment : data) {
            maxLength = Math.max(maxLength, segment.getLength());
        }
        if (maxLength == Long.MIN_VALUE) {
            maxLength = 1;
        }
    }
    double maxFactor = 1.0 / (maxLength + 1.0);
    long minX = Long.MAX_VALUE;
    for (ISegment segment : data) {
        double xBox = segment.getLength() * maxFactor * width;
        if (yOrigSeries[(int) xBox] < 1) {
            yOrigSeries[(int) xBox] = 1;
        } else {
            yOrigSeries[(int) xBox]++;
        }
        minX = Math.min(minX, segment.getLength());
    }
    double timeWidth = (double) maxLength / (double) width;
    for (int i = 0; i < width; i++) {
        xOrigSeries[i] = i * timeWidth;
        if (!fSeriesType.equals(Type.BAR)) {
            xOrigSeries[i] += timeWidth / 2;
        }
    }
    double maxY = Double.NEGATIVE_INFINITY;
    for (int i = 0; i < width; i++) {
        maxY = Math.max(maxY, yOrigSeries[i]);
    }
    if (minX == maxLength) {
        maxLength++;
        minX--;
    }
    series.setDataModel(new DoubleArraySeriesModel(xOrigSeries, yOrigSeries));
    final IAxis xAxis = fChart.getAxisSet().getXAxis(0);
    /*
         * adjustrange appears to bring origin back since we pad the series with
         * 0s, not interesting.
         */
    AxisRange currentDurationRange = fCurrentDurationRange;
    if (Double.isFinite(currentDurationRange.getLower()) && Double.isFinite(currentDurationRange.getUpper())) {
        xAxis.setRange(new Range(currentDurationRange.getLower(), currentDurationRange.getUpper()));
    } else {
        xAxis.adjustRange();
    }
    xAxis.getTick().setFormat(DENSITY_TIME_FORMATTER);
    ILegend legend = fChart.getLegend();
    legend.setVisible(fSegmentStoreProviders.size() > 1);
    legend.setPosition(SWT.BOTTOM);
    /*
         * Clamp range lower to 0.9 to make it log, 0.1 would be scientifically
         * accurate, but we cannot have partial counts.
         */
    for (ISeries<?> internalSeries : fChart.getSeriesSet().getSeries()) {
        maxY = Math.max(maxY, internalSeries.getDataModel().getMaxY().doubleValue());
    }
    fChart.getAxisSet().getYAxis(0).setRange(new Range(0.9, Math.max(1.0, maxY)));
    fChart.getAxisSet().getYAxis(0).enableLogScale(true);
    new Thread(() -> {
        for (ISegmentStoreDensityViewerDataListener l : fListeners) {
            l.chartUpdated();
        }
    }).start();
}
Also used : ILegend(org.eclipse.swtchart.ILegend) DoubleArraySeriesModel(org.eclipse.swtchart.model.DoubleArraySeriesModel) Range(org.eclipse.swtchart.Range) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) SegmentStoreWithRange(org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.table.SegmentStoreContentProvider.SegmentStoreWithRange) AxisRange(org.eclipse.tracecompass.tmf.ui.viewers.xychart.AxisRange) IAxis(org.eclipse.swtchart.IAxis) AxisRange(org.eclipse.tracecompass.tmf.ui.viewers.xychart.AxisRange) ISegment(org.eclipse.tracecompass.segmentstore.core.ISegment)

Aggregations

ISegment (org.eclipse.tracecompass.segmentstore.core.ISegment)51 Test (org.junit.Test)22 NonNull (org.eclipse.jdt.annotation.NonNull)7 Nullable (org.eclipse.jdt.annotation.Nullable)7 SWTBotTable (org.eclipse.swtbot.swt.finder.widgets.SWTBotTable)7 ISegmentStoreProvider (org.eclipse.tracecompass.analysis.timing.core.segmentstore.ISegmentStoreProvider)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 IAnalysisModule (org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule)6 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)5 Map (java.util.Map)4 Predicate (java.util.function.Predicate)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 IStatistics (org.eclipse.tracecompass.analysis.timing.core.statistics.IStatistics)4 BasicSegment (org.eclipse.tracecompass.segmentstore.core.BasicSegment)4 ISegmentStore (org.eclipse.tracecompass.segmentstore.core.ISegmentStore)4 Objects (java.util.Objects)3 TableViewer (org.eclipse.jface.viewers.TableViewer)3 Performance (org.eclipse.test.performance.Performance)3 PerformanceMeter (org.eclipse.test.performance.PerformanceMeter)3