use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class AbstractOprofileLaunchConfigurationDelegate method launch.
@Override
public void launch(ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
this.config = config;
Oprofile.OprofileProject.setProject(getProject());
// default options created in the constructor
LaunchOptions options = new LaunchOptions();
options.loadConfiguration(config);
IPath exePath = getExePath(config);
options.setBinaryImage(exePath.toOSString());
Oprofile.OprofileProject.setProfilingBinary(options.getOprofileComboText());
/*
* Parameters needed for the application under profiling
*/
String[] appArgs = getProgramArgumentsArray(config);
String[] appEnv = getEnvironment(config);
// if daemonEvents null or zero size, the default event will be used
OprofileDaemonEvent[] daemonEvents = null;
ArrayList<OprofileDaemonEvent> events = new ArrayList<>();
if (!config.getAttribute(OprofileLaunchPlugin.ATTR_USE_DEFAULT_EVENT, false)) {
// get the events to profile from the counters
OprofileCounter[] counters = oprofileCounters(config);
for (int i = 0; i < counters.length; ++i) {
if (counters[i].getEnabled()) {
OprofileDaemonEvent[] counterEvents = counters[i].getDaemonEvents();
events.addAll(Arrays.asList(counterEvents));
}
}
daemonEvents = new OprofileDaemonEvent[events.size()];
events.toArray(daemonEvents);
}
if (!preExec(options, daemonEvents, launch)) {
return;
}
Process process = null;
// outputing the profiling data to the project dir/OPROFILE_DATA
if (OprofileProject.getProfilingBinary().equals(OprofileProject.OPERF_BINARY)) {
String eventsString = null;
// Event spec: "EVENT:count:mask:profileKernel:profileUser"
StringBuilder spec = new StringBuilder();
spec.append(EVENTS);
boolean isCommaAllowed = false;
for (int i = 0; i < events.size(); i++) {
OprofileDaemonEvent event = events.get(i);
if (isCommaAllowed) {
spec.append(',');
}
spec.append(event.getEvent().getText());
spec.append(OPD_SETUP_EVENT_SEPARATOR);
spec.append(event.getResetCount());
spec.append(OPD_SETUP_EVENT_SEPARATOR);
spec.append(event.getEvent().getUnitMask().getMaskValue());
spec.append(OPD_SETUP_EVENT_SEPARATOR);
spec.append((event.getProfileKernel() ? OPD_SETUP_EVENT_TRUE : OPD_SETUP_EVENT_FALSE));
spec.append(OPD_SETUP_EVENT_SEPARATOR);
spec.append((event.getProfileUser() ? OPD_SETUP_EVENT_TRUE : OPD_SETUP_EVENT_FALSE));
isCommaAllowed = true;
}
eventsString = spec.toString();
ArrayList<String> argArray = new ArrayList<>(Arrays.asList(appArgs));
// Use remote file proxy to determine data folder since the project may be either local or remote
IRemoteFileProxy proxy = RemoteProxyManager.getInstance().getFileProxy(OprofileProject.getProject());
IFileStore dataFolder = proxy.getResource(oprofileWorkingDirURI(config).getPath() + IPath.SEPARATOR + OPROFILE_DATA);
if (!dataFolder.fetchInfo().exists()) {
dataFolder.mkdir(EFS.SHALLOW, null);
}
argArray.add(0, exePath.toOSString());
if (events.size() > 0) {
argArray.add(0, eventsString);
}
argArray.add(0, SESSION_DIR + oprofileWorkingDirURI(config).getPath() + IPath.SEPARATOR + OPROFILE_DATA);
argArray.add(0, OprofileProject.OPERF_BINARY);
boolean appended = false;
for (int i = 0; i < options.getExecutionsNumber(); i++) {
/*
* If profiling multiple times,
* append oprofile results from 2nd execution on.
*/
if (!appended && i != 0) {
argArray.add(1, APPEND);
appended = true;
}
String[] arguments = new String[argArray.size()];
arguments = argArray.toArray(arguments);
try {
process = RuntimeProcessFactory.getFactory().exec(arguments, appEnv, OprofileProject.getProject());
} catch (IOException e1) {
if (process != null)
process.destroy();
// $NON-NLS-1$
Status status = new Status(IStatus.ERROR, OprofileLaunchPlugin.PLUGIN_ID, OprofileLaunchMessages.getString("oprofilelaunch.error.interrupted_error.status_message"));
throw new CoreException(status);
}
DebugPlugin.newProcess(launch, process, renderProcessLabel(exePath.toOSString()));
try {
process.waitFor();
} catch (InterruptedException e) {
if (process != null)
process.destroy();
// $NON-NLS-1$
Status status = new Status(IStatus.ERROR, OprofileLaunchPlugin.PLUGIN_ID, OprofileLaunchMessages.getString("oprofilelaunch.error.interrupted_error.status_message"));
throw new CoreException(status);
}
}
}
// outputing the profiling data to the project dir/OPROFILE_DATA
if (OprofileProject.getProfilingBinary().equals(OprofileProject.OCOUNT_BINARY)) {
String eventsString = null;
// Event spec: "EVENT:count:mask:profileKernel:profileUser"
StringBuilder spec = new StringBuilder();
spec.append(EVENTS);
boolean isCommaAllowed = false;
for (int i = 0; i < events.size(); i++) {
OprofileDaemonEvent event = events.get(i);
if (isCommaAllowed) {
spec.append(',');
}
spec.append(event.getEvent().getText());
spec.append(OPD_SETUP_EVENT_SEPARATOR);
spec.append(event.getResetCount());
spec.append(OPD_SETUP_EVENT_SEPARATOR);
spec.append(event.getEvent().getUnitMask().getMaskValue());
spec.append(OPD_SETUP_EVENT_SEPARATOR);
spec.append((event.getProfileKernel() ? OPD_SETUP_EVENT_TRUE : OPD_SETUP_EVENT_FALSE));
spec.append(OPD_SETUP_EVENT_SEPARATOR);
spec.append((event.getProfileUser() ? OPD_SETUP_EVENT_TRUE : OPD_SETUP_EVENT_FALSE));
isCommaAllowed = true;
}
eventsString = spec.toString();
ArrayList<String> argArray = new ArrayList<>(Arrays.asList(appArgs));
argArray.add(0, exePath.toOSString());
if (events.size() > 0) {
argArray.add(0, eventsString);
}
argArray.add(0, OUTPUT_FILE + oprofileWorkingDirURI(config).getPath() + IPath.SEPARATOR + OCOUNT_DATA);
argArray.add(0, OprofileProject.OCOUNT_BINARY);
String[] arguments = new String[argArray.size()];
arguments = argArray.toArray(arguments);
try {
process = RuntimeProcessFactory.getFactory().exec(arguments, OprofileProject.getProject());
} catch (IOException e1) {
process.destroy();
// $NON-NLS-1$
Status status = new Status(IStatus.ERROR, OprofileLaunchPlugin.PLUGIN_ID, OprofileLaunchMessages.getString("oprofilelaunch.error.interrupted_error.status_message"));
throw new CoreException(status);
}
DebugPlugin.newProcess(launch, process, renderProcessLabel(exePath.toOSString()));
try {
process.waitFor();
// Put the OCount data in a separate view
StringBuffer buffer = new StringBuffer();
// Use remote file proxy to operate resources since the project may be either local or remote
IRemoteFileProxy proxy = RemoteProxyManager.getInstance().getFileProxy(OprofileProject.getProject());
IFileStore ocountDataStore = proxy.getResource(oprofileWorkingDirURI(config).getPath() + IPath.SEPARATOR + OCOUNT_DATA);
try (InputStream is = ocountDataStore.openInputStream(EFS.NONE, monitor);
BufferedReader reader = new BufferedReader(new InputStreamReader(is))) {
String s = reader.readLine();
// $NON-NLS-1$
String sep_char = "";
while (s != null) {
buffer.append(s);
buffer.append(sep_char);
// $NON-NLS-1$
sep_char = "\n";
s = reader.readLine();
}
// Open the OCount View and display output from ocount
final String text = buffer.toString();
Display.getDefault().syncExec(() -> refreshOcountView(text));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (InterruptedException e) {
process.destroy();
// $NON-NLS-1$
Status status = new Status(IStatus.ERROR, OprofileLaunchPlugin.PLUGIN_ID, OprofileLaunchMessages.getString("oprofilelaunch.error.interrupted_error.status_message"));
throw new CoreException(status);
}
return;
}
postExec(options, daemonEvents, process);
}
use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class TestCheckEventsPreParse method assertValidity.
public void assertValidity(String path) {
IFileStore fileStore = null;
String infoAbsFilePath = null;
Path infoFilePath = new Path(REL_PATH_TO_INFO_PRE_PARSE_RAW);
URL infoFileURL = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), infoFilePath, null);
try {
infoAbsFilePath = FileLocator.toFileURL(infoFileURL).getFile();
fileStore = EFS.getLocalFileSystem().getStore(new Path(infoAbsFilePath));
} catch (IOException e) {
fail("Failed to convert the resource file's path.");
}
InfoAdapter ia = new InfoAdapter(fileStore);
ia.process();
cea = new CheckEventAdapter(ctr, "CPU_CLK_UNHALTED", umask);
cea.process();
Document actualDocument = cea.getDocument();
Element actualRoot = (Element) actualDocument.getElementsByTagName(CheckEventAdapter.CHECK_EVENTS).item(0);
Path filePath = new Path(path);
URL fileURL = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), filePath, null);
Element expectedRoot = null;
try {
String absFilePath = FileLocator.toFileURL(fileURL).getFile();
File file = new File(absFilePath);
FileInputStream inp = new FileInputStream(file);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
builder = factory.newDocumentBuilder();
Document expectedDocument = builder.parse(inp);
expectedRoot = (Element) expectedDocument.getElementsByTagName(CheckEventAdapter.CHECK_EVENTS).item(0);
} catch (FileNotFoundException e) {
fail("File was not found.");
} catch (IOException e) {
fail("Failed to convert the resource file's path.");
} catch (SAXException e) {
fail("Failed to parse the XML.");
} catch (ParserConfigurationException e) {
fail("Failed to create a document builder.");
}
Element expectedResultTag = (Element) expectedRoot.getElementsByTagName(CheckEventAdapter.RESULT).item(0);
Element actualResultTag = (Element) actualRoot.getElementsByTagName(CheckEventAdapter.RESULT).item(0);
assertEquals(expectedResultTag.getTextContent(), actualResultTag.getTextContent());
}
use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class EventIdCache method getUnitMaskType.
/**
* Get the unit mask type. Schema Version 1.1 and newer of ophelp XML
* will list the unit mask type as an attribute. Older version will not
* so we default to file lookups.
*
* @param name the name of the event
* @return the type of unit mask. This can be either mandatory, exclusive,
* bitmask, or null if none could be found.
*/
public String getUnitMaskType(String name) {
IProject project = Oprofile.OprofileProject.getProject();
EventIdCache eventIdCache;
if (project != null) {
eventIdCache = cacheMap.get(project.getLocationURI().getHost());
} else {
eventIdCache = cacheMap.get(LOCAL);
}
if (eventIdCache.eventRoot == null) {
readXML(eventIdCache);
buildCache(eventIdCache);
}
Element header = (Element) eventIdCache.eventRoot.getElementsByTagName(HEADER).item(0);
double schemaVersion = 0;
if (!eventIdCache.eventRoot.getAttribute(SCHEMA).isEmpty()) {
schemaVersion = Double.parseDouble(eventIdCache.eventRoot.getAttribute(SCHEMA));
} else {
schemaVersion = Double.parseDouble(header.getAttribute(SCHEMA));
}
String unitMaskType = null;
IRemoteFileProxy proxy = null;
try {
proxy = RemoteProxyManager.getInstance().getFileProxy(Oprofile.OprofileProject.getProject());
} catch (CoreException e) {
e.printStackTrace();
}
// Schema Version > 1.0 has the unit mask type within the XML
if (schemaVersion > 1.0) {
Element event = getElementWithName(name);
Element unitMaskTag = (Element) event.getElementsByTagName(InfoAdapter.UNIT_MASKS).item(0);
return unitMaskTag.getAttribute(CATEGORY);
} else {
IFileStore fileStore = proxy.getResource(InfoAdapter.CPUTYPE);
try (InputStream fileInputStream = fileStore.openInputStream(EFS.NONE, new NullProgressMonitor());
BufferedReader bi = new BufferedReader(new InputStreamReader(fileInputStream))) {
String cpuType = bi.readLine();
// $NON-NLS-1$
IFileStore opArchEvents = proxy.getResource(InfoAdapter.OP_SHARE + cpuType + "/" + InfoAdapter.EVENTS);
// $NON-NLS-1$
IFileStore opArchUnitMasks = proxy.getResource(InfoAdapter.OP_SHARE + cpuType + "/" + InfoAdapter.UNIT_MASKS);
try (InputStream inputStreamEvents = opArchEvents.openInputStream(EFS.NONE, new NullProgressMonitor());
BufferedReader eventReader = new BufferedReader(new InputStreamReader(inputStreamEvents))) {
String line;
while ((line = eventReader.readLine()) != null) {
// find the line with the event name
if (line.contains("name:" + name + ' ')) {
// $NON-NLS-1$
// $NON-NLS-1$
int start = line.indexOf("um:") + 3;
int end = line.indexOf(' ', start);
// grab the string that references the unit mask type
String um = line.substring(start, end);
try (InputStream inputStreamMasks = opArchUnitMasks.openInputStream(EFS.NONE, new NullProgressMonitor());
BufferedReader unitMaskReader = new BufferedReader(new InputStreamReader(inputStreamMasks))) {
while ((line = unitMaskReader.readLine()) != null) {
if (line.contains("name:" + um + ' ')) {
// $NON-NLS-1$
// $NON-NLS-1$
start = line.indexOf("type:") + 5;
end = line.indexOf(' ', start);
unitMaskType = line.substring(start, end);
return unitMaskType;
}
}
}
}
}
}
} catch (IOException | CoreException e) {
}
}
return unitMaskType;
}
use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class RemoteConnection method copyFileToRemoteHost.
private void copyFileToRemoteHost(String localPath, String remotePath, IProgressMonitor monitor) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor, 15);
try {
IFileSystem localFS = EFS.getLocalFileSystem();
IFileStore localFile = localFS.getStore(Path.fromOSString(localPath));
IFileStore rmtFile = rmtFileProxy.getResource(remotePath);
localFile.copy(rmtFile, EFS.OVERWRITE, progress);
} finally {
if (monitor != null) {
monitor.done();
}
}
}
use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class RemoteConnection method copyFileFromRemoteHost.
/**
* Copy a data from a path (can be a file or directory) from the remote host
* to the local host.
*
* @param remotePath The path to copy from.
* @param localPath The path to copy to.
* @param monitor The progress monitor.
* @throws CoreException If a problem during copy occurred.
*/
private void copyFileFromRemoteHost(String remotePath, String localPath, IProgressMonitor monitor) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor, 15);
try {
IFileSystem localFS = EFS.getLocalFileSystem();
IFileStore localFile = localFS.getStore(Path.fromOSString(localPath));
IFileStore rmtFile = rmtFileProxy.getResource(remotePath);
rmtFile.copy(localFile, EFS.OVERWRITE, progress);
} finally {
if (monitor != null) {
monitor.done();
}
}
}
Aggregations