Search in sources :

Example 1 with PMStatEntry

use of org.eclipse.linuxtools.internal.perf.model.PMStatEntry in project linuxtools by eclipse.

the class StatsComparisonTest method testPMStatEntryComparison.

@Test
public void testPMStatEntryComparison() {
    String expectedEvent = "event";
    String expectedUnits = "unit";
    float expectedSamples = statEntry.getSamples() - statEntry2.getSamples();
    float expectedMetrics = statEntry.getMetrics() - statEntry2.getMetrics();
    float expectedDeviation = statEntry.getDeviation() + statEntry2.getDeviation();
    float expectedScaling = statEntry.getScaling() + statEntry2.getScaling();
    PMStatEntry expectedDiff = new PMStatEntry(expectedSamples, expectedEvent, expectedMetrics, expectedUnits, expectedDeviation, expectedScaling);
    PMStatEntry actualDiff = statEntry.compare(statEntry2);
    // test stat entry comparison
    assertEquals(expectedDiff, actualDiff);
}
Also used : PMStatEntry(org.eclipse.linuxtools.internal.perf.model.PMStatEntry) Test(org.junit.Test)

Example 2 with PMStatEntry

use of org.eclipse.linuxtools.internal.perf.model.PMStatEntry in project linuxtools by eclipse.

the class StatComparisonData method runComparison.

/**
 * Compare stat data files and store the result in the result field.
 */
public void runComparison() {
    ArrayList<PMStatEntry> statsDiff = getComparisonStats();
    if (!statsDiff.isEmpty()) {
        String[][] statsDiffStr = new String[statsDiff.size()][];
        int currentRow = 0;
        // gather comparison results in a string array
        for (PMStatEntry statEntry : statsDiff) {
            statsDiffStr[currentRow] = statEntry.toStringArray();
            currentRow++;
        }
        // apply format to each entry and set the result
        String format = getFormat(statsDiffStr);
        String curLine;
        for (String[] statEntry : statsDiffStr) {
            curLine = String.format(format, (Object[]) statEntry);
            curLine = // $NON-NLS-1$
            curLine.contains(PMStatEntry.TIME) ? // $NON-NLS-1$
            "\n" + curLine : curLine;
            result += curLine;
        }
    } else {
    }
}
Also used : PMStatEntry(org.eclipse.linuxtools.internal.perf.model.PMStatEntry)

Example 3 with PMStatEntry

use of org.eclipse.linuxtools.internal.perf.model.PMStatEntry in project linuxtools by eclipse.

the class StatsComparisonTest method setUp.

@Before
public void setUp() {
    String event = "event";
    String units = "unit";
    float samples = 1;
    float metrics = 2;
    float deviation = 3;
    float scaling = 4;
    statEntry = new PMStatEntry(samples, event, metrics, units, deviation, scaling);
    statEntry2 = new PMStatEntry(samples, event, metrics, units, deviation, scaling);
    statEntry3 = new PMStatEntry(samples++, event, metrics++, units, deviation++, scaling);
    statEntry4 = new PMStatEntry(samples--, "event2", metrics--, units, deviation--, scaling);
}
Also used : PMStatEntry(org.eclipse.linuxtools.internal.perf.model.PMStatEntry) Before(org.junit.Before)

Example 4 with PMStatEntry

use of org.eclipse.linuxtools.internal.perf.model.PMStatEntry 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 5 with PMStatEntry

use of org.eclipse.linuxtools.internal.perf.model.PMStatEntry in project linuxtools by eclipse.

the class StatComparisonData method collectStats.

/**
 * Collect statistics entries from the specified stat data file.
 *
 * @param file file to collect from
 * @return List containing statistics entries from the given file.
 */
private static ArrayList<PMStatEntry> collectStats(IPath file) {
    ArrayList<PMStatEntry> result = new ArrayList<>();
    BufferedReader statReader = null;
    URI fileURI = null;
    try {
        fileURI = new URI(file.toPortableString());
        IRemoteFileProxy proxy = null;
        proxy = RemoteProxyManager.getInstance().getFileProxy(fileURI);
        IFileStore newDataFileStore = proxy.getResource(fileURI.getPath());
        statReader = new BufferedReader(new InputStreamReader(newDataFileStore.openInputStream(EFS.NONE, null)));
        // pattern for a valid perf stat entry
        Pattern entryPattern = Pattern.compile(PMStatEntry.getString(Type.ENTRY_PATTERN));
        // pattern for last stat entry (seconds elapsed):
        Pattern totalTimePattern = Pattern.compile(PMStatEntry.getString(Type.TIME_PATTERN));
        String line;
        while ((line = statReader.readLine()) != null) {
            line = line.trim();
            Matcher match = entryPattern.matcher(line);
            String samples, event, usage, units, delta, scale;
            PMStatEntry statEntry;
            if (match.find()) {
                // extract information from groups
                samples = match.group(1);
                event = match.group(2);
                usage = match.group(7);
                units = match.group(8);
                delta = match.group(10);
                scale = match.group(14);
                // create stat entry
                statEntry = new PMStatEntry(toFloat(samples), event, toFloat(usage), units, toFloat(delta), toFloat(scale));
                // add stat entry to results list
                result.add(statEntry);
            } else if (line.contains(PMStatEntry.TIME)) {
                // match seconds elapsed pattern
                match = totalTimePattern.matcher(line);
                if (match.find()) {
                    samples = match.group(1);
                    event = match.group(2);
                    delta = match.group(4);
                    // create stat entry
                    statEntry = new PMStatEntry(toFloat(samples), event, 0, null, toFloat(delta), 0);
                    result.add(statEntry);
                }
            }
        }
        return result;
    } catch (IOException | CoreException | URISyntaxException e) {
        PerfPlugin.getDefault().openError(e, Messages.MsgError);
    } finally {
        try {
            if (statReader != null) {
                statReader.close();
            }
        } catch (IOException e) {
            PerfPlugin.getDefault().openError(e, Messages.PerfResourceLeak_title);
        }
    }
    return result;
}
Also used : Pattern(java.util.regex.Pattern) InputStreamReader(java.io.InputStreamReader) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) PMStatEntry(org.eclipse.linuxtools.internal.perf.model.PMStatEntry) CoreException(org.eclipse.core.runtime.CoreException) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) BufferedReader(java.io.BufferedReader) IFileStore(org.eclipse.core.filesystem.IFileStore)

Aggregations

PMStatEntry (org.eclipse.linuxtools.internal.perf.model.PMStatEntry)6 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 IFileStore (org.eclipse.core.filesystem.IFileStore)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 StatComparisonData (org.eclipse.linuxtools.internal.perf.StatComparisonData)1 IRemoteFileProxy (org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy)1 Before (org.junit.Before)1