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