use of org.eclipse.linuxtools.systemtap.graphing.core.structures.GraphData in project linuxtools by eclipse.
the class SystemTapScriptGraphOptionsTab method createGraphsFromConfiguration.
/**
* Creates graph data corresponding to the graphs that will plot a script's parsed output data.
* @param configuration The desired run configuration.
* @return A data set.
*/
public static List<LinkedList<GraphData>> createGraphsFromConfiguration(ILaunchConfiguration configuration) throws CoreException {
// Restrict number of regexs to at least one, so at least
// one inner list will exist in the return value.
int numberOfRegexs = Math.max(configuration.getAttribute(NUMBER_OF_REGEXS, 1), 1);
ArrayList<LinkedList<GraphData>> graphsList = new ArrayList<>(numberOfRegexs);
for (int r = 0; r < numberOfRegexs; r++) {
int numberOfGraphs = configuration.getAttribute(NUMBER_OF_GRAPHS + r, 0);
LinkedList<GraphData> graphs = new LinkedList<>();
for (int i = 0; i < numberOfGraphs; i++) {
GraphData graphData = new GraphData();
graphData.title = configuration.getAttribute(get2DConfigData(GRAPH_TITLE, r, i), (String) null);
graphData.key = configuration.getAttribute(get2DConfigData(GRAPH_KEY, r, i), (String) null);
graphData.xSeries = configuration.getAttribute(get2DConfigData(GRAPH_X_SERIES, r, i), 0);
graphData.graphID = configuration.getAttribute(get2DConfigData(GRAPH_ID, r, i), (String) null);
int ySeriesLength = configuration.getAttribute(get2DConfigData(GRAPH_Y_SERIES_LENGTH, r, i), 0);
if (ySeriesLength == 0) {
graphData.ySeries = null;
} else {
int[] ySeries = new int[ySeriesLength];
for (int j = 0; j < ySeriesLength; j++) {
// $NON-NLS-1$
ySeries[j] = configuration.getAttribute(get2DConfigData(GRAPH_Y_SERIES, r, i + "_" + j), 0);
}
graphData.ySeries = ySeries;
}
graphs.add(graphData);
}
graphsList.add(graphs);
}
return graphsList;
}
use of org.eclipse.linuxtools.systemtap.graphing.core.structures.GraphData in project linuxtools by eclipse.
the class SystemTapScriptGraphOptionsTab method initializeFrom.
@Override
public void initializeFrom(ILaunchConfiguration configuration) {
try {
textListenersEnabled = false;
// Reset lists & settings to keep things idempotent.
regularExpressionCombo.removeAll();
outputList.clear();
regexErrorMessages.clear();
columnNamesList.clear();
cachedNamesList.clear();
graphsTable.removeAll();
badGraphs.clear();
// There should always be at least one regular expression (a blank one still counts).
// If configuration's number of regexs is zero, it is outdated.
int numberOfRegexs = Math.max(configuration.getAttribute(NUMBER_OF_REGEXS, 1), 1);
// Only allow removing regexs if there are more than one.
removeRegexButton.setEnabled(numberOfRegexs > 1);
for (int r = 0; r < numberOfRegexs; r++) {
// Save all of the configuration's regular expressions & sample outputs in a list.
// $NON-NLS-1$
regularExpressionCombo.add(configuration.getAttribute(REGULAR_EXPRESSION + r, ""));
// $NON-NLS-1$
outputList.add(configuration.getAttribute(SAMPLE_OUTPUT + r, ""));
// Save each regex's list of group names.
int numberOfColumns = configuration.getAttribute(NUMBER_OF_COLUMNS + r, 0);
ArrayList<String> namelist = new ArrayList<>(numberOfColumns);
for (int i = 0; i < numberOfColumns; i++) {
namelist.add(configuration.getAttribute(get2DConfigData(REGEX_BOX, r, i), (String) null));
}
columnNamesList.add(namelist);
// Reclaim missing column data that was required for existing graphs at the time of the previous "apply".
int numberOfExtras = configuration.getAttribute(NUMBER_OF_EXTRAS + r, 0);
Stack<String> oldnames = new Stack<>();
for (int i = 0; i < numberOfExtras; i++) {
oldnames.push(configuration.getAttribute(get2DConfigData(EXTRA_BOX, r, i), (String) null));
}
cachedNamesList.add(oldnames);
regexErrorMessages.add(null);
}
if (getNumberOfRegexs() < MAX_NUMBER_OF_REGEXS) {
regularExpressionCombo.add(Messages.SystemTapScriptGraphOptionsTab_regexAddNew);
}
// When possible, preserve the selection on subsequent initializations, for user convenience.
int defaultSelectedRegex = 0 <= selectedRegex && selectedRegex < numberOfRegexs ? selectedRegex : 0;
regularExpressionCombo.select(defaultSelectedRegex);
// Add graphs
graphsDataList = createGraphsFromConfiguration(configuration);
graphsData = graphsDataList.get(defaultSelectedRegex);
for (GraphData graphData : graphsData) {
TableItem item = new TableItem(graphsTable, SWT.NONE);
setUpGraphTableItem(item, graphData, true);
}
// Handles all remaining updates.
updateRegexSelection(defaultSelectedRegex, true);
checkAllOtherErrors();
boolean chart = configuration.getAttribute(RUN_WITH_CHART, false);
setGraphingEnabled(chart);
this.runWithChartCheckButton.setSelection(chart);
} catch (CoreException e) {
ExceptionErrorDialog.openError(Messages.SystemTapScriptGraphOptionsTab_cantInitializeTab, e);
} finally {
textListenersEnabled = true;
}
}
use of org.eclipse.linuxtools.systemtap.graphing.core.structures.GraphData in project linuxtools by eclipse.
the class SystemTapScriptGraphOptionsTab method updateRegexSelection.
/**
* This handles UI & list updating whenever a different regular expression is selected.
* @param newSelection The index of the regex to be selected.
* @param force If true, the UI will update even if the index of the selected regex did not change.
*/
private void updateRegexSelection(int newSelection, boolean force) {
// Quit if the selection didn't change anything, or if the selection is invalid (-1).
if (newSelection == -1 || (!force && selectedRegex == newSelection)) {
return;
}
selectedRegex = newSelection;
boolean textListenersDisabled = !textListenersEnabled;
if (!textListenersDisabled) {
textListenersEnabled = false;
}
sampleOutputText.setText(outputList.get(selectedRegex));
cachedNames = cachedNamesList.get(selectedRegex);
// Update the number of columns and their titles here, and not in refreshRegexRows,
// using the list of saved active names instead of a cachedNames stack.
List<String> columnNames = columnNamesList.get(selectedRegex);
int desiredNumberOfColumns = columnNames.size();
// Remove all columns to easily update them all immediately afterwards.
while (numberOfVisibleColumns > 0) {
removeColumn(false);
}
while (numberOfVisibleColumns < desiredNumberOfColumns) {
addColumn(columnNames.get(numberOfVisibleColumns));
}
refreshRegexRows();
// Now, only display graphs that are associated with the selected regex.
graphsData = graphsDataList.get(selectedRegex);
graphsTable.removeAll();
selectedTableItem = null;
setSelectionControlsEnabled(false);
for (GraphData gd : graphsData) {
TableItem item = new TableItem(graphsTable, SWT.NONE);
setUpGraphTableItem(item, gd, badGraphs.contains(gd));
}
graphsGroup.setText(MessageFormat.format(Messages.SystemTapScriptGraphOptionsTab_graphSetTitleBase, selectedRegex + 1));
if (!textListenersDisabled) {
textListenersEnabled = true;
}
}
use of org.eclipse.linuxtools.systemtap.graphing.core.structures.GraphData in project linuxtools by eclipse.
the class SystemTapScriptGraphOptionsTab method performApply.
@Override
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
configuration.setAttribute(RUN_WITH_CHART, this.runWithChartCheckButton.getSelection());
int numberOfRegexs = getNumberOfRegexs();
for (int r = 0; r < numberOfRegexs; r++) {
// Save data sets, and clear removed ones.
configuration.setAttribute(REGULAR_EXPRESSION + r, regularExpressionCombo.getItem(r));
configuration.setAttribute(SAMPLE_OUTPUT + r, outputList.get(r));
List<String> columnNames = columnNamesList.get(r);
int numberOfColumns = columnNames.size();
for (int i = 0; i < numberOfColumns; i++) {
configuration.setAttribute(get2DConfigData(REGEX_BOX, r, i), columnNames.get(i));
}
cleanUpConfigurationItem(configuration, NUMBER_OF_COLUMNS, REGEX_BOX, r, numberOfColumns);
configuration.setAttribute(NUMBER_OF_COLUMNS + r, numberOfColumns);
// If the current regex has graphs with missing data, store all cached names
// in the configuration so that they will be easily restorable for next time.
Stack<String> extranames = cachedNamesList.get(r);
int numberOfExtras = findBadGraphs(r) == null ? 0 : extranames.size();
for (int i = 0; i < numberOfExtras; i++) {
configuration.setAttribute(get2DConfigData(EXTRA_BOX, r, i), extranames.get(i));
}
cleanUpConfigurationItem(configuration, NUMBER_OF_EXTRAS, EXTRA_BOX, r, numberOfExtras);
configuration.setAttribute(NUMBER_OF_EXTRAS + r, numberOfExtras);
// Save new graphs, and clear removed ones.
LinkedList<GraphData> list = graphsDataList.get(r);
int numberOfGraphs = list.size();
for (int i = 0; i < numberOfGraphs; i++) {
GraphData graphData = list.get(i);
configuration.setAttribute(get2DConfigData(GRAPH_TITLE, r, i), graphData.title);
configuration.setAttribute(get2DConfigData(GRAPH_KEY, r, i), graphData.key);
configuration.setAttribute(get2DConfigData(GRAPH_X_SERIES, r, i), graphData.xSeries);
configuration.setAttribute(get2DConfigData(GRAPH_ID, r, i), graphData.graphID);
int ySeriesLength = graphData.ySeries.length;
for (int j = 0; j < ySeriesLength; j++) {
// $NON-NLS-1$
configuration.setAttribute(// $NON-NLS-1$
get2DConfigData(GRAPH_Y_SERIES, r, i + "_" + j), graphData.ySeries[j]);
}
cleanUpConfigurationGraphYSeries(configuration, r, i, ySeriesLength);
configuration.setAttribute(get2DConfigData(GRAPH_Y_SERIES_LENGTH, r, i), ySeriesLength);
}
cleanUpConfigurationGraphs(configuration, r, numberOfGraphs);
configuration.setAttribute(NUMBER_OF_GRAPHS + r, numberOfGraphs);
}
cleanUpConfiguration(configuration, numberOfRegexs);
configuration.setAttribute(NUMBER_OF_REGEXS, numberOfRegexs);
}
use of org.eclipse.linuxtools.systemtap.graphing.core.structures.GraphData in project linuxtools by eclipse.
the class SystemTapScriptGraphOptionsTab method createColumnSelector.
private void createColumnSelector(Composite parent) {
GridLayout layout = new GridLayout();
parent.setLayout(layout);
Composite topLayout = new Composite(parent, SWT.NONE);
topLayout.setLayout(new GridLayout(1, false));
topLayout.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
Button generateExpsButton = new Button(topLayout, SWT.PUSH);
generateExpsButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
generateExpsButton.setText(Messages.SystemTapScriptGraphOptionsTab_generateFromPrintsButton);
generateExpsButton.setToolTipText(Messages.SystemTapScriptGraphOptionsTab_generateFromPrintsTooltip);
generateExpsButton.addSelectionListener(regexGenerator);
Composite regexButtonLayout = new Composite(parent, SWT.NONE);
regexButtonLayout.setLayout(new GridLayout(3, false));
regexButtonLayout.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
Label selectedRegexLabel = new Label(regexButtonLayout, SWT.NONE);
selectedRegexLabel.setText(Messages.SystemTapScriptGraphOptionsTab_regexLabel);
selectedRegexLabel.setToolTipText(Messages.SystemTapScriptGraphOptionsTab_regexTooltip);
regularExpressionCombo = new Combo(regexButtonLayout, SWT.DROP_DOWN);
regularExpressionCombo.setTextLimit(MAX_REGEX_LENGTH);
regularExpressionCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
regularExpressionCombo.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
int selected = regularExpressionCombo.getSelectionIndex();
if (selected == selectedRegex) {
return;
}
// If deselecting an empty regular expression, delete it automatically.
if (regularExpressionCombo.getItem(selectedRegex).isEmpty() && graphsDataList.get(selectedRegex).size() == 0 && outputList.get(selectedRegex).isEmpty()) {
// Otherwise, the deleted blank entry would be replaced by another blank entry.
if (selected == regularExpressionCombo.getItemCount() - 1) {
// To keep the text blank.
regularExpressionCombo.select(selectedRegex);
return;
}
removeRegex(false);
if (selected > selectedRegex) {
selected--;
}
}
// update all appropriate values to make room for a new regular expression.
if (selected == regularExpressionCombo.getItemCount() - 1 && getNumberOfRegexs() < MAX_NUMBER_OF_REGEXS) {
// $NON-NLS-1$
outputList.add("");
regexErrorMessages.add(null);
columnNamesList.add(new ArrayList<String>());
cachedNamesList.add(new Stack<String>());
graphsDataList.add(new LinkedList<GraphData>());
// Remove "Add New Regex" from the selected combo item; make it blank.
// $NON-NLS-1$
regularExpressionCombo.setItem(selected, "");
regularExpressionCombo.select(selected);
updateRegexSelection(selected, false);
updateLaunchConfigurationDialog();
// (Don't do this _every_ time something is added.)
if (getNumberOfRegexs() == 2) {
removeRegexButton.setEnabled(true);
}
if (getNumberOfRegexs() < MAX_NUMBER_OF_REGEXS) {
regularExpressionCombo.add(Messages.SystemTapScriptGraphOptionsTab_regexAddNew);
}
} else {
updateRegexSelection(selected, false);
}
}));
regularExpressionCombo.addModifyListener(regexListener);
removeRegexButton = new Button(regexButtonLayout, SWT.PUSH);
removeRegexButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
removeRegexButton.setText(Messages.SystemTapScriptGraphOptionsTab_regexRemove);
removeRegexButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
IWorkbench workbench = PlatformUI.getWorkbench();
MessageDialog dialog = new MessageDialog(workbench.getActiveWorkbenchWindow().getShell(), Messages.SystemTapScriptGraphOptionsTab_removeRegexTitle, null, MessageFormat.format(Messages.SystemTapScriptGraphOptionsTab_removeRegexAsk, regularExpressionCombo.getItem(selectedRegex)), MessageDialog.QUESTION, new String[] { "Yes", "No" }, // $NON-NLS-1$ //$NON-NLS-2$
0);
int result = dialog.open();
if (result == 0) {
// Yes
removeRegex(true);
}
}));
GridLayout twoColumns = new GridLayout(2, false);
Composite regexSummaryComposite = new Composite(parent, SWT.NONE);
regexSummaryComposite.setLayout(twoColumns);
regexSummaryComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
Label sampleOutputLabel = new Label(regexSummaryComposite, SWT.NONE);
sampleOutputLabel.setText(Messages.SystemTapScriptGraphOptionsTab_sampleOutputLabel);
sampleOutputLabel.setToolTipText(Messages.SystemTapScriptGraphOptionsTab_sampleOutputTooltip);
this.sampleOutputText = new Text(regexSummaryComposite, SWT.BORDER);
this.sampleOutputText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
this.sampleOutputText.addModifyListener(sampleOutputListener);
sampleOutputText.setToolTipText(Messages.SystemTapScriptGraphOptionsTab_sampleOutputTooltip);
Composite expressionTableLabels = new Composite(parent, SWT.NONE);
expressionTableLabels.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
expressionTableLabels.setLayout(twoColumns);
Label label = new Label(expressionTableLabels, SWT.NONE);
label.setText(Messages.SystemTapScriptGraphOptionsTab_columnTitle);
label.setAlignment(SWT.LEFT);
Label label2 = new Label(expressionTableLabels, SWT.NONE);
label2.setAlignment(SWT.LEFT);
label2.setText(Messages.SystemTapScriptGraphOptionsTab_extractedValueLabel);
ScrolledComposite regexTextScrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.BORDER);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
data.heightHint = 200;
regexTextScrolledComposite.setLayoutData(data);
textFieldsComposite = new Composite(regexTextScrolledComposite, SWT.NONE);
textFieldsComposite.setLayout(new GridLayout(4, false));
regexTextScrolledComposite.setContent(textFieldsComposite);
regexTextScrolledComposite.setExpandHorizontal(true);
// To position the column labels properly, add a dummy column and use its children's sizes for reference.
// This is necessary since expressionTableLabels can't share a layout with textFieldsComposite.
textListenersEnabled = false;
addColumn(null);
data = new GridData(SWT.FILL, SWT.FILL, false, false);
data.horizontalIndent = textFieldsComposite.getChildren()[2].getLocation().x;
data.widthHint = textFieldsComposite.getChildren()[2].getSize().x;
label.setLayoutData(data);
label2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
removeColumn(false);
textListenersEnabled = true;
}
Aggregations