use of org.eclipse.linuxtools.systemtap.graphing.core.datasets.IFilteredDataSet in project linuxtools by eclipse.
the class SystemTapScriptLaunchConfigurationDelegate method launch.
@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
// Wait for other stap launches' consoles to be initiated before starting a new launch.
ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
for (ILaunch olaunch : manager.getLaunches()) {
if (olaunch.equals(launch)) {
continue;
}
if (olaunch instanceof SystemTapScriptLaunch && ((SystemTapScriptLaunch) olaunch).getConsole() == null) {
throw new CoreException(new Status(IStatus.ERROR, IDEPlugin.PLUGIN_ID, Messages.SystemTapScriptLaunchError_waitForConsoles));
}
}
if (!SystemTapScriptGraphOptionsTab.isValidLaunch(configuration)) {
throw new CoreException(new Status(IStatus.ERROR, IDEPlugin.PLUGIN_ID, Messages.SystemTapScriptLaunchError_graph));
}
RunScriptHandler action;
boolean runWithChart = configuration.getAttribute(SystemTapScriptGraphOptionsTab.RUN_WITH_CHART, false);
// If runWithChart is true there must be at least one graph, but this isn't guaranteed
// to be true for outdated Launch Configurations. So for safety, make sure there are graphs.
int numGraphs = configuration.getAttribute(SystemTapScriptGraphOptionsTab.NUMBER_OF_REGEXS, 0);
if (runWithChart && numGraphs > 0) {
List<IDataSetParser> parsers = SystemTapScriptGraphOptionsTab.createDatasetParsers(configuration);
List<IFilteredDataSet> dataSets = SystemTapScriptGraphOptionsTab.createDataset(configuration);
List<String> names = SystemTapScriptGraphOptionsTab.createDatasetNames(configuration);
List<LinkedList<GraphData>> graphs = SystemTapScriptGraphOptionsTab.createGraphsFromConfiguration(configuration);
action = new RunScriptChartHandler(parsers, dataSets, names, graphs);
} else {
action = new RunScriptHandler();
}
// Path
// $NON-NLS-1$
IPath scriptPath = new Path(configuration.getAttribute(SystemTapScriptLaunchConfigurationTab.SCRIPT_PATH_ATTR, ""));
if (!scriptPath.toFile().exists()) {
throw new CoreException(new Status(IStatus.ERROR, IDEPlugin.PLUGIN_ID, MessageFormat.format(Messages.SystemTapScriptLaunchError_fileNotFound, scriptPath.toString())));
}
String extension = scriptPath.getFileExtension();
if (extension == null || !extension.equals("stp")) {
// $NON-NLS-1$
throw new CoreException(new Status(IStatus.ERROR, IDEPlugin.PLUGIN_ID, MessageFormat.format(Messages.SystemTapScriptLaunchError_fileNotStp, scriptPath.toString())));
}
action.setPath(scriptPath);
// Run locally and/or as current user.
action.setRemoteScriptOptions(configuration.getAttribute(SystemTapScriptLaunchConfigurationTab.CURRENT_USER_ATTR, true) ? null : new RemoteScriptOptions(// $NON-NLS-1$
configuration.getAttribute(SystemTapScriptLaunchConfigurationTab.USER_NAME_ATTR, ""), // $NON-NLS-1$
configuration.getAttribute(SystemTapScriptLaunchConfigurationTab.USER_PASS_ATTR, ""), configuration.getAttribute(SystemTapScriptLaunchConfigurationTab.LOCAL_HOST_ATTR, true) ? LOCALHOST : configuration.getAttribute(SystemTapScriptLaunchConfigurationTab.HOST_NAME_ATTR, LOCALHOST), configuration.getAttribute(SystemTapScriptLaunchConfigurationTab.USE_DEFAULT_PORT_ATTR, true) ? DEFAULT_PORT : configuration.getAttribute(SystemTapScriptLaunchConfigurationTab.PORT_ATTR, DEFAULT_PORT)));
// $NON-NLS-1$
String value = configuration.getAttribute(IDEPreferenceConstants.STAP_CMD_OPTION[IDEPreferenceConstants.KEY], "");
if (!value.isEmpty()) {
// $NON-NLS-1$
action.addComandLineOptions(IDEPreferenceConstants.STAP_CMD_OPTION[IDEPreferenceConstants.FLAG] + " " + value);
}
// Add command line options
for (int i = 0; i < IDEPreferenceConstants.STAP_BOOLEAN_OPTIONS.length; i++) {
boolean flag = configuration.getAttribute(IDEPreferenceConstants.STAP_BOOLEAN_OPTIONS[i][IDEPreferenceConstants.KEY], false);
if (flag) {
action.addComandLineOptions(IDEPreferenceConstants.STAP_BOOLEAN_OPTIONS[i][IDEPreferenceConstants.FLAG]);
}
}
for (int i = 0; i < IDEPreferenceConstants.STAP_STRING_OPTIONS.length; i++) {
// $NON-NLS-1$
value = configuration.getAttribute(IDEPreferenceConstants.STAP_STRING_OPTIONS[i][IDEPreferenceConstants.KEY], "");
if (!value.isEmpty()) {
// $NON-NLS-1$
action.addComandLineOptions(IDEPreferenceConstants.STAP_STRING_OPTIONS[i][IDEPreferenceConstants.FLAG] + " " + value);
}
}
// $NON-NLS-1$
value = configuration.getAttribute(SystemTapScriptOptionsTab.MISC_COMMANDLINE_OPTIONS, "");
if (!value.isEmpty()) {
action.addComandLineOptions(value);
}
action.setLaunch((SystemTapScriptLaunch) launch);
try {
action.execute(null);
} catch (ExecutionException e) {
throw new CoreException(new Status(IStatus.ERROR, IDEPlugin.PLUGIN_ID, e.getMessage()));
}
}
use of org.eclipse.linuxtools.systemtap.graphing.core.datasets.IFilteredDataSet in project linuxtools by eclipse.
the class TestCreateSystemtapScript method createAndViewDummyData.
private static void createAndViewDummyData(String[] titles, Object[] data) {
if (data.length % titles.length != 0) {
throw new IllegalArgumentException("data.length must be a multiple of titles.length.");
}
final int numRows = data.length / titles.length;
IFilteredDataSet dataset = new FilteredRowDataSet(titles);
for (int i = 0; i < numRows; i++) {
IDataEntry dataEntry = new RowEntry();
Object[] values = new Object[titles.length];
for (int v = 0; v < titles.length; v++) {
values[v] = data[titles.length * i + v];
}
dataEntry.putRow(0, values);
dataset.setData(dataEntry);
}
final File dataFile;
try {
dataFile = File.createTempFile("testSet", ".set");
dataFile.deleteOnExit();
if (!dataset.writeToFile(dataFile)) {
throw new IOException();
}
} catch (IOException e) {
fail("Could not create dummy data set.");
return;
}
UIThreadRunnable.syncExec(() -> {
new ImportDataSetHandler().execute(dataFile.getPath());
});
String editorName = dataFile.getName().concat(" Graphs");
bot.waitUntil(new EditorIsActive(editorName));
}
use of org.eclipse.linuxtools.systemtap.graphing.core.datasets.IFilteredDataSet in project linuxtools by eclipse.
the class ImportDataSetHandler method execute.
/**
* Import a data set from the specified path.
* @param path The path of the data set to import.
*/
public void execute(String path) {
IFilteredDataSet dataset = null;
File file = new File(path);
try (InputStreamReader fr = new InputStreamReader(new FileInputStream(file), Charset.defaultCharset());
BufferedReader br = new BufferedReader(fr)) {
String id = br.readLine();
// $NON-NLS-1$
String[] titles = br.readLine().split(", ");
if (id == null && titles == null) {
throw new IOException();
} else if (id.equals(RowDataSet.ID)) {
dataset = new FilteredRowDataSet(titles);
} else if (id.equals(TableDataSet.ID)) {
dataset = new FilteredTableDataSet(titles);
} else {
throw new IOException();
}
dataset.readFromFile(file);
String title = path.substring(path.lastIndexOf('/') + 1);
IWorkbenchPage p = PlatformUI.getWorkbench().showPerspective(IDEPerspective.ID, PlatformUI.getWorkbench().getActiveWorkbenchWindow());
GraphSelectorEditor ivp = (GraphSelectorEditor) p.openEditor(new GraphSelectorEditorInput(title), GraphSelectorEditor.ID);
ivp.createScriptSets(path, Arrays.asList(title), Arrays.asList(dataset));
} catch (FileNotFoundException fnfe) {
ExceptionErrorDialog.openError(Messages.ImportDataSetAction_FileNotFound, fnfe);
} catch (IOException ioe) {
ExceptionErrorDialog.openError(Messages.ImportDataSetAction_FileInvalid, ioe);
} catch (WorkbenchException we) {
ExceptionErrorDialog.openError(Messages.RunScriptChartHandler_couldNotSwitchToGraphicPerspective, we);
}
}
Aggregations