From 41ac47d732eed8392d60d0f6773e5a279d49b999 Mon Sep 17 00:00:00 2001 From: Adrian Dudau Date: Thu, 12 Dec 2013 13:36:50 +0100 Subject: initial commit of Enea Linux 3.1 Migrated from the internal git server on the dora-enea branch Signed-off-by: Adrian Dudau --- .../yocto/sdk/remotetools/actions/BaseModel.java | 123 +++++++++ .../sdk/remotetools/actions/BaseSettingDialog.java | 216 ++++++++++++++++ .../sdk/remotetools/actions/DialogHandler.java | 42 ++++ .../sdk/remotetools/actions/IBaseConstants.java | 27 ++ .../sdk/remotetools/actions/LatencytopHandler.java | 35 +++ .../sdk/remotetools/actions/OprofileHandler.java | 55 ++++ .../sdk/remotetools/actions/OprofileModel.java | 171 +++++++++++++ .../yocto/sdk/remotetools/actions/PerfHandler.java | 30 +++ .../sdk/remotetools/actions/PowertopHandler.java | 48 ++++ .../sdk/remotetools/actions/PowertopModel.java | 109 ++++++++ .../remotetools/actions/PowertopSettingDialog.java | 131 ++++++++++ .../remotetools/actions/SimpleSettingDialog.java | 54 ++++ .../sdk/remotetools/actions/SystemtapHandler.java | 70 ++++++ .../sdk/remotetools/actions/SystemtapModel.java | 88 +++++++ .../actions/SystemtapSettingDialog.java | 280 +++++++++++++++++++++ .../yocto/sdk/remotetools/actions/Ust2Handler.java | 59 +++++ .../yocto/sdk/remotetools/actions/Ust2Model.java | 166 ++++++++++++ .../sdk/remotetools/actions/Ust2SettingDialog.java | 104 ++++++++ .../remotetools/actions/UstSettingDialogBase.java | 170 +++++++++++++ .../sdk/remotetools/actions/YoctoBspHandler.java | 38 +++ 20 files changed, 2016 insertions(+) create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseModel.java create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseSettingDialog.java create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/DialogHandler.java create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/IBaseConstants.java create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/LatencytopHandler.java create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/OprofileHandler.java create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/OprofileModel.java create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PerfHandler.java create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopHandler.java create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopModel.java create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopSettingDialog.java create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SimpleSettingDialog.java create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapHandler.java create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapModel.java create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapSettingDialog.java create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2Handler.java create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2Model.java create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2SettingDialog.java create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/UstSettingDialogBase.java create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/YoctoBspHandler.java (limited to 'plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions') diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseModel.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseModel.java new file mode 100644 index 0000000..dacd192 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseModel.java @@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 2010 Intel Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel - initial API and implementation + *******************************************************************************/ +package org.yocto.sdk.remotetools.actions; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.rse.core.model.IHost; +import org.yocto.remote.utils.RSEHelper; +import org.yocto.remote.utils.RemoteShellExec; + +abstract public class BaseModel implements IRunnableWithProgress { + protected IHost host; + protected String taskName; + protected String localScript; + protected String remoteExec; + protected String localFile; + protected String remoteFile; + + private static final int WORKLOAD = 100; + + private static final int INIT_PERCENT = 5; + private static final int PRE_PROCESS_PERCENT = 30; + private static final int PROCESS_PERCENT = 30; + private static final int POST_PROCESS_PERCENT = 30; + private static final int CLEAN_PERCENT = 5; + + private static final String RUN_MSG = "Running task: "; + private static final String INIT_MSG = "Initializing "; + private static final String PRE_PROCESS_MSG = "Preparing "; + private static final String PROCESS_MSG = "Processing "; + private static final String POST_PROCESS_MSG = "Finishing "; + private static final String CLEAN_MSG = "Cleaning "; + private static final String DOTS = "..."; + private static final String FAILED_ERR_MSG = " failed with exit code "; + + public void preProcess(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException{ + //upload script to remote + try { + RSEHelper.putRemoteFileInPlugin(host, localScript, remoteExec, monitor); + }catch (InterruptedException e){ + throw e; + }catch (InvocationTargetException e) { + throw e; + }catch (Exception e) { + throw new InvocationTargetException(e, e.getMessage()); + } + } + public void postProcess(IProgressMonitor monitor) throws InvocationTargetException,InterruptedException{} + + abstract public void process(IProgressMonitor monitor) throws InvocationTargetException,InterruptedException; + + public BaseModel(IHost host, String taskName, String localScript, String remoteExec) { + this.host = host; + this.taskName = taskName; + this.localScript = localScript; + this.remoteExec = remoteExec; + } + protected void init(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + } + + protected void clean(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + } + + public void run(IProgressMonitor monitor) throws InvocationTargetException, + InterruptedException { + + try { + monitor.beginTask(RUN_MSG + taskName, WORKLOAD); + + monitor.subTask(INIT_MSG + taskName + DOTS); + init(new SubProgressMonitor(monitor, INIT_PERCENT)); + + monitor.subTask(PRE_PROCESS_MSG + taskName + DOTS); + preProcess(new SubProgressMonitor(monitor, PRE_PROCESS_PERCENT)); + + monitor.subTask(PROCESS_MSG + taskName + DOTS); + process(new SubProgressMonitor(monitor, PROCESS_PERCENT)); + + monitor.subTask(POST_PROCESS_MSG + taskName + DOTS); + postProcess(new SubProgressMonitor(monitor, POST_PROCESS_PERCENT)); + } catch (InterruptedException e){ + throw new InterruptedException("User cancelled!"); + } catch (InvocationTargetException e) { + throw e; + } finally { + monitor.subTask(CLEAN_MSG + taskName + DOTS); + clean(new SubProgressMonitor(monitor, CLEAN_PERCENT)); + monitor.done(); + } + } + + protected void getDataFile(IProgressMonitor monitor) throws Exception { + RSEHelper.getRemoteFile( host, localFile, remoteFile, monitor); + } + protected void runRemoteShellExec(IProgressMonitor monitor, String args, boolean cancelable) throws Exception { + try { + RemoteShellExec exec = new RemoteShellExec(host, remoteExec); + exec.start(null, args, monitor); + monitor.worked(1); + checkTerminate(exec.getInputStream()); + int exit_code = exec.waitFor(cancelable ? monitor : null); + exec.terminate(); + if(exit_code != 0) + throw new Exception(taskName + FAILED_ERR_MSG + new Integer(exit_code).toString()); + } finally { + monitor.done(); + } + } + protected void checkTerminate(InputStream inputStream) throws IOException {} +} diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseSettingDialog.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseSettingDialog.java new file mode 100644 index 0000000..7845959 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseSettingDialog.java @@ -0,0 +1,216 @@ +/******************************************************************************* + * Copyright (c) 2006, 2010 PalmSource, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ewa Matejska (PalmSource) - initial API and implementation + * Martin Oberhuber (Wind River) - [186773] split ISystemRegistryUI from ISystemRegistry + * Martin Oberhuber (Wind River) - [196934] hide disabled system types in remotecdt combo + * Yu-Fen Kuo (MontaVista) - [190613] Fix NPE in Remotecdt when RSEUIPlugin has not been loaded + * Martin Oberhuber (Wind River) - [cleanup] Avoid using SystemStartHere in production code + * Johann Draschwandtner (Wind River) - [231827][remotecdt]Auto-compute default for Remote path + * Johann Draschwandtner (Wind River) - [233057][remotecdt]Fix button enablement + * Anna Dushistova (MontaVista) - [181517][usability] Specify commands to be run before remote application launch + * Anna Dushistova (MontaVista) - [223728] [remotecdt] connection combo is not populated until RSE is activated + * Anna Dushistova (MontaVista) - [267951] [remotecdt] Support systemTypes without files subsystem + * Lianhao Lu (Intel) - Modified for internal use + *******************************************************************************/ + +package org.yocto.sdk.remotetools.actions; + +import org.yocto.remote.utils.RSEHelper; +import org.yocto.sdk.remotetools.Messages; +import org.yocto.sdk.remotetools.SWTFactory; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.rse.core.model.IHost; +import org.eclipse.rse.ui.actions.SystemNewConnectionAction; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; + +public class BaseSettingDialog extends Dialog { + + protected String title; + protected String curConn; //current rse connection name + protected IHost conn;//rse IHost + + protected Button newRemoteConnectionButton; + protected Label connectionLabel; + protected Combo connectionCombo; + protected SystemNewConnectionAction action = null; + + + protected BaseSettingDialog(Shell parentShell,String title, String connection) { + super(parentShell); + this.title=title; + this.curConn=connection; + } + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText(title); + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite comp = (Composite)super.createDialogArea(parent); + GridLayout topLayout = new GridLayout(); + comp.setLayout(topLayout); + + /* The RSE Connection dropdown with New button. */ + SWTFactory.createVerticalSpacer(comp, 1); + createRemoteConnectionGroup(comp); + + return comp; + } + + + @Override + protected void createButtonsForButtonBar(Composite parent) { + super.createButtonsForButtonBar(parent); + updateCurConn(); + } + + protected void createRemoteConnectionGroup(Composite parent) { + Composite projComp = new Composite(parent, SWT.NONE); + GridLayout projLayout = new GridLayout(); + projLayout.numColumns = 6; + projLayout.marginHeight = 0; + projLayout.marginWidth = 0; + projComp.setLayout(projLayout); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + projComp.setLayoutData(gd); + + connectionLabel = new Label(projComp, SWT.NONE); + connectionLabel.setText(Messages.BaseSettingDialog_Connection); + gd = new GridData(); + gd.horizontalSpan = 1; + connectionLabel.setLayoutData(gd); + + connectionCombo = new Combo(projComp, SWT.DROP_DOWN | SWT.READ_ONLY); + gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 4; + connectionCombo.setLayoutData(gd); + connectionCombo.addModifyListener(new ModifyListener() { + + public void modifyText(ModifyEvent e) { + //setDirty(true); + //updateLaunchConfigurationDialog(); + //useDefaultsFromConnection(); + updateCurConn(); + } + }); + + newRemoteConnectionButton = SWTFactory.createPushButton(projComp, + Messages.BaseSettingDialog_New, null); + newRemoteConnectionButton.addSelectionListener(new SelectionAdapter() { + + public void widgetSelected(SelectionEvent evt) { + handleNewRemoteConnectionSelected(); + //updateLaunchConfigurationDialog(); + updateConnectionPulldown(); + } + }); + gd = new GridData(); + gd.horizontalSpan = 1; + newRemoteConnectionButton.setLayoutData(gd); + + updateConnectionPulldown(); + } + + protected boolean updateOkButton() { + boolean ret=false; + Button button=getButton(IDialogConstants.OK_ID); + if(button!=null) + button.setEnabled(false); + IHost currentConnectionSelected = getCurrentConnection(); + if (currentConnectionSelected != null) { + if (RSEHelper.isHostViable(currentConnectionSelected) && button != null){ + button.setEnabled(true); + ret=true; + } + } + return ret; + } + + protected void updateCurConn() { + IHost currentConnectionSelected = getCurrentConnection(); + if (currentConnectionSelected != null) { + if (RSEHelper.isHostViable(currentConnectionSelected)) + curConn=currentConnectionSelected.getAliasName(); + } + updateOkButton(); + } + + protected IHost getCurrentConnection() { + int currentSelection = connectionCombo.getSelectionIndex(); + String remoteConnection = currentSelection >= 0 ? connectionCombo + .getItem(currentSelection) : null; + return RSEHelper.getRemoteConnectionByName(remoteConnection); + } + + protected void handleNewRemoteConnectionSelected() { + if (action == null) { + action = new SystemNewConnectionAction(getShell(), + false, false, null); + } + + try { + action.run(); + } catch (Exception e) { + // Ignore + } + } + + protected void updateConnectionPulldown() { + int index=-1; + RSEHelper.waitForRSEInitCompletition(); + // already initialized + connectionCombo.removeAll(); + IHost[] connections = RSEHelper.getSuitableConnections(); + for (int i = 0; i < connections.length; i++) { + connectionCombo.add(connections[i].getAliasName()); + if(connections[i].getAliasName().equals(curConn)) + index=i; + } + + if(index>=0) { + connectionCombo.select(index); + }else if (connections.length > 0) { + connectionCombo.select(connections.length - 1); + } + + //TODO + //connectionCombo.computeSize(SWT.DEFAULT, SWT.DEFAULT,true); + connectionCombo.pack(true); + connectionCombo.layout(); + connectionCombo.getParent().layout(); + + updateCurConn(); + } + + @Override + protected void okPressed() { + conn=getCurrentConnection(); + super.okPressed(); + } + + public IHost getHost() { + return conn; + } +} diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/DialogHandler.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/DialogHandler.java new file mode 100644 index 0000000..231de77 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/DialogHandler.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2013 Intel Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel - initial API and implementation + *******************************************************************************/ +package org.yocto.sdk.remotetools.actions; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.rse.core.model.IHost; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.handlers.HandlerUtil; +import org.yocto.remote.utils.TerminalHandler; + +abstract public class DialogHandler extends TerminalHandler { + + protected BaseSettingDialog setting; + + abstract protected String getDialogTitle(); + + protected void initialize(ExecutionEvent event) throws ExecutionException{ + IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); + shell = window.getShell(); + setting = new SimpleSettingDialog(shell, getDialogTitle(), getConnnectionName()); + } + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + initialize(event); + + if(setting.open() == BaseSettingDialog.OK) { + IHost currentHost = setting.getHost(); + execute(currentHost); + } + return null; + } +} diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/IBaseConstants.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/IBaseConstants.java new file mode 100644 index 0000000..d4bbe12 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/IBaseConstants.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2010 Intel Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel - initial API and implementation + *******************************************************************************/ +package org.yocto.sdk.remotetools.actions; + +public interface IBaseConstants { + public static final String TCF_TYPE_ID="org.eclipse.tcf.rse.systemType";//$NON-NLS-1$ + + public static final String QUALIFIER="org.yocto.sdk.remotetools";//$NON-NLS-1$ + + public static final String CONNECTION_NAME_OPROFILE = QUALIFIER + "connection.oprofile"; //$NON-NLS-1$ + public static final String CONNECTION_NAME_UST = QUALIFIER + "connection.ust"; //$NON-NLS-1$ + public static final String CONNECTION_NAME_POWERTOP = QUALIFIER + "connection.powertop"; //$NON-NLS-1$ + public static final String CONNECTION_NAME_LATENCYTOP = QUALIFIER + "connection.latencytop"; //$NON-NLS-1$ + public static final String CONNECTION_NAME_PERF = QUALIFIER + "connection.perf"; //$NON-NLS-1$ + public static final String CONNECTION_NAME_SYSTEMTAP = QUALIFIER + "connection.systemtap"; //$NON-NLS-1$ + + public static final String DIALOG_TITLE_LATENCYTOP = "Latencytop"; //$NON-NLS-1$ + public static final String DIALOG_TITLE_PERF = "Perf"; //$NON-NLS-1$ +} diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/LatencytopHandler.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/LatencytopHandler.java new file mode 100644 index 0000000..1088dee --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/LatencytopHandler.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2010 Intel Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel - initial API and implementation + *******************************************************************************/ +package org.yocto.sdk.remotetools.actions; + + +public class LatencytopHandler extends DialogHandler { + + protected String changeTerm = "export TERM=xterm;"; + private static String initCmd="export PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin; cd; sudo latencytop\r"; + + @Override + protected String getInitCmd() { + return initCmd; + } + @Override + protected String changeTerm() { + return changeTerm; + } + @Override + protected String getConnnectionName() { + return IBaseConstants.CONNECTION_NAME_LATENCYTOP; + } + @Override + protected String getDialogTitle() { + return IBaseConstants.DIALOG_TITLE_LATENCYTOP; + } +} diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/OprofileHandler.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/OprofileHandler.java new file mode 100644 index 0000000..980737f --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/OprofileHandler.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2010 Intel Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel - initial API and implementation + *******************************************************************************/ +package org.yocto.sdk.remotetools.actions; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.progress.IProgressService; + +public class OprofileHandler extends AbstractHandler { + + public Object execute(ExecutionEvent event) throws ExecutionException { + + if(OprofileModel.checkAvail()!=true) { + return null; + } + + IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); + + SimpleSettingDialog setting=new SimpleSettingDialog( + window.getShell(), + "Oprofile", + IBaseConstants.CONNECTION_NAME_OPROFILE + ); + + if(setting.open()==BaseSettingDialog.OK) { + IProgressService progressService = PlatformUI.getWorkbench().getProgressService(); + OprofileModel op=new OprofileModel(setting.getHost(),window); + try { + progressService.busyCursorWhile(op); + }catch (InterruptedException e) { + //user cancelled + }catch (Exception e) { + e.printStackTrace(); + MessageDialog.openError(window.getShell(), + "Oprofile", + (e.getCause() != null) ? e.getCause().getMessage() : e.getMessage()); + } + } + return null; + } + +} diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/OprofileModel.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/OprofileModel.java new file mode 100644 index 0000000..7fbe7c6 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/OprofileModel.java @@ -0,0 +1,171 @@ +/******************************************************************************* + * Copyright (c) 2010 Intel Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel - initial API and implementation + *******************************************************************************/ +package org.yocto.sdk.remotetools.actions; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.rse.core.model.IHost; +import org.eclipse.ui.IWorkbenchWindow; +import org.yocto.remote.utils.CommonHelper; +import org.yocto.sdk.ide.YoctoSDKPlugin; +import org.yocto.sdk.ide.preferences.PreferenceConstants; +import org.yocto.sdk.remotetools.LocalJob; +import org.yocto.sdk.remotetools.Messages; + +public class OprofileModel extends BaseModel { + + private static final String REMOTE_EXEC = "/tmp/yocto_tool.sh"; + private static final String LOCAL_SCRIPT = "resources/yocto_tool.sh"; + + private static final String LOCAL_EXEC = "oprofile-viewer"; + + private static final String TASK_NAME = "oprofile command"; + + private IWorkbenchWindow window; + public OprofileModel(IHost host, IWorkbenchWindow window) { + super(host, TASK_NAME, LOCAL_SCRIPT, REMOTE_EXEC); + this.window = window; + } + + private void startServer(IProgressMonitor monitor) throws Exception { + String args="start -d oprofile-server"; + runRemoteShellExec(monitor, args, true); + } + + private void stopServer(IProgressMonitor monitor) throws Exception { + String args = "stop -d oprofile-server"; + runRemoteShellExec(monitor, args, false); + } + + private String getSearchPath() + { + try + { + String search=null; + IPreferenceStore store = YoctoSDKPlugin.getDefault().getPreferenceStore(); + String env_script=store.getString(PreferenceConstants.TOOLCHAIN_ROOT) + + "/" + + "environment-setup-" + + store.getString(PreferenceConstants.TOOLCHAIN_TRIPLET); + File file = new File(env_script); + + if (file.exists()) { + BufferedReader input = new BufferedReader(new FileReader(file)); + + try + { + String line = null; + + while ((line = input.readLine()) != null) + { + if (!line.startsWith("export")) + continue; + String sKey = line.substring("export".length() + 1, line.indexOf('=')); + if(!sKey.equals("PATH")) + continue; + String sValue = line.substring(line.indexOf('=') + 1); + if (sValue.startsWith("\"") && sValue.endsWith("\"")) + sValue = sValue.substring(sValue.indexOf('"') + 1, sValue.lastIndexOf('"')); + /* If PATH ending with $PATH, we need to join with current system path */ + if (sKey.equalsIgnoreCase("PATH")) { + if (sValue.lastIndexOf("$PATH") >= 0) + sValue = sValue.substring(0, sValue.lastIndexOf("$PATH")) + System.getenv("PATH"); + } + search=sValue; + //System.out.printf("get env key %s value %s\n", sKey, sValue); + } + + } + finally { + input.close(); + } + } + + return search; + + } + catch (IOException e) + { + e.printStackTrace(); + return null; + } + + } + + @Override + public void process(IProgressMonitor monitor) + throws InvocationTargetException, InterruptedException { + + boolean stopServer=true; + + try { + try { + monitor.beginTask("Starting oprofile", 100); + //start oprofile-server + monitor.subTask("Starting oprofile-server"); + startServer(new SubProgressMonitor(monitor,80)); + + //start local oprofile-viewer + monitor.subTask("oprofile-viewer is running locally"); + String searchPath=getSearchPath(); + + new LocalJob("oprofile-viewer", + (searchPath!=null) ? + new String[] {LOCAL_EXEC,"-h",host.getHostName(),"-s",searchPath} : + new String[] {LOCAL_EXEC,"-h",host.getHostName()}, + null, + null, + window).schedule(); + //we can't stop server because the oprofile-viewer is running asynchronously + stopServer=false; + + }catch (InterruptedException e) { + throw e; + }finally { + //stop oprofile-server + if(stopServer) { + monitor.subTask("Stopping oprofile-viewer"); + stopServer(new SubProgressMonitor(monitor,30)); + } + } + }catch (InterruptedException e){ + throw e; + }catch (InvocationTargetException e) { + throw e; + }catch (Exception e){ + throw new InvocationTargetException(e, e.getMessage()); + }finally { + monitor.done(); + } + } + + static public boolean checkAvail() { + boolean ret=CommonHelper.isExecAvail(LOCAL_EXEC); + + if(ret==false) { + CommonHelper.showErrorDialog("Oprofile", null,Messages.ErrorOprofileViewer); + }else { + ret=CommonHelper.isExecAvail("opreport"); + if(ret==false) { + CommonHelper.showErrorDialog("Oprofile", null,Messages.ErrorOprofile); + } + } + return ret; + } + +} diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PerfHandler.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PerfHandler.java new file mode 100644 index 0000000..f3f9e49 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PerfHandler.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2010 Intel Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel - initial API and implementation + *******************************************************************************/ +package org.yocto.sdk.remotetools.actions; + + +public class PerfHandler extends DialogHandler { + + private static String initCmd="cd; perf\r"; + + @Override + protected String getInitCmd() { + return initCmd; + } + @Override + protected String getConnnectionName() { + return IBaseConstants.CONNECTION_NAME_PERF; + } + @Override + protected String getDialogTitle() { + return IBaseConstants.DIALOG_TITLE_PERF; + } +} diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopHandler.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopHandler.java new file mode 100644 index 0000000..152f142 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopHandler.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2010 Intel Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel - initial API and implementation + *******************************************************************************/ +package org.yocto.sdk.remotetools.actions; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.progress.IProgressService; + +public class PowertopHandler extends AbstractHandler { + + public Object execute(ExecutionEvent event) throws ExecutionException { + IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); + + PowertopSettingDialog setting=new PowertopSettingDialog( + window.getShell() + ); + + if(setting.open()==BaseSettingDialog.OK) { + IProgressService progressService = PlatformUI.getWorkbench().getProgressService(); + PowertopModel op=new PowertopModel(setting.getHost(),setting.getTime(),setting.getShowPid(),window.getShell().getDisplay()); + try { + progressService.busyCursorWhile(op); + }catch (InterruptedException e) { + //user cancelled + }catch (Exception e) { + e.printStackTrace(); + MessageDialog.openError(window.getShell(), + "Powertop", + (e.getCause() != null) ? e.getCause().getMessage() : e.getMessage()); + } + } + return null; + } + +} diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopModel.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopModel.java new file mode 100644 index 0000000..79bef61 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopModel.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2010 Intel Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel - initial API and implementation + *******************************************************************************/ +package org.yocto.sdk.remotetools.actions; + +import java.io.File; +import java.lang.reflect.InvocationTargetException; +import java.text.SimpleDateFormat; +import java.util.Calendar; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.rse.core.model.IHost; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.yocto.sdk.remotetools.views.BaseFileView; + +public class PowertopModel extends BaseModel { + + private static final String REMOTE_EXEC = "/tmp/yocto_tool.sh"; + private static final String LOCAL_SCRIPT = "resources/yocto_tool.sh"; + + private static final String REMOTE_FILE_PREFIX = "/tmp/yocto-powertop-"; + private static final String LOCAL_FILE_SUFFIX = ".local"; + + private static final String TASK_NAME = "powertop command"; + + private Float time; + private boolean showpid; + Display display; + + public PowertopModel(IHost host, Float time,boolean showpid,Display display) { + super(host, TASK_NAME, LOCAL_SCRIPT, REMOTE_EXEC); + this.time=time; + this.showpid=showpid; + this.display=display; + } + + @Override + public void postProcess(IProgressMonitor monitor) + throws InvocationTargetException, InterruptedException { + try { + new File(localFile).delete(); + }catch (Exception e) { + + } + } + + private void generateData(IProgressMonitor monitor) throws Exception { + String currentDate = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(Calendar.getInstance().getTime()).toString(); + remoteFile = new String(REMOTE_FILE_PREFIX + currentDate); + localFile = new String(remoteFile + LOCAL_FILE_SUFFIX); + + String args = "start -l " + remoteFile + " powertop --debug --time " + time.toString(); + if(showpid) + args += " -p"; + runRemoteShellExec(monitor, args, true); + } + + @Override + public void process(IProgressMonitor monitor) + throws InvocationTargetException, InterruptedException { + + monitor.beginTask("Running powertop", 100); + try { + //running powertop + monitor.subTask("Generating powertop data file remotely"); + generateData(new SubProgressMonitor(monitor,30)); + //download datafile + monitor.subTask("Downloading powertop data file"); + getDataFile(new SubProgressMonitor(monitor,30)); + //show it in the powertop view + display.syncExec(new Runnable() { + public void run() { + BaseFileView view; + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + try { + view=(BaseFileView) page.showView("org.yocto.sdk.remotetools.views.PowerTopView"); + }catch (PartInitException e) { + e.printStackTrace(); + return; + } + view.setInput(localFile); + page.bringToTop(view); + } + }); + + }catch (InterruptedException e){ + throw e; + }catch (InvocationTargetException e) { + throw e; + }catch (Exception e){ + throw new InvocationTargetException(e, e.getMessage()); + }finally { + monitor.done(); + } + + } + +} diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopSettingDialog.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopSettingDialog.java new file mode 100644 index 0000000..bb41a4a --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopSettingDialog.java @@ -0,0 +1,131 @@ +/******************************************************************************* + * Copyright (c) 2010 Intel Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel - initial API and implementation + *******************************************************************************/ +package org.yocto.sdk.remotetools.actions; + +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.yocto.sdk.remotetools.Activator; +import org.yocto.sdk.remotetools.Messages; +import org.yocto.sdk.remotetools.SWTFactory; + +public class PowertopSettingDialog extends BaseSettingDialog { + + static protected String TITLE="Powertop"; + + protected boolean showPid=false; + protected Float time; + protected Button showPidButton; + protected Text timeText; + + protected PowertopSettingDialog(Shell parentShell, String title, String conn) { + super(parentShell,title,conn); + } + + public PowertopSettingDialog(Shell parentShell) { + this(parentShell, + TITLE, + Activator.getDefault().getDialogSettings().get(IBaseConstants.CONNECTION_NAME_POWERTOP) + ); + } + + public boolean getShowPid() { + return showPid; + } + + public Float getTime() { + return time; + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite comp=(Composite)super.createDialogArea(parent); + GridLayout topLayout = new GridLayout(); + comp.setLayout(topLayout); + + /*argument*/ + SWTFactory.createVerticalSpacer(comp, 1); + createInternal(comp); + + updateOkButton(); + return comp; + } + + protected void createInternal(Composite parent) + { + Composite projComp = new Composite(parent, SWT.NONE); + GridLayout projLayout = new GridLayout(); + projLayout.numColumns = 4; + projLayout.marginHeight = 0; + projLayout.marginWidth = 0; + projComp.setLayout(projLayout); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + projComp.setLayoutData(gd); + + Label label = new Label(projComp, SWT.NONE); + label.setText(Messages.Powertop_Time_Text); + gd = new GridData(); + gd.horizontalSpan = 1; + label.setLayoutData(gd); + + timeText = new Text(projComp, SWT.SINGLE | SWT.BORDER); + timeText.setText("5"); + timeText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + updateOkButton(); + } + }); + gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 3; + timeText.setLayoutData(gd); + } + + @Override + protected boolean updateOkButton() { + boolean ret=super.updateOkButton(); + if(ret==true) { + try { + Float.valueOf(timeText.getText()); + }catch (Exception e) { + Button button=getButton(IDialogConstants.OK_ID); + if(button!=null) + button.setEnabled(false); + ret=false; + } + } + return ret; + } + + @Override + protected void okPressed() { + IDialogSettings settings = Activator.getDefault().getDialogSettings(); + // store the value of the generate sections checkbox + if(getCurrentConnection()==null) { + settings.put(IBaseConstants.CONNECTION_NAME_POWERTOP, + (String)null); + }else { + settings.put(IBaseConstants.CONNECTION_NAME_POWERTOP, + getCurrentConnection().getAliasName()); + } + time=new Float(timeText.getText()); + super.okPressed(); + } +} diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SimpleSettingDialog.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SimpleSettingDialog.java new file mode 100644 index 0000000..140d892 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SimpleSettingDialog.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2010 Intel Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel - initial API and implementation + *******************************************************************************/ +package org.yocto.sdk.remotetools.actions; + +import org.yocto.sdk.remotetools.Activator; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; + +public class SimpleSettingDialog extends BaseSettingDialog { + + private final String connPropName; + /* + protected SimpleSettingDialog(Shell parentShell, String title, String conn) { + super(parentShell,title,conn); + } + */ + + public SimpleSettingDialog(Shell parentShell, String title, String connPropertyName) { + super(parentShell, + title, + Activator.getDefault().getDialogSettings().get(connPropertyName) + ); + connPropName=connPropertyName; + } + + @Override + protected Control createDialogArea(Composite parent) { + return super.createDialogArea(parent); + } + + @Override + protected void okPressed() { + IDialogSettings settings = Activator.getDefault().getDialogSettings(); + // store the value of the generate sections checkbox + if(getCurrentConnection()==null) { + settings.put(connPropName, + (String)null); + }else { + settings.put(connPropName, + getCurrentConnection().getAliasName()); + } + super.okPressed(); + } +} diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapHandler.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapHandler.java new file mode 100644 index 0000000..f5d34d8 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapHandler.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2011 Intel Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel - initial API and implementation + *******************************************************************************/ +package org.yocto.sdk.remotetools.actions; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.progress.IProgressService; + +public class SystemtapHandler extends AbstractHandler { + protected SystemtapSettingDialog setting; + protected String changeTerm="export TERM=vt100;"; + protected IWorkbenchWindow window; + protected Shell shell; + + public Object execute(ExecutionEvent event) throws ExecutionException { + + this.window = HandlerUtil.getActiveWorkbenchWindowChecked(event); + shell = window.getShell(); + setting=new SystemtapSettingDialog( + shell, "Systemtap" + ); + + + if(setting.open() == BaseSettingDialog.OK) { + + String metadata_location = ((SystemtapSettingDialog)setting).getMetadataLocation(); + String builddir_location = ((SystemtapSettingDialog)setting).getBuilddirLocation(); + String remote_host = ((SystemtapSettingDialog)setting).getRemoteHost(); + String user_id = ((SystemtapSettingDialog)setting).getUserID(); + String systemtap_script = ((SystemtapSettingDialog)setting).getSystemtapScript(); + String systemtap_args = ((SystemtapSettingDialog)setting).getSystemtapArgs(); + IProgressService progressService = PlatformUI.getWorkbench().getProgressService(); + SystemtapModel op = new SystemtapModel(metadata_location, builddir_location, remote_host, user_id, systemtap_script, + systemtap_args,window.getShell().getDisplay()); + try { + progressService.busyCursorWhile(op); + }catch (InterruptedException e) { + //user cancelled + }catch (Exception e) { + e.printStackTrace(); + MessageDialog.openError(window.getShell(), + "Systemtap", + e.getMessage()); + } + } + return false; + } + + protected void initialize(ExecutionEvent event) throws ExecutionException { + this.window = HandlerUtil.getActiveWorkbenchWindowChecked(event); + shell = window.getShell(); + setting=new SystemtapSettingDialog( + shell, "Systemtap" + ); + } + +} diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapModel.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapModel.java new file mode 100644 index 0000000..bb2fa2d --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapModel.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2010 Intel Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel - initial API and implementation + *******************************************************************************/ +package org.yocto.sdk.remotetools.actions; + +import java.io.File; +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.IConsoleManager; +import org.eclipse.ui.console.MessageConsole; +import org.yocto.remote.utils.ShellSession; + +public class SystemtapModel extends BaseModel { + protected static final String DEFAULT_INIT_SCRIPT = "oe-init-build-env"; + protected static final String SYSTEMTAP_CONSOLE = "Systemtap Console"; + + private static final String TASK_NAME = "systemtap command"; + + protected MessageConsole sessionConsole; + private String metadata_location; + private String builddir_location; + private String remote_host; + private String user_id; + private String systemtap_script; + private String systemtap_args; + + Display display; + + public SystemtapModel(String metadata_location, String builddir_location, String remote_host, String user_id, String systemtap_script, String systemtap_args, Display display) { + super(null, TASK_NAME, "", ""); + this.metadata_location = metadata_location; + this.builddir_location = builddir_location; + this.remote_host = remote_host; + this.user_id = user_id; + this.systemtap_script = systemtap_script; + this.systemtap_args = systemtap_args; + this.display = display; + if (sessionConsole == null) { + IConsoleManager conMan = ConsolePlugin.getDefault().getConsoleManager(); + IConsole[] existing = conMan.getConsoles(); + for (int i = 0; i < existing.length; i++) + if (SYSTEMTAP_CONSOLE.equals(existing[i].getName())) { + sessionConsole = (MessageConsole) existing[i]; + break; + } + if (sessionConsole == null) { + sessionConsole = new MessageConsole(SYSTEMTAP_CONSOLE, null); + conMan.addConsoles(new IConsole[] { sessionConsole }); + } + } + + ConsolePlugin.getDefault().getConsoleManager().showConsoleView(sessionConsole); + } + + @Override + public void preProcess(IProgressMonitor monitor) + throws InvocationTargetException, InterruptedException {} + + @Override + public void process(IProgressMonitor monitor) + throws InvocationTargetException, InterruptedException { + try { + ShellSession shell = new ShellSession(ShellSession.SHELL_TYPE_BASH, + new File(this.metadata_location), new File(this.builddir_location), + DEFAULT_INIT_SCRIPT, sessionConsole.newOutputStream()); + boolean acceptedKey = shell.ensureKnownHostKey(user_id, remote_host); + if (acceptedKey) { + String crosstapCmd = "crosstap " + user_id + "@" + remote_host + " " + systemtap_script; + if (systemtap_args != null) + crosstapCmd = crosstapCmd + " " + systemtap_args; + shell.execute(crosstapCmd); + } + } catch (Exception e) { + throw new InvocationTargetException(e,e.getMessage()); + } + } +} diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapSettingDialog.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapSettingDialog.java new file mode 100644 index 0000000..760715c --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapSettingDialog.java @@ -0,0 +1,280 @@ +/******************************************************************************* + * Copyright (c) 2010 Intel Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel - initial API and implementation + *******************************************************************************/ +package org.yocto.sdk.remotetools.actions; + +import java.io.File; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.yocto.remote.utils.CommonHelper; +import org.yocto.sdk.remotetools.Activator; +import org.yocto.sdk.remotetools.Messages; +import org.yocto.sdk.remotetools.SWTFactory; + +public class SystemtapSettingDialog extends Dialog { + + static protected String TITLE="Systemtap Crosstap"; + protected String title; + protected String metadata_location; + protected String builddir_location; + protected String systemtap_script; + protected String user_id; + protected String remote_host; + protected String systemtap_args; + protected boolean okPressed; + protected Button metadataLocationBtn; + protected Button builddirLocationBtn; + protected Button systemtapScriptBtn; + protected Text userIDText; + protected Text remoteHostText; + protected Text systemtapArgsText; + protected Text systemtapScriptText; + protected Text metadataLocationText; + protected Text builddirLocationText; + + protected SystemtapSettingDialog(Shell parentShell, String title) { + super(parentShell); + this.title = title; + this.okPressed = false; + setShellStyle(getShellStyle() | SWT.RESIZE); + } + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText(title); + } + + public boolean isOKPressed() { + return okPressed; + } + + public String getSystemtapScript() { + return systemtap_script; + } + + public String getMetadataLocation() { + return metadata_location; + } + + public String getBuilddirLocation() { + return builddir_location; + } + + public String getRemoteHost() { + return remote_host; + } + + public String getUserID() { + return user_id; + } + + public String getSystemtapArgs() { + return systemtap_args; + } + @Override + protected Control createDialogArea(Composite parent) { + Composite comp=(Composite)super.createDialogArea(parent); + GridLayout topLayout = new GridLayout(); + comp.setLayout(topLayout); + + /*argument*/ + SWTFactory.createVerticalSpacer(comp, 1); + createInternal(comp); + + return comp; + } + + protected void createInternal(Composite parent) + { + Composite projComp = new Composite(parent, SWT.NONE); + GridLayout projLayout = new GridLayout(); + projLayout.numColumns = 2; + projLayout.marginHeight = 0; + projLayout.marginWidth = 0; + projComp.setLayout(projLayout); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + projComp.setLayoutData(gd); + + Label label = new Label(projComp, SWT.NONE); + label.setText(Messages.Metadata_Location); + Composite textContainer = new Composite(projComp, SWT.NONE); + textContainer.setLayout(new GridLayout(2, false)); + textContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + metadataLocationText = (Text)addTextControl(textContainer, metadata_location); + metadataLocationBtn = addDirSelectButton(textContainer, metadataLocationText); + + label = new Label(projComp, SWT.NONE); + label.setText(Messages.Builddir_Location); + textContainer = new Composite(projComp, SWT.NONE); + textContainer.setLayout(new GridLayout(2, false)); + textContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + builddirLocationText = (Text)addTextControl(textContainer, builddir_location); + builddirLocationBtn = addDirSelectButton(textContainer, builddirLocationText); + + label = new Label(projComp, SWT.NONE); + label.setText(Messages.User_ID); + userIDText = new Text(projComp, SWT.SINGLE | SWT.BORDER); + + if(user_id!=null) + userIDText.setText(user_id); + gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 1; + userIDText.setLayoutData(gd); + + label = new Label(projComp, SWT.NONE); + label.setText(Messages.Remote_Host); + + remoteHostText = new Text(projComp, SWT.SINGLE | SWT.BORDER); + if(remote_host != null) + remoteHostText.setText(remote_host); + gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 1; + remoteHostText.setLayoutData(gd); + + label = new Label(projComp, SWT.NONE); + label.setText(Messages.Systemtap_Script); + textContainer = new Composite(projComp, SWT.NONE); + textContainer.setLayout(new GridLayout(2, false)); + textContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + systemtapScriptText = (Text)addTextControl(textContainer, systemtap_script); + systemtapScriptBtn = addFileSelectButton(textContainer, systemtapScriptText); + + label = new Label(projComp, SWT.NONE); + label.setText(Messages.Systemtap_Args); + + systemtapArgsText = new Text(projComp, SWT.SINGLE | SWT.BORDER); + if(systemtap_args != null) + systemtapArgsText.setText(systemtap_args); + gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 1; + systemtapArgsText.setLayoutData(gd); + } + + private Control addTextControl(final Composite parent, String value) { + final Text text; + + text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.BORDER); + text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + if (value != null) + text.setText(value); + text.setSize(10, 150); + return (Control)text; + } + + private Button addDirSelectButton(final Composite parent, final Text text) { + Button button = new Button(parent, SWT.PUSH | SWT.LEAD); + button.setText("Browse"); + button.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent event) { + String dirName; + + dirName = new DirectoryDialog(parent.getShell()).open(); + if (dirName != null) { + text.setText(dirName); + } + } + }); + return button; + } + + private Button addFileSelectButton(final Composite parent, final Text text) { + Button button = new Button(parent, SWT.PUSH | SWT.LEAD); + button.setText("Browse"); + button.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent event) { + String fileName; + + fileName = new FileDialog(parent.getShell()).open(); + if (fileName != null) { + text.setText(fileName); + } + } + }); + return button; + } + + @Override + protected void okPressed() { + IDialogSettings settings = Activator.getDefault().getDialogSettings(); + metadata_location = metadataLocationText.getText(); + if ( (metadata_location == null) || metadata_location.isEmpty()) { + CommonHelper.showErrorDialog("SystemTap Error", null, "Please specify your metadata location!"); + return; + } + File metadata_dir = new File(metadata_location); + if (!metadata_dir.exists()) { + CommonHelper.showErrorDialog("SystemTap Error", null, "The specified metadata location does not exist!"); + return; + } + if (!metadata_dir.isDirectory()) { + CommonHelper.showErrorDialog("SystemTap Error", null, "The specified metadata location is not a directory!"); + return; + } + builddir_location = builddirLocationText.getText(); + if ( (builddir_location == null) || builddir_location.isEmpty()) { + CommonHelper.showErrorDialog("SystemTap Error", null, "Please specify your builddir location!"); + return; + } + File builddir_dir = new File(builddir_location); + if (!builddir_dir.exists()) { + CommonHelper.showErrorDialog("SystemTap Error", null, "The specified builddir location does not exist!"); + } + if (!metadata_dir.isDirectory()) { + CommonHelper.showErrorDialog("SystemTap Error", null, "The specified builddir location is not a directory!"); + return; + } + user_id = userIDText.getText(); + if ( (user_id == null) || user_id.isEmpty()) { + CommonHelper.showErrorDialog("SystemTap Error", null, "Please specify remote user id!"); + return; + } + + remote_host = remoteHostText.getText(); + if ( (remote_host == null) || remote_host.isEmpty()) { + CommonHelper.showErrorDialog("SystemTap Error", null, "Please specify remote host IP!"); + return; + } + + systemtap_script = systemtapScriptText.getText(); + if ( (systemtap_script == null) || systemtap_script.isEmpty()) { + CommonHelper.showErrorDialog("SystemTap Error", null, "Please specify your systemtap script"); + return; + } + File script_file = new File(systemtap_script); + if (!script_file.exists()) { + CommonHelper.showErrorDialog("SystemTap Error", null, "The specified systemtap script does not exist!"); + return; + } + if (!script_file.isFile()) { + CommonHelper.showErrorDialog("SystemTap Error", null, "The specified systemtap script is not a file!"); + return; + } + systemtap_args = systemtapArgsText.getText(); + okPressed = true; + super.okPressed(); + } +} diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2Handler.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2Handler.java new file mode 100644 index 0000000..9e18097 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2Handler.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2010 Intel Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel - initial API and implementation + *******************************************************************************/ +package org.yocto.sdk.remotetools.actions; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.progress.IProgressService; + +import org.yocto.sdk.remotetools.Messages; + +public class Ust2Handler extends AbstractHandler { + + public Object execute(ExecutionEvent event) throws ExecutionException { + + //if(UstModel.checkAvail()!=true) { + // return null; + //} + + IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); + + Ust2SettingDialog setting=new Ust2SettingDialog( + window.getShell() + ); + + if(setting.open()==BaseSettingDialog.OK) { + IProgressService progressService = PlatformUI.getWorkbench().getProgressService(); + String project = setting.getProject(); + if (project == null) { + MessageDialog.openError(window.getShell(), "Lttng-ust", Messages.ErrorUstProject); + return null; + } + Ust2Model op=new Ust2Model(setting.getHost(),setting.getTrace(), project, window); + try { + progressService.busyCursorWhile(op); + }catch (InterruptedException e) { + //user cancelled + }catch (Exception e) { + e.printStackTrace(); + MessageDialog.openError(window.getShell(), + "Ust", + (e.getCause() != null) ? e.getCause().getMessage() : e.getMessage()); + } + } + return null; + } +} diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2Model.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2Model.java new file mode 100644 index 0000000..8dcc5b3 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2Model.java @@ -0,0 +1,166 @@ +/******************************************************************************* + * Copyright (c) 2010 Intel Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel - initial API and implementation + *******************************************************************************/ +package org.yocto.sdk.remotetools.actions; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.rse.core.model.IHost; +import org.eclipse.ui.IWorkbenchWindow; + +public class Ust2Model extends BaseModel { + + private static final String REMOTE_EXEC = "/tmp/ust_tar.sh"; + private static final String LOCAL_SCRIPT = "resources/ust_tar.sh"; + + private static final String LOCAL_FILE_SUFFIX = ".local.tar"; + private static final String REMOTE_FILE_SUFFIX = ".tar"; + private static final String LOCAL_EXEC = "lttv-gui"; + private static final String TRACE_FOLDER_NAME = "Traces"; + private static final String DATAFILE_PREFIX = "ustfile:"; + + private static final String TASK_NAME = "ust2trace command"; + + private String trace_loc; + + private String prj_name; + + private IWorkbenchWindow window; + + public Ust2Model(IHost host, String trace, String project, IWorkbenchWindow window) { + super(host, TASK_NAME, LOCAL_SCRIPT, REMOTE_EXEC); + trace_loc = trace; + + prj_name = project; + this.window = window; + } + + @Override + protected void checkTerminate(InputStream is) throws IOException { + String temp; + BufferedReader in = new BufferedReader(new InputStreamReader(is)); + while((temp = in.readLine())!=null) { + int idx = temp.indexOf(DATAFILE_PREFIX); + if(idx != -1) { + remoteFile = temp.substring(idx + DATAFILE_PREFIX.length()); + break; + } + } + } + + private void generateData(IProgressMonitor monitor) throws Exception { + runRemoteShellExec(monitor, trace_loc, true); + if(remoteFile == null) + throw new Exception("Ust: null remote data file"); + if(remoteFile.endsWith(REMOTE_FILE_SUFFIX)==false) + throw new Exception("Wrong ust data file " + remoteFile); + + localFile = new String(remoteFile.substring(0, remoteFile.length()-4) + LOCAL_FILE_SUFFIX); + } + + private void importToProject(IProgressMonitor monitor) throws Exception { + ProcessBuilder pb = new ProcessBuilder("tar", "fx", localFile); + pb.directory(new File("/tmp")); + Process p=pb.start(); + if(p.waitFor()!=0) + throw new Exception("extract ust data files failed"); + + String traceName = localFile.substring(0,localFile.length()-LOCAL_FILE_SUFFIX.length()); + + IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot(); + IPath full_path = wsroot.getFullPath(); + IProject project = wsroot.getProject(prj_name); + IFolder traceFolder = project.getFolder(TRACE_FOLDER_NAME); + if (!traceFolder.exists()) { + throw new Exception("Can't find file trace folder in selected project."); + } + + String trace_str = traceName.substring(0, traceName.indexOf('-')); + traceFolder.createLink(new Path(trace_str), IResource.REPLACE, monitor); + for (IResource resource:traceFolder.members()) { + String extension = resource.getFileExtension(); + if (extension != null) + continue; + else { + //traceFolder.setPersistentProperty(TmfCommonConstants.TRACETYPE, "org.eclipse.linuxtools.tmf.ui.type.ctf"); + //resource.setPersistentProperty(TmfCommonConstants.TRACETYPE, "org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace"); + //traceFolder.setPersistentProperty(TmfCommonConstants.TRACEICON, "icons/obj16/garland16.png"); + //traceFolder.touch(null); + } + } + } + + private String[] generateViewerParam() throws Exception { + String viewerParam=new String(LOCAL_EXEC); + int i; + + ProcessBuilder pb = new ProcessBuilder("tar", "fx", localFile); + pb.directory(new File("/tmp")); + Process p=pb.start(); + if(p.waitFor()!=0) + throw new Exception("extract ust data files failed"); + File f=new File(localFile.substring(0,localFile.length()-LOCAL_FILE_SUFFIX.length())); + File []subdir=f.listFiles(); + + for (i=0;i= 0 ? projectCombo + .getItem(currentSelection) : null; + IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot(); + IProject project = wsroot.getProject(importProject); + return project; + } + + protected void updateProjectPulldown() { + int index=-1; + + projectCombo.removeAll(); + IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot(); + IProject[] projects = wsroot.getProjects(); + + for (int i = 0; i < projects.length; ++i) { + try { + if (projects[i].isOpen() && projects[i].hasNature(TmfProjectNature.ID)) { + String projName = projects[i].getName(); + projectCombo.add(projName); + if (curProject != null) + if (projName.matches(curProject)) + index = i; + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + if(index>=0) { + projectCombo.select(index); + }else if (projectCombo.getItemCount()> 0) { + projectCombo.select(projectCombo.getItemCount() - 1); + } + + //TODO + //connectionCombo.computeSize(SWT.DEFAULT, SWT.DEFAULT,true); + projectCombo.pack(true); + projectCombo.layout(); + projectCombo.getParent().layout(); + + updateCurProject(); + } + protected void createArgument(Composite parent) + { + } + + @Override + protected boolean updateOkButton() { + boolean ret=super.updateOkButton(); + return ret; + } +} diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/YoctoBspHandler.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/YoctoBspHandler.java new file mode 100644 index 0000000..c97afb6 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/YoctoBspHandler.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2010 Intel Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel - initial API and implementation + *******************************************************************************/ +package org.yocto.sdk.remotetools.actions; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.handlers.HandlerUtil; + +import org.yocto.sdk.remotetools.wizards.bsp.YoctoBSPWizard; + +public class YoctoBspHandler extends AbstractHandler { + + public Object execute(ExecutionEvent event) throws ExecutionException { + + IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); + // Instantiates and initializes the wizard + YoctoBSPWizard bspWizard = new YoctoBSPWizard(); + //bspWizard.init(window.getWorkbench(), (IStructuredSelection)selection); + // Instantiates the wizard container with the wizard and opens it + WizardDialog dialog = new WizardDialog(window.getShell(), bspWizard); + //dialog.create(); + dialog.open(); + //YoctoBspDialog setting=new YoctoBspDialog(window.getShell()); + //setting.open(); + return null; + } +} -- cgit v1.2.3-54-g00ecf