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));
}
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));
}
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();
}
}
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));
}
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();
}
Aggregations