Search in sources :

Example 1 with StatComparisonData

use of org.eclipse.linuxtools.internal.perf.StatComparisonData in project linuxtools by eclipse.

the class StatComparisonView method setInput.

@Override
public void setInput(Object input) {
    if (input instanceof ICompareInput) {
        fInput = (ICompareInput) input;
        if (fInput.getAncestor() != null || (fInput.getKind() & Differencer.DIRECTION_MASK) != 0) {
            setStyledText(Messages.CompUnsupported);
        } else {
            // get corresponding files
            IPath oldDatum;
            IPath newDatum;
            if (fInput.getLeft() instanceof ResourceNode) {
                ResourceNode left = (ResourceNode) fInput.getLeft();
                oldDatum = left.getResource().getLocation();
            } else {
                IEncodedStreamContentAccessor lStream = (IEncodedStreamContentAccessor) fInput.getLeft();
                oldDatum = generateTempFile(lStream);
            }
            if (fInput.getRight() instanceof ResourceNode) {
                ResourceNode right = (ResourceNode) fInput.getRight();
                newDatum = right.getResource().getLocation();
            } else {
                IEncodedStreamContentAccessor rStream = (IEncodedStreamContentAccessor) fInput.getRight();
                newDatum = generateTempFile(rStream);
            }
            String title = MessageFormat.format(Messages.ContentDescription_0, oldDatum.toFile().getName(), newDatum.toFile().getName());
            // create comparison data and run comparison.
            StatComparisonData diffData;
            if (reverse) {
                diffData = new StatComparisonData(title, newDatum, oldDatum);
            } else {
                diffData = new StatComparisonData(title, oldDatum, newDatum);
            }
            diffData.runComparison();
            updateData(diffData);
        }
    }
    fComposite.layout();
}
Also used : IPath(org.eclipse.core.runtime.IPath) StatComparisonData(org.eclipse.linuxtools.internal.perf.StatComparisonData) ICompareInput(org.eclipse.compare.structuremergeviewer.ICompareInput) IEncodedStreamContentAccessor(org.eclipse.compare.IEncodedStreamContentAccessor) ResourceNode(org.eclipse.compare.ResourceNode)

Example 2 with StatComparisonData

use of org.eclipse.linuxtools.internal.perf.StatComparisonData in project linuxtools by eclipse.

the class StatsComparisonTest method testStatComparisonResult.

@Test
public void testStatComparisonResult() throws IOException {
    IPath oldStatData = Path.fromOSString(STAT_RES + "perf_old.stat");
    IPath newStatData = Path.fromOSString(STAT_RES + "perf_new.stat");
    IPath diffStatData = Path.fromOSString(STAT_RES + "perf_diff.stat");
    try (BufferedReader diffDataReader = new BufferedReader(new FileReader(diffStatData.toFile()))) {
        StatComparisonData diffData = new StatComparisonData("title", oldStatData, newStatData);
        diffData.runComparison();
        String actualResult = diffData.getPerfData();
        String[] actualResultLines = actualResult.split("\n");
        String curLine;
        for (int i = 0; i < actualResultLines.length; i++) {
            curLine = diffDataReader.readLine();
            /**
             * Elapsed seconds are usually very close to zero, and thus
             * prone to some small formatting differences across systems.
             * Total time entry items are checked more thoroughly to avoid
             * test failures.
             */
            if (curLine.contains(PMStatEntry.TIME)) {
                String expectedEntry = curLine.trim();
                String actualEntry = actualResultLines[i].trim();
                String expectedSamples = expectedEntry.substring(0, expectedEntry.indexOf(" "));
                String expectedRest = expectedEntry.substring(expectedEntry.indexOf(" ") + 1);
                String actualSamples = actualEntry.substring(0, actualEntry.indexOf(" "));
                String actualRest = actualEntry.substring(actualEntry.indexOf(" ") + 1);
                assertEquals(StatComparisonData.toFloat(actualSamples), StatComparisonData.toFloat(expectedSamples), 0);
                assertEquals(actualRest, expectedRest);
            } else {
                assertEquals(actualResultLines[i], curLine);
            }
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) StatComparisonData(org.eclipse.linuxtools.internal.perf.StatComparisonData) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Test(org.junit.Test)

Example 3 with StatComparisonData

use of org.eclipse.linuxtools.internal.perf.StatComparisonData in project linuxtools by eclipse.

the class StatsComparisonTest method testStatDataComparison.

@Test
public void testStatDataComparison() {
    IPath oldStatData = Path.fromOSString(STAT_RES + "perf_old.stat");
    IPath newStatData = Path.fromOSString(STAT_RES + "perf_new.stat");
    StatComparisonData diffData = new StatComparisonData("title", oldStatData, newStatData);
    // expected comparison list
    ArrayList<PMStatEntry> expectedDiff = new ArrayList<>();
    expectedDiff.add(new PMStatEntry((float) -4.0, "cpu-clock", (float) 0.0, null, (float) 0.54, (float) 0.0));
    expectedDiff.add(new PMStatEntry((float) -2000.0, "page-faults", (float) -0.31, "M/sec", (float) 0.02, (float) 0.0));
    expectedDiff.add(new PMStatEntry((float) 0.0, "context-switches", (float) -0.13, "K/sec", (float) 36.34, (float) 0.0));
    expectedDiff.add(new PMStatEntry((float) -1000.0, "minor-faults", (float) -0.3, "M/sec", (float) 0.02, (float) 0.0));
    expectedDiff.add(new PMStatEntry((float) 0.0, "major-faults", (float) 0.0, "K/sec", (float) 0.0, (float) 0.0));
    expectedDiff.add(new PMStatEntry((float) -0.008, "seconds time elapsed", (float) 0.0, null, (float) 0.92, (float) 0.0));
    ArrayList<PMStatEntry> actualDiff = diffData.getComparisonStats();
    assertFalse(actualDiff.isEmpty());
    for (PMStatEntry expectedEntry : expectedDiff) {
        assertTrue(actualDiff.contains(expectedEntry));
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) PMStatEntry(org.eclipse.linuxtools.internal.perf.model.PMStatEntry) StatComparisonData(org.eclipse.linuxtools.internal.perf.StatComparisonData) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with StatComparisonData

use of org.eclipse.linuxtools.internal.perf.StatComparisonData in project linuxtools by eclipse.

the class StatsComparisonTest method testStatDataComparisonFieldGetters.

@Test
public void testStatDataComparisonFieldGetters() {
    IPath oldStatData = Path.fromOSString(STAT_RES + "perf_old.stat");
    IPath newStatData = Path.fromOSString(STAT_RES + "perf_new.stat");
    String dataTitle = "title";
    StatComparisonData diffData = new StatComparisonData(dataTitle, oldStatData, newStatData);
    assertEquals(dataTitle, diffData.getTitle());
    assertEquals("", diffData.getPerfData());
    assertNotNull(diffData.getDataID());
    assertEquals(oldStatData.toOSString(), diffData.getOldDataPath());
    assertEquals(newStatData.toOSString(), diffData.getNewDataPath());
    assertEquals(oldStatData.toOSString() + diffData.getDataID(), diffData.getOldDataID());
    assertEquals(newStatData.toOSString() + diffData.getDataID(), diffData.getNewDataID());
}
Also used : IPath(org.eclipse.core.runtime.IPath) StatComparisonData(org.eclipse.linuxtools.internal.perf.StatComparisonData) Test(org.junit.Test)

Aggregations

IPath (org.eclipse.core.runtime.IPath)4 StatComparisonData (org.eclipse.linuxtools.internal.perf.StatComparisonData)4 Test (org.junit.Test)3 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 ArrayList (java.util.ArrayList)1 IEncodedStreamContentAccessor (org.eclipse.compare.IEncodedStreamContentAccessor)1 ResourceNode (org.eclipse.compare.ResourceNode)1 ICompareInput (org.eclipse.compare.structuremergeviewer.ICompareInput)1 PMStatEntry (org.eclipse.linuxtools.internal.perf.model.PMStatEntry)1