Search in sources :

Example 1 with TracedNode

use of org.erlide.tracing.core.mvc.model.TracedNode in project erlide_eclipse by erlang.

the class NodeCellModifier method modify.

@Override
public void modify(final Object element, final String property, final Object value) {
    final TracedNode node = (TracedNode) ((TableItem) element).getData();
    switch(NodeColumn.valueOf(property)) {
        case COOKIE:
            node.setCookie((String) value);
            break;
        case ENABLED:
            node.setEnabled((Boolean) value);
            break;
        case NODE_NAME:
            node.setNodeName((String) value);
            break;
        default:
    }
    tableViewer.refresh();
}
Also used : TracedNode(org.erlide.tracing.core.mvc.model.TracedNode)

Example 2 with TracedNode

use of org.erlide.tracing.core.mvc.model.TracedNode in project erlide_eclipse by erlang.

the class ProcessHelper method getProcsOnTracedNodes.

/**
 * Returns list of processes on all traced nodes.
 *
 * @return list of processes
 */
public static TracedProcess[] getProcsOnTracedNodes() {
    try {
        final IOtpRpc backend = TraceBackend.getInstance().getBackend(true).getOtpRpc();
        final List<OtpErlangAtom> nodeAtoms = new ArrayList<>();
        for (final Object o : TraceBackend.getInstance().getTracedNodesArray()) {
            final TracedNode tracedNode = (TracedNode) o;
            if (tracedNode.isEnabled()) {
                nodeAtoms.add(new OtpErlangAtom(tracedNode.getNodeName()));
            }
        }
        final OtpErlangList nodesList = new OtpErlangList(nodeAtoms.toArray(new OtpErlangAtom[nodeAtoms.size()]));
        final OtpErlangList procList = (OtpErlangList) backend.call(ProcessHelper.MODULE_NAME, ProcessHelper.FUNCTION_NAME, "x", nodesList);
        final TracedProcess[] processes = new TracedProcess[procList.arity()];
        for (int i = 0; i < procList.arity(); i++) {
            final OtpErlangTuple tuple = (OtpErlangTuple) procList.elementAt(i);
            processes[i] = new TracedProcess(tuple);
        }
        return processes;
    } catch (final RpcException e) {
        ErlLogger.error(e);
    }
    return null;
}
Also used : TracedProcess(org.erlide.tracing.core.mvc.model.TracedProcess) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) RpcException(org.erlide.runtime.rpc.RpcException) ArrayList(java.util.ArrayList) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) TracedNode(org.erlide.tracing.core.mvc.model.TracedNode) IOtpRpc(org.erlide.runtime.rpc.IOtpRpc)

Example 3 with TracedNode

use of org.erlide.tracing.core.mvc.model.TracedNode in project erlide_eclipse by erlang.

the class ControlPanelView method createNodeButtonsPanel.

private void createNodeButtonsPanel(final Composite parent) {
    final Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new RowLayout());
    // "Add" button
    Button button = new Button(container, SWT.PUSH | SWT.CENTER);
    button.setText("New node");
    button.setToolTipText("Add new node you want to trace");
    button.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD));
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            TraceBackend.getInstance().addTracedNode(new TracedNode());
            nodesTableViewer.refresh();
        }
    });
    // "Remove" button
    button = new Button(container, SWT.PUSH | SWT.CENTER);
    button.setText("Remove node");
    button.setToolTipText("Remove selected node");
    button.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE));
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final TracedNode tracedNode = (TracedNode) ((IStructuredSelection) nodesTableViewer.getSelection()).getFirstElement();
            if (tracedNode != null) {
                TraceBackend.getInstance().removeTracedNode(tracedNode);
                nodesTableViewer.refresh();
            }
        }
    });
    // "Add erlide nodes" button
    button = new Button(container, SWT.PUSH | SWT.CENTER);
    button.setText("Add existing nodes");
    button.setToolTipText("Add all Erlang nodes started directly from eclipse");
    button.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD));
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            for (final IBackend backend : NodeHelper.getBackends(true)) {
                final TracedNode node = new TracedNode();
                node.setNodeName(backend.getName());
                TraceBackend.getInstance().addTracedNode(node);
            }
            nodesTableViewer.refresh();
        }
    });
    // Pattern config buttons
    final Button loadConfigButton = new Button(container, SWT.PUSH | SWT.CENTER);
    final Button deleteConfigButton = new Button(container, SWT.PUSH | SWT.CENTER);
    final Button saveConfigButton = new Button(container, SWT.PUSH | SWT.CENTER);
    final Button saveAsConfigButton = new Button(container, SWT.PUSH | SWT.CENTER);
    final Label configNameLabel = new Label(container, SWT.NULL);
    configNameLabel.setLayoutData(new RowData(120, SWT.DEFAULT));
    // "Load nodes config" button
    loadConfigButton.setToolTipText("Load nodes configuration...");
    loadConfigButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER));
    loadConfigButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final ElementListSelectionDialog dialog = new SelectConfigurationDialog(parent.getShell(), new LabelProvider());
            dialog.setElements(ConfigurationManager.getNodesConfig());
            dialog.open();
            final String result = (String) dialog.getFirstResult();
            if (result != null) {
                nodesConfigName = result;
                configNameLabel.setText(nodesConfigName);
                TraceBackend.getInstance().loadTracedNodes(ConfigurationManager.loadNodesConfig(nodesConfigName));
                nodesTableViewer.refresh();
            }
        }
    });
    // "Delete nodes configuration" button
    deleteConfigButton.setToolTipText("Delete current node configuration...");
    deleteConfigButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ELCL_REMOVE));
    deleteConfigButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (nodesConfigName != null) {
                final MessageBox messageBox = new MessageBox(parent.getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
                messageBox.setMessage("Delete \"" + nodesConfigName + "\"?");
                messageBox.setText("Delete configuration");
                if (messageBox.open() == SWT.YES) {
                    ConfigurationManager.removeNodesConfig(nodesConfigName);
                    nodesConfigName = null;
                    configNameLabel.setText("");
                }
            }
        }
    });
    // "Save nodes configuration" button
    saveConfigButton.setToolTipText("Save current nodes configuration");
    saveConfigButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ETOOL_SAVE_EDIT));
    saveConfigButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (nodesConfigName != null) {
                if (!ConfigurationManager.saveNodesConfig(nodesConfigName)) {
                    final MessageBox messageBox = new MessageBox(parent.getShell(), SWT.ICON_ERROR | SWT.OK);
                    messageBox.setMessage("Unable to save configuration: " + nodesConfigName);
                    messageBox.setText("Error");
                    messageBox.open();
                }
            }
        }
    });
    // "Save nodes configuration as..." button
    saveAsConfigButton.setToolTipText("Save current nodes configuration as...");
    saveAsConfigButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ETOOL_SAVEAS_EDIT));
    saveAsConfigButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final String[] configurations = ConfigurationManager.getNodesConfig();
            final Set<String> existingNames = new HashSet<>(Arrays.asList(configurations));
            final InputDialog dialog = new ConfigurationSaveAsDialog(parent.getShell(), "Save nodes configuration", "Enter name for configuration:", nodesConfigName, existingNames);
            if (dialog.open() == Window.OK) {
                if (ConfigurationManager.saveNodesConfig(dialog.getValue())) {
                    nodesConfigName = dialog.getValue();
                    configNameLabel.setText(nodesConfigName);
                } else {
                    final MessageBox messageBox = new MessageBox(parent.getShell(), SWT.ICON_ERROR | SWT.OK);
                    messageBox.setMessage("Unable to save configuration: " + dialog.getValue());
                    messageBox.setText("Error");
                    messageBox.open();
                }
            }
        }
    });
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) InputDialog(org.eclipse.jface.dialogs.InputDialog) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TracedNode(org.erlide.tracing.core.mvc.model.TracedNode) SelectConfigurationDialog(org.erlide.tracing.core.ui.dialogs.SelectConfigurationDialog) MessageBox(org.eclipse.swt.widgets.MessageBox) RowData(org.eclipse.swt.layout.RowData) Button(org.eclipse.swt.widgets.Button) ElementListSelectionDialog(org.eclipse.ui.dialogs.ElementListSelectionDialog) RowLayout(org.eclipse.swt.layout.RowLayout) IBackend(org.erlide.backend.api.IBackend) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ConfigurationSaveAsDialog(org.erlide.tracing.core.ui.dialogs.ConfigurationSaveAsDialog) NodeLabelProvider(org.erlide.tracing.core.mvc.view.NodeLabelProvider) TracePatternLabelProvider(org.erlide.tracing.core.mvc.view.TracePatternLabelProvider) ProcessLabelProvider(org.erlide.tracing.core.mvc.view.ProcessLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 4 with TracedNode

use of org.erlide.tracing.core.mvc.model.TracedNode in project erlide_eclipse by erlang.

the class TraceBackend method start.

/**
 * Starts tracing given nodes.
 *
 * @return <code>true</code> if successful, <code>false</code> otherwise
 */
public TracingStatus start() {
    TracingStatus status = TracingStatus.OK;
    if (!tracing) {
        synchronized (this) {
            if (!tracing) {
                try {
                    tracing = true;
                    getBackend(true);
                    loadingFileInfo = true;
                    handler = new TraceEventHandler();
                    tracerBackend.getRuntime().registerEventListener(handler);
                    // list of nodes being traced
                    final List<OtpErlangObject> erlangObjects = new ArrayList<>();
                    notActivatedNodes = new HashSet<>();
                    for (final TracedNode tracedNode : tracedNodes) {
                        if (tracedNode.isEnabled()) {
                            final OtpErlangAtom name = new OtpErlangAtom(tracedNode.getNodeName());
                            final OtpErlangAtom cookie = new OtpErlangAtom(tracedNode.getCookie());
                            erlangObjects.add(new OtpErlangTuple(new OtpErlangObject[] { name, cookie }));
                            notActivatedNodes.add(tracedNode.getNodeName());
                        }
                    }
                    final OtpErlangList nodes = new OtpErlangList(erlangObjects.toArray(new OtpErlangObject[erlangObjects.size()]));
                    // net tick time
                    final int tickTimeValue = Activator.getDefault().getPreferenceStore().getInt(PreferenceNames.TICK_TIME);
                    final OtpErlangInt netTickTime = new OtpErlangInt(tickTimeValue);
                    final OtpErlangObject callResult = tracerBackend.getOtpRpc().call(Constants.ERLANG_HELPER_MODULE, TraceBackend.FUN_START, "xsi", nodes, Constants.OUTPUT_FILE, netTickTime);
                    status = processResult(callResult);
                    if (TracingStatus.OK.equals(status) || TracingStatus.NOT_ALL_NODES_ACTIVATED.equals(status)) {
                        setProcessFlags();
                        setFunctionTracePatterns();
                        for (final ITraceNodeObserver listener : listeners) {
                            try {
                                listener.startTracing();
                            } catch (final Exception e) {
                                ErlLogger.error(e);
                            }
                        }
                    } else {
                        tracing = false;
                    }
                } catch (final Exception e) {
                    ErlLogger.error(e);
                    status = TracingStatus.EXCEPTION_THROWN;
                    errorObject = e;
                    tracing = false;
                }
            }
        }
    }
    return status;
}
Also used : OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) ArrayList(java.util.ArrayList) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) TracedNode(org.erlide.tracing.core.mvc.model.TracedNode) RpcException(org.erlide.runtime.rpc.RpcException) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangInt(com.ericsson.otp.erlang.OtpErlangInt) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple)

Aggregations

TracedNode (org.erlide.tracing.core.mvc.model.TracedNode)4 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)2 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)2 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)2 ArrayList (java.util.ArrayList)2 RpcException (org.erlide.runtime.rpc.RpcException)2 OtpErlangInt (com.ericsson.otp.erlang.OtpErlangInt)1 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 InputDialog (org.eclipse.jface.dialogs.InputDialog)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 RowData (org.eclipse.swt.layout.RowData)1 RowLayout (org.eclipse.swt.layout.RowLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1