use of org.eclipse.linuxtools.systemtap.structures.TreeNode in project linuxtools by eclipse.
the class TreeSettings method readTree.
/**
* Opposite action as writeTree. Reconstruct a tree from a previously-saved {@link IMemento}.
* @param data The {@link IMemento} to read the tree out of.
* @return The reconstructed {@link TreeNode}.
*/
private static TreeNode readTree(IMemento data) {
String disp = data.getString(M_DISP);
String def = data.getString(M_DEFINITON);
boolean c = data.getBoolean(M_CLICKABLE);
Object d = StapTreeDataFactory.createObjectFromString(data.getString(M_DATA), data.getString(M_DATATYPE));
TreeNode parent;
if (def == null) {
parent = new TreeNode(d, disp, c);
} else {
parent = new TreeDefinitionNode(d, disp, getValueFromString(def), c);
}
for (IMemento child : data.getChildren()) {
parent.add(readTree(child));
}
return parent;
}
use of org.eclipse.linuxtools.systemtap.structures.TreeNode in project linuxtools by eclipse.
the class ProbeParser method delTapsets.
@Override
protected int delTapsets(String[] tapsets, IProgressMonitor monitor) {
TreeNode aliases = tree.getChildByName(Messages.ProbeParser_aliasProbes);
// come from removed directories, and remove them from the group.
for (int i = 0; i < tapsets.length; i++) {
for (int g = 0, gn = aliases.getChildCount(); g < gn; g++) {
if (monitor.isCanceled()) {
return IStatus.CANCEL;
}
TreeNode group = aliases.getChildAt(g);
for (int p = 0, pn = group.getChildCount(); p < pn; p++) {
String definition = ((TreeDefinitionNode) group.getChildAt(p)).getDefinition();
if (definition != null && definition.startsWith(tapsets[i])) {
group.remove(p--);
pn--;
}
}
// If removing the only probe left in a probe group, remove the group.
if (group.getChildCount() == 0) {
aliases.remove(g--);
gn--;
}
}
}
return IStatus.OK;
}
use of org.eclipse.linuxtools.systemtap.structures.TreeNode in project linuxtools by eclipse.
the class ProbeParser method addStaticProbes.
/**
* Runs stap to obtain a log of all static probes, and populate the probe tree with them.
* @return An {@link IStatus} severity level for the result of the operation.
*/
private int addStaticProbes(IProgressMonitor monitor) {
TreeNode statics = new TreeNode(Messages.ProbeParser_staticProbes, false);
tree.add(statics);
if (monitor.isCanceled()) {
return IStatus.CANCEL;
}
// $NON-NLS-1$
String probeDump = runStap(new String[] { "--dump-probe-types" }, null, false);
int result = verifyRunResult(probeDump);
if (result != IStatus.OK) {
return result;
}
if (!doQuickErrorCheck(probeDump)) {
return IStatus.ERROR;
}
boolean canceled = false;
try (Scanner st = new Scanner(probeDump)) {
TreeNode groupNode = null;
while (st.hasNextLine()) {
if (monitor.isCanceled()) {
canceled = true;
break;
}
String tokenString = st.nextLine();
groupNode = addOrFindProbeGroup(extractProbeGroupName(tokenString), groupNode, statics);
groupNode.add(makeStaticProbeNode(tokenString));
}
}
statics.sortTree();
return !canceled ? IStatus.OK : IStatus.CANCEL;
}
use of org.eclipse.linuxtools.systemtap.structures.TreeNode in project linuxtools by eclipse.
the class ProbeParser method addSingleProbeAlias.
/**
* Adds a single probe alias to the collection.
* @param probeLine A line of probe information printed by a call to "stap -L".
* @param aliases The tree of probe aliases. The probe will be added to this tree.
* @param groupNode For optimization, pass an existing group node here, as it will be used if the
* probe belongs in it. Otherwise, or if <code>null</code> is passed, a new one will be created.
* @param groupName The name of the probe group, or <code>null</code> if it is unknown at the time
* this method is called.
* @param definition The path of the file in which this probe is defined, or <code>null</code> if it
* is unknown at the time this method is called.
*/
private TreeNode addSingleProbeAlias(String probeLine, TreeNode aliases, TreeNode groupNode, String groupName, String definition) {
StringTokenizer probeTokenizer = new StringTokenizer(probeLine);
String probeName = probeTokenizer.nextToken();
TreeNode probeNode = makeProbeAliasNode(probeName, definition == null ? findDefinitionOf(probeName) : definition);
groupNode = addOrFindProbeGroup(groupName == null ? extractProbeGroupName(probeName) : groupName, groupNode, aliases);
groupNode.add(probeNode);
addAllVarNodesToProbeNode(probeTokenizer, probeNode);
return groupNode;
}
use of org.eclipse.linuxtools.systemtap.structures.TreeNode in project linuxtools by eclipse.
the class ProbeParser method addTapsets.
@Override
protected int addTapsets(String tapsetContents, String[] additions, IProgressMonitor monitor) {
boolean canceled = false;
TreeNode aliases = tree.getChildByName(Messages.ProbeParser_aliasProbes);
Map<String, ArrayList<String>> fileToItemMap = new HashMap<>();
// Search tapset contents for all files provided by each added directory.
for (int i = 0; i < additions.length; i++) {
int firstTagIndex = 0;
while (true) {
// Get the contents of each file provided by the directory additions[i].
firstTagIndex = tapsetContents.indexOf(SharedParser.makeFileTag(additions[i]), firstTagIndex);
if (firstTagIndex == -1) {
break;
}
int nextTagIndex = tapsetContents.indexOf(SharedParser.TAG_FILE, firstTagIndex + 1);
String fileContents = nextTagIndex != -1 ? tapsetContents.substring(firstTagIndex, nextTagIndex) : tapsetContents.substring(firstTagIndex);
String filename;
try (Scanner st = new Scanner(fileContents)) {
filename = SharedParser.findFileNameInTag(st.nextLine());
}
// Search file contents for the probes the file provides.
ArrayList<String> newItems = new ArrayList<>();
Matcher matcher = Pattern.compile(MessageFormat.format(TAPSET_PROBE_REGEX, // $NON-NLS-1$
"(\\S+)")).matcher(fileContents);
while (matcher.find()) {
newItems.add(matcher.group(1));
}
if (!newItems.isEmpty()) {
fileToItemMap.put(filename, newItems);
}
// Remove the contents of the file that was just examined from the total contents.
tapsetContents = tapsetContents.substring(0, firstTagIndex).concat(tapsetContents.substring(firstTagIndex + fileContents.length()));
}
}
// Run stap on each discovered probe to obtain their variable information.
for (Map.Entry<String, ArrayList<String>> entry : fileToItemMap.entrySet()) {
for (String newitem : entry.getValue()) {
if (canceled || monitor.isCanceled()) {
canceled = true;
break;
}
addSingleProbeAlias(// $NON-NLS-1$
runStap(new String[] { "-L" }, newitem, false), aliases, null, null, entry.getKey());
}
}
aliases.sortTree();
return !canceled ? IStatus.OK : IStatus.CANCEL;
}
Aggregations