Refactoring of remotetools plugin
v2 cover Refactoring of remotetools plugin
- refactor all remote tools plugin to have single points of control for remote utilities plugin
- remove all duplicate code
Ioana Grigoropol (8):
Remove UstLegacyModel since it is no longer supported Refactor Model(s) to display customized messages
Unify preProcess for all commands models
Add default behaviour for post-processing commands
Remove duplicate code when getting remote data from powertop and ust2 Refactor RemoteApplication implementation
Refactor powertop, oprofile and ust2 models to remove duplicate code Refactor Latencytop and Perf Handler to remove duplicate code
.../yocto/sdk/remotetools/actions/BaseModel.java | 115 +++++++--- .../sdk/remotetools/actions/IBaseConstants.java | 3 + .../sdk/remotetools/actions/LatencytopHandler.java | 22 +- .../sdk/remotetools/actions/OprofileModel.java | 81 ++----- .../yocto/sdk/remotetools/actions/PerfHandler.java | 22 +- .../sdk/remotetools/actions/PowertopModel.java | 90 ++------ .../sdk/remotetools/actions/SystemtapModel.java | 34 ++- .../sdk/remotetools/actions/TerminalHandler.java | 16 +- .../yocto/sdk/remotetools/actions/Ust2Model.java | 132 +++-------- .../sdk/remotetools/actions/UstModelLegacy.java | 238 -------------------- .../sdk/remotetools/remote/RemoteApplication.java | 155 ------------- .../sdk/remotetools/remote/RemoteShellExec.java | 149 ++++++++++++ 12 files changed, 348 insertions(+), 709 deletions(-) delete mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/UstModelLegacy.java delete mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/remote/RemoteApplication.java create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/remote/RemoteShellExec.java
Signature · 1 line
1.7.9.5
PATCH v2 1/8 Remove UstLegacyModel since it is no longer supported
- lttng legacy support was dropped but the model remained behind and it should not be maintained anymore
--- .../sdk/remotetools/actions/UstModelLegacy.java | 238 -------------------- 1 file changed, 238 deletions(-) delete mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/UstModelLegacy.java
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/UstModelLegacy.java deleted +0 -238
@@ -1,238 +0,0 @@ -/******************************************************************************* - * 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.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.IProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.core.runtime.IPath; -import org.eclipse.rse.core.model.IHost; -import org.eclipse.ui.IWorkbenchWindow; - -import org.yocto.sdk.remotetools.CommonHelper; -import org.yocto.sdk.remotetools.Messages; -import org.yocto.sdk.remotetools.RSEHelper; -import org.yocto.sdk.remotetools.remote.RemoteApplication; - -public class UstModelLegacy extends BaseModel { - - static final private String REMOTE_EXEC="/tmp/yocto_ust.sh"; - static final private String LOCAL_SCRIPT="resources/yocto_ust.sh"; - - static final private String LOCAL_FILE_SUFFIX=".local.tar"; - static final private String REMOTE_FILE_SUFFIX=".tar"; - static final private String LOCAL_EXEC="lttv-gui"; - public static final String TRACE_FOLDER_NAME = "Traces"; - static final private String DATAFILE_PREFIX = "ustfile:"; - - private String argument; - private String application; - private String prj_name; - - private String localfile; - - private IWorkbenchWindow window; - - public UstModelLegacy(IHost host, String app,String arg, String project, IWorkbenchWindow window) { - super(host); - application=app; - argument=arg; - prj_name = project; - this.window=window; - } - - @Override - public void preProcess(IProgressMonitor monitor) - throws InvocationTargetException, InterruptedException { - ///upload script to remote - try { - RSEHelper.putRemoteFileInPlugin( - rseConnection, - LOCAL_SCRIPT, - REMOTE_EXEC, - monitor); - }catch (InterruptedException e){ - throw e; - }catch (InvocationTargetException e) { - throw e; - }catch (Exception e) { - throw new InvocationTargetException(e,e.getMessage()); - } - - } - - @Override - public void postProcess(IProgressMonitor monitor) - throws InvocationTargetException, InterruptedException { - try { - new File(localfile).delete(); - //NOT delete the directory since lttv-gui is running asynchronously - //new File(localfile.substring(0,localfile.length()-LOCAL_FILE_SUFFIX.length())).delete(); - }catch (Exception e) { - - } - } - - private String generateData(IProgressMonitor monitor) throws Exception { - int exit_code; - RemoteApplication app=new RemoteApplication(rseConnection,null,REMOTE_EXEC,null); - String tempArgs=new String(); - if(application!=null) - tempArgs=tempArgs.concat(application + " "); - if(argument!=null) - tempArgs=tempArgs.concat(argument); - String remoteDataFile=null; - - try { - String temp; - int idx; - monitor.beginTask("Starting usttrace", 2); - //starting usttrace - app.start(null,tempArgs,monitor); - monitor.worked(1); - BufferedReader in=new BufferedReader(new InputStreamReader(app.getInputStream())); - while((temp=in.readLine())!=null) { - idx=temp.indexOf(DATAFILE_PREFIX); - if(idx!=-1) { - remoteDataFile=temp.substring(idx + DATAFILE_PREFIX.length()); - break; - } - } - exit_code=app.waitFor(monitor); - app.terminate(); - if(exit_code!=0) { - throw new Exception("Starting usttrace failed with exit code " + new Integer(exit_code).toString()); - } - }finally { - monitor.done(); - } - if(remoteDataFile==null) - throw new Exception("Ust: null remote data file"); - return remoteDataFile; - } - - private void getDataFile(IProgressMonitor monitor,String datafile) throws Exception { - - if(datafile.endsWith(REMOTE_FILE_SUFFIX)==false) - throw new Exception("Wrong ust data file "+datafile); - - localfile=new String(datafile.substring(0,datafile.length()-4) + LOCAL_FILE_SUFFIX); - - RSEHelper.getRemoteFile( - rseConnection, - localfile, - datafile, - monitor); - } - - 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."); - } - - traceFolder.createLink(new Path(traceName), IResource.REPLACE, monitor); - } - - 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<subdir.length;i++) { - if(subdir[i].isDirectory()) { - viewerParam=viewerParam.concat(" -t " + subdir[i].getAbsolutePath()); - } - } - - return viewerParam.split(" "); - } - - @Override - public void process(IProgressMonitor monitor) - throws InvocationTargetException, InterruptedException { - // TODO Auto-generated method stub - - String datafile; - - monitor.beginTask("Running ust", 100); - try { - //running usttrace - monitor.subTask("Generating user space lttng data file remotely"); - datafile=generateData(new SubProgressMonitor(monitor,30)); - - //download datafile to local - monitor.subTask("Downloading user space lttng data file"); - getDataFile(new SubProgressMonitor(monitor,30),datafile); - - //extract datafile and import to lttng project - importToProject(new SubProgressMonitor(monitor,30)); - //extract datafile, prepare cmd array - /* JZ - we're using Eclipse built-in Lttng-viewer now - String []cmdarray=generateViewerParam(); - if(cmdarray==null) { - throw new Exception("Ust: empty ust data"); - } - monitor.worked(30); - - monitor.subTask("lttv-gui is running locally"); - //start lttv-gui asynchronously - new LocalJob("lttv-gui",cmdarray,null,null,window).schedule(); - */ - }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("User Mode Lttng", null,Messages.ErrorLttvGui); - } - return ret; - } - -}
Signature · 1 line
1.7.9.5
PATCH v2 2/8 Refactor Model(s) to display customized messages
In reply to Ioana Grigoropol- each of the remote tools models (systemtap, oprofile, powertop, ust2, ustlegacy) inherits BaseModel class
- when running any of these models there are a series of actions performed such as:
- init
- pre-process
- process
- post-process
- clean
- while the action is running, a progress monitor is displayed showing no message and no progress update
- in order to set an appropriate message for the monitor, define a taskName at the parent level that will be customized by each of the models
- each time the action performed changes, the monitor's subtask message should be updated accordingly
--- .../yocto/sdk/remotetools/actions/BaseModel.java | 70 ++++++++++++-------- .../sdk/remotetools/actions/OprofileModel.java | 15 +++-- .../sdk/remotetools/actions/PowertopModel.java | 13 ++-- .../sdk/remotetools/actions/SystemtapModel.java | 7 +- .../yocto/sdk/remotetools/actions/Ust2Model.java | 10 +-- 5 files changed, 70 insertions(+), 45 deletions(-)
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseModel.java +42 -28
@@ -18,49 +18,63 @@ import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.rse.core.model.IHost; abstract public class BaseModel implements IRunnableWithProgress { - - protected IHost rseConnection; + protected IHost host; + protected String taskName; + + 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 = "..."; abstract public void preProcess(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException; abstract public void postProcess(IProgressMonitor monitor) throws InvocationTargetException,InterruptedException; abstract public void process(IProgressMonitor monitor) throws InvocationTargetException,InterruptedException; - public BaseModel(IHost rseConnection) { - this.rseConnection=rseConnection; + public BaseModel(IHost host, String taskName) { + this.host = host; + this.taskName = taskName; } - protected void init(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - /* - if(rseConnection==null) { - throw new InvocationTargetException(new Exception("NULL rse connection"),"NULL rse connection"); - }*/ } - protected void uninit(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - + protected void clean(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { } - + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { - monitor.beginTask("", 100); - init(new SubProgressMonitor(monitor,5)); - if(monitor.isCanceled()) - throw new InterruptedException("User canncelled"); - preProcess(new SubProgressMonitor(monitor,30)); - if(monitor.isCanceled()) - throw new InterruptedException("User canncelled"); - process(new SubProgressMonitor(monitor,30)); - if(monitor.isCanceled()) - throw new InterruptedException("User canncelled"); - postProcess(new SubProgressMonitor(monitor,30)); - }catch (InterruptedException e){ - throw e; - }catch (InvocationTargetException e) { + 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 { - uninit(new SubProgressMonitor(monitor,5)); + } finally { + monitor.subTask(CLEAN_MSG + taskName + DOTS); + clean(new SubProgressMonitor(monitor, CLEAN_PERCENT)); monitor.done(); } }
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/OprofileModel.java +9 -6
@@ -36,18 +36,21 @@ public class OprofileModel extends BaseModel { static final private String LOCAL_SCRIPT="resources/yocto_tool.sh"; static final private String LOCAL_EXEC="oprofile-viewer"; + private static final String TASK_NAME = "oprofile command"; + private IWorkbenchWindow window; public OprofileModel(IHost host, IWorkbenchWindow window) { - super(host); + super(host, TASK_NAME); this.window=window; } + @Override public void preProcess(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { //upload script to remote try { RSEHelper.putRemoteFileInPlugin( - rseConnection, + host, LOCAL_SCRIPT, REMOTE_EXEC, monitor);
@@ -68,7 +71,7 @@ public class OprofileModel extends BaseModel { private void startServer(IProgressMonitor monitor) throws Exception { int exit_code; - RemoteApplication app=new RemoteApplication(rseConnection,null,REMOTE_EXEC,null); + RemoteApplication app=new RemoteApplication(host,null,REMOTE_EXEC,null); String args="start -d oprofile-server"; try {
@@ -89,7 +92,7 @@ public class OprofileModel extends BaseModel { private void stopServer(IProgressMonitor monitor) throws Exception { - RemoteApplication app=new RemoteApplication(rseConnection,null,REMOTE_EXEC,null); + RemoteApplication app=new RemoteApplication(host,null,REMOTE_EXEC,null); String args="stop -d oprofile-server"; try { monitor.beginTask("Stopping oprofile-server", 2);
@@ -177,8 +180,8 @@ public class OprofileModel extends BaseModel { new LocalJob("oprofile-viewer", (searchPath!=null) ? - new String[] {LOCAL_EXEC,"-h",rseConnection.getHostName(),"-s",searchPath} : - new String[] {LOCAL_EXEC,"-h",rseConnection.getHostName()}, + new String[] {LOCAL_EXEC,"-h",host.getHostName(),"-s",searchPath} : + new String[] {LOCAL_EXEC,"-h",host.getHostName()}, null, null, window).schedule();
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopModel.java +8 -5
@@ -33,15 +33,18 @@ public class PowertopModel extends BaseModel { final private String LOCAL_SCRIPT="resources/yocto_tool.sh"; final private String REMOTE_FILE_PREFIX="/tmp/yocto-powertop-"; final private String LOCAL_FILE_SUFFIX=".local"; + + private static final String TASK_NAME = "powertop command"; + private Float time; private boolean showpid; Display display; - + String localfile; String remotefile; public PowertopModel(IHost host, Float time,boolean showpid,Display display) { - super(host); + super(host, TASK_NAME); this.time=time; this.showpid=showpid; this.display=display;
@@ -53,7 +56,7 @@ public class PowertopModel extends BaseModel { //upload script to remote try { RSEHelper.putRemoteFileInPlugin( - rseConnection, + host, LOCAL_SCRIPT, REMOTE_EXEC, monitor);
@@ -79,7 +82,7 @@ public class PowertopModel extends BaseModel { private void generateData(IProgressMonitor monitor) throws Exception { int exit_code; - RemoteApplication app=new RemoteApplication(rseConnection,null,REMOTE_EXEC,null); + RemoteApplication app=new RemoteApplication(host,null,REMOTE_EXEC,null); String currentDate=new SimpleDateFormat("yyyyMMddHHmmssSSS").format(Calendar.getInstance().getTime()).toString(); remotefile=new String(REMOTE_FILE_PREFIX + currentDate); localfile=new String(remotefile + LOCAL_FILE_SUFFIX);
@@ -117,7 +120,7 @@ public class PowertopModel extends BaseModel { private void getDataFile(IProgressMonitor monitor) throws Exception { RSEHelper.getRemoteFile( - rseConnection, + host, localfile, remotefile, monitor);
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapModel.java +5 -2
@@ -24,17 +24,20 @@ import org.yocto.sdk.remotetools.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 remote_host; private String user_id; private String systemtap_script; private String systemtap_args; - + Display display; public SystemtapModel(String metadata_location, String remote_host, String user_id, String systemtap_script, String systemtap_args, Display display) { - super(null); + super(null, TASK_NAME); this.metadata_location=metadata_location; this.remote_host=remote_host; this.user_id=user_id;
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2Model.java +6 -4
@@ -40,6 +40,8 @@ public class Ust2Model extends BaseModel { static final private String LOCAL_EXEC="lttv-gui"; public static final String TRACE_FOLDER_NAME = "Traces"; static final private String DATAFILE_PREFIX = "ustfile:"; + + private static final String TASK_NAME = "ust2trace command"; private String trace_loc;
@@ -50,7 +52,7 @@ public class Ust2Model extends BaseModel { private IWorkbenchWindow window; public Ust2Model(IHost host, String trace, String project, IWorkbenchWindow window) { - super(host); + super(host, TASK_NAME); trace_loc=trace; prj_name = project;
@@ -63,7 +65,7 @@ public class Ust2Model extends BaseModel { ///upload script to remote try { RSEHelper.putRemoteFileInPlugin( - rseConnection, + host, LOCAL_SCRIPT, REMOTE_EXEC, monitor);
@@ -91,7 +93,7 @@ public class Ust2Model extends BaseModel { private String generateData(IProgressMonitor monitor) throws Exception { int exit_code; - RemoteApplication app=new RemoteApplication(rseConnection,null,REMOTE_EXEC,null); + RemoteApplication app=new RemoteApplication(host,null,REMOTE_EXEC,null); String remoteDataFile=null;
@@ -131,7 +133,7 @@ public class Ust2Model extends BaseModel { localfile=new String(datafile.substring(0,datafile.length()-4) + LOCAL_FILE_SUFFIX); RSEHelper.getRemoteFile( - rseConnection, + host, localfile, datafile, monitor);
Signature · 1 line
1.7.9.5
PATCH v2 3/8 Unify preProcess for all commands models
In reply to Ioana Grigoropol- all remote tools models(except systemtap) perform the same action in the pre-processing step duplicating the code
- move the default code for pre-processing step in the BaseModel
- move the local script path and the remote executable location variables that are needed for pre-processing in the BaseModel
- customize the variables in the constructor of each remote tool model
--- .../yocto/sdk/remotetools/actions/BaseModel.java | 20 ++++++++- .../sdk/remotetools/actions/OprofileModel.java | 44 +++++------------- .../sdk/remotetools/actions/PowertopModel.java | 39 +++++----------- .../sdk/remotetools/actions/SystemtapModel.java | 30 ++++++------- .../yocto/sdk/remotetools/actions/Ust2Model.java | 47 ++++++-------------- 5 files changed, 67 insertions(+), 113 deletions(-)
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseModel.java +18 -2
@@ -16,10 +16,13 @@ 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.sdk.remotetools.RSEHelper; abstract public class BaseModel implements IRunnableWithProgress { protected IHost host; protected String taskName; + protected String localScript; + protected String remoteExec; private static final int WORKLOAD = 100;
@@ -37,13 +40,26 @@ abstract public class BaseModel implements IRunnableWithProgress { private static final String CLEAN_MSG = "Cleaning "; private static final String DOTS = "..."; - abstract public void preProcess(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException; + 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()); + } + } abstract public void postProcess(IProgressMonitor monitor) throws InvocationTargetException,InterruptedException; abstract public void process(IProgressMonitor monitor) throws InvocationTargetException,InterruptedException; - public BaseModel(IHost host, String taskName) { + 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 { }
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/OprofileModel.java +12 -32
76 lines not on this page · raw message
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopModel.java +10 -29
@@ -29,10 +29,11 @@ import org.yocto.sdk.remotetools.views.BaseFileView; public class PowertopModel extends BaseModel { - final private String REMOTE_EXEC="/tmp/yocto_tool.sh"; - final private String LOCAL_SCRIPT="resources/yocto_tool.sh"; - final private String REMOTE_FILE_PREFIX="/tmp/yocto-powertop-"; - final private String LOCAL_FILE_SUFFIX=".local"; + 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";
@@ -44,31 +45,11 @@ public class PowertopModel extends BaseModel { String remotefile; public PowertopModel(IHost host, Float time,boolean showpid,Display display) { - super(host, TASK_NAME); + super(host, TASK_NAME, LOCAL_SCRIPT, REMOTE_EXEC); this.time=time; this.showpid=showpid; this.display=display; } - - @Override - public void preProcess(IProgressMonitor monitor) - throws InvocationTargetException, InterruptedException { - //upload script to remote - try { - RSEHelper.putRemoteFileInPlugin( - host, - LOCAL_SCRIPT, - REMOTE_EXEC, - monitor); - }catch (InterruptedException e){ - throw e; - }catch (InvocationTargetException e) { - throw e; - }catch (Exception e) { - throw new InvocationTargetException(e,e.getMessage()); - } - - } @Override public void postProcess(IProgressMonitor monitor)
@@ -82,13 +63,13 @@ public class PowertopModel extends BaseModel { private void generateData(IProgressMonitor monitor) throws Exception { int exit_code; - RemoteApplication app=new RemoteApplication(host,null,REMOTE_EXEC,null); + RemoteApplication app = new RemoteApplication(host, null, remoteExec, null); String currentDate=new SimpleDateFormat("yyyyMMddHHmmssSSS").format(Calendar.getInstance().getTime()).toString(); - remotefile=new String(REMOTE_FILE_PREFIX + currentDate); - localfile=new String(remotefile + LOCAL_FILE_SUFFIX); + remotefile = new String(REMOTE_FILE_PREFIX + currentDate); + localfile = new String(remotefile + LOCAL_FILE_SUFFIX); ArrayList <String> param= new ArrayList <String>(); - param.add(REMOTE_EXEC); + param.add(remoteExec); param.add("start"); param.add("-l"); param.add(remotefile);
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapModel.java +14 -16
@@ -37,13 +37,13 @@ public class SystemtapModel extends BaseModel { Display display; public SystemtapModel(String metadata_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.remote_host=remote_host; - this.user_id=user_id; - this.systemtap_script=systemtap_script; + super(null, TASK_NAME, "", ""); + this.metadata_location = metadata_location; + this.remote_host = remote_host; + this.user_id = user_id; + this.systemtap_script = systemtap_script; this.systemtap_args = systemtap_args; - this.display=display; + this.display = display; if (sessionConsole == null) { IConsoleManager conMan = ConsolePlugin.getDefault().getConsoleManager(); IConsole[] existing = conMan.getConsoles();
@@ -62,13 +62,12 @@ public class SystemtapModel extends BaseModel { } @Override - - public void preProcess(IProgressMonitor monitor) - throws InvocationTargetException, InterruptedException { - } + public void preProcess(IProgressMonitor monitor) + throws InvocationTargetException, InterruptedException {} - public void process(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),
@@ -85,9 +84,8 @@ public class SystemtapModel extends BaseModel { } } - - public void postProcess(IProgressMonitor monitor) - throws InvocationTargetException, InterruptedException { - } + @Override + public void postProcess(IProgressMonitor monitor) + throws InvocationTargetException, InterruptedException {} }
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2Model.java +13 -34
79 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v2 4/8 Add default behaviour for post-processing commands
In reply to Ioana Grigoropol- after processing the remote tool command, the post processing action is performed
- for most of the remote tools commands, this action doesn't actually do something (with two exceptions that perform some file cleanup)
- provide default empty behaviour for post-processing action in BaseModel and only perform clean-up for actions that need it
--- .../yocto/sdk/remotetools/actions/BaseModel.java | 3 ++- .../sdk/remotetools/actions/OprofileModel.java | 6 ------ .../sdk/remotetools/actions/SystemtapModel.java | 5 ----- .../yocto/sdk/remotetools/actions/Ust2Model.java | 12 ------------ 4 files changed, 2 insertions(+), 24 deletions(-)
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseModel.java +2 -1
@@ -52,7 +52,8 @@ abstract public class BaseModel implements IRunnableWithProgress { throw new InvocationTargetException(e, e.getMessage()); } } - abstract public void postProcess(IProgressMonitor monitor) throws InvocationTargetException,InterruptedException; + 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) {
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/OprofileModel.java +0 -6
@@ -42,12 +42,6 @@ public class OprofileModel extends BaseModel { super(host, TASK_NAME, LOCAL_SCRIPT, REMOTE_EXEC); this.window = window; } - - @Override - public void postProcess(IProgressMonitor monitor) - throws InvocationTargetException, InterruptedException { - - } private void startServer(IProgressMonitor monitor) throws Exception { int exit_code;
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapModel.java +0 -5
@@ -83,9 +83,4 @@ public class SystemtapModel extends BaseModel { throw new InvocationTargetException(e,e.getMessage()); } } - - @Override - public void postProcess(IProgressMonitor monitor) - throws InvocationTargetException, InterruptedException {} - }
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2Model.java +0 -12
@@ -57,18 +57,6 @@ public class Ust2Model extends BaseModel { prj_name = project; this.window = window; } - - @Override - public void postProcess(IProgressMonitor monitor) - throws InvocationTargetException, InterruptedException { - try { - //new File(localfile).delete(); - //NOT delete the directory since lttv-gui is running asynchronously - //new File(localfile.substring(0,localfile.length()-LOCAL_FILE_SUFFIX.length())).delete(); - }catch (Exception e) { - - } - } private String generateData(IProgressMonitor monitor) throws Exception { int exit_code;
Signature · 1 line
1.7.9.5
PATCH v2 5/8 Remove duplicate code when getting remote data from powertop and ust2
In reply to Ioana Grigoropol - powertop and ust2 models contain duplicate code that performs the same action when getting data from remote host (method getDataFile)
- unify getDataFile method implementation by removing the extra param from ust2-> convert it into a field of BaseModel
- move getDataFile method to BaseModel in order to remove duplicate code
- move localFile and remoteFile variables to BaseModel
- ensure that each model will check the validity of the remote file at the end of generateData method
--- .../yocto/sdk/remotetools/actions/BaseModel.java | 5 +++ .../sdk/remotetools/actions/PowertopModel.java | 25 +++--------- .../yocto/sdk/remotetools/actions/Ust2Model.java | 40 ++++++-------------- 3 files changed, 23 insertions(+), 47 deletions(-)
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseModel.java +5 -0
@@ -23,6 +23,8 @@ abstract public class BaseModel implements IRunnableWithProgress { protected String taskName; protected String localScript; protected String remoteExec; + protected String localFile; + protected String remoteFile; private static final int WORKLOAD = 100;
@@ -96,4 +98,7 @@ abstract public class BaseModel implements IRunnableWithProgress { } } + protected void getDataFile(IProgressMonitor monitor) throws Exception { + RSEHelper.getRemoteFile( host, localFile, remoteFile, monitor); + } }
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopModel.java +6 -19
@@ -40,9 +40,6 @@ public class PowertopModel extends BaseModel { private Float time; private boolean showpid; Display display; - - String localfile; - String remotefile; public PowertopModel(IHost host, Float time,boolean showpid,Display display) { super(host, TASK_NAME, LOCAL_SCRIPT, REMOTE_EXEC);
@@ -55,7 +52,7 @@ public class PowertopModel extends BaseModel { public void postProcess(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { - new File(localfile).delete(); + new File(localFile).delete(); }catch (Exception e) { }
@@ -65,21 +62,21 @@ public class PowertopModel extends BaseModel { int exit_code; RemoteApplication app = new RemoteApplication(host, null, remoteExec, null); String currentDate=new SimpleDateFormat("yyyyMMddHHmmssSSS").format(Calendar.getInstance().getTime()).toString(); - remotefile = new String(REMOTE_FILE_PREFIX + currentDate); - localfile = new String(remotefile + LOCAL_FILE_SUFFIX); + remoteFile = new String(REMOTE_FILE_PREFIX + currentDate); + localFile = new String(remoteFile + LOCAL_FILE_SUFFIX); ArrayList <String> param= new ArrayList <String>(); param.add(remoteExec); param.add("start"); param.add("-l"); - param.add(remotefile); + param.add(remoteFile); param.add("powertop"); param.add("-d"); param.add("-t"); param.add(time.toString()); if(showpid) param.add("-p"); - String args = "start -l " + remotefile + " powertop -d -t " + time.toString(); + String args = "start -l " + remoteFile + " powertop -d -t " + time.toString(); if(showpid) args += " -p";
@@ -98,16 +95,6 @@ public class PowertopModel extends BaseModel { } } - private void getDataFile(IProgressMonitor monitor) throws Exception { - - RSEHelper.getRemoteFile( - host, - localfile, - remotefile, - monitor); - } - - @Override public void process(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
@@ -131,7 +118,7 @@ public class PowertopModel extends BaseModel { e.printStackTrace(); return; } - view.setInput(localfile); + view.setInput(localFile); page.bringToTop(view); } });
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2Model.java +12 -28
@@ -26,7 +26,6 @@ import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.rse.core.model.IHost; import org.eclipse.ui.IWorkbenchWindow; -import org.yocto.sdk.remotetools.RSEHelper; import org.yocto.sdk.remotetools.remote.RemoteApplication; public class Ust2Model extends BaseModel {
@@ -46,8 +45,6 @@ public class Ust2Model extends BaseModel { private String prj_name; - private String localfile; - private IWorkbenchWindow window; public Ust2Model(IHost host, String trace, String project, IWorkbenchWindow window) {
@@ -58,12 +55,10 @@ public class Ust2Model extends BaseModel { this.window = window; } - private String generateData(IProgressMonitor monitor) throws Exception { + private void generateData(IProgressMonitor monitor) throws Exception { int exit_code; RemoteApplication app = new RemoteApplication(host, null, remoteExec, null); - String remoteDataFile = null; - try { String temp; int idx;
@@ -75,7 +70,7 @@ public class Ust2Model extends BaseModel { while((temp=in.readLine())!=null) { idx=temp.indexOf(DATAFILE_PREFIX); if(idx!=-1) { - remoteDataFile=temp.substring(idx + DATAFILE_PREFIX.length()); + remoteFile = temp.substring(idx + DATAFILE_PREFIX.length()); break; } }
@@ -87,33 +82,22 @@ public class Ust2Model extends BaseModel { }finally { monitor.done(); } - if(remoteDataFile==null) + if(remoteFile == null) throw new Exception("Ust: null remote data file"); - return remoteDataFile; - } - - private void getDataFile(IProgressMonitor monitor,String datafile) throws Exception { - - if(datafile.endsWith(REMOTE_FILE_SUFFIX)==false) - throw new Exception("Wrong ust data file "+datafile); - - localfile=new String(datafile.substring(0,datafile.length()-4) + LOCAL_FILE_SUFFIX); + if(remoteFile.endsWith(REMOTE_FILE_SUFFIX)==false) + throw new Exception("Wrong ust data file " + remoteFile); - RSEHelper.getRemoteFile( - host, - localfile, - datafile, - monitor); + 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); + 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()); + String traceName = localFile.substring(0,localFile.length()-LOCAL_FILE_SUFFIX.length()); IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot(); IPath full_path = wsroot.getFullPath();
@@ -142,12 +126,12 @@ public class Ust2Model extends BaseModel { String viewerParam=new String(LOCAL_EXEC); int i; - ProcessBuilder pb = new ProcessBuilder("tar", "fx", localfile); + 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 f=new File(localFile.substring(0,localFile.length()-LOCAL_FILE_SUFFIX.length())); File []subdir=f.listFiles(); for (i=0;i<subdir.length;i++) {
@@ -171,11 +155,11 @@ public class Ust2Model extends BaseModel { //preparing remote trace monitor.subTask("Preparing user space lttng data file remotely"); - datafile=generateData(new SubProgressMonitor(monitor,30)); + generateData(new SubProgressMonitor(monitor,30)); //download datafile to local monitor.subTask("Downloading user space lttng data file"); - getDataFile(new SubProgressMonitor(monitor,30),datafile); + getDataFile(new SubProgressMonitor(monitor,30)); //extract datafile and import to lttng project importToProject(new SubProgressMonitor(monitor,30));
Signature · 1 line
1.7.9.5
PATCH v2 6/8 Refactor RemoteApplication implementation
In reply to Ioana Grigoropol- remove references that are not used for running remote commands:
- remote directory where the command will be ran
- remove environment on remote host
- rename class to RemoteShellExec since it is a wrapper over a remote shell execution of a command
--- .../sdk/remotetools/actions/OprofileModel.java | 18 +-- .../sdk/remotetools/actions/PowertopModel.java | 25 +--- .../yocto/sdk/remotetools/actions/Ust2Model.java | 18 +-- .../sdk/remotetools/remote/RemoteApplication.java | 155 -------------------- .../sdk/remotetools/remote/RemoteShellExec.java | 149 +++++++++++++++++++ 5 files changed, 174 insertions(+), 191 deletions(-) delete mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/remote/RemoteApplication.java create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/remote/RemoteShellExec.java
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/OprofileModel.java +9 -9
@@ -26,7 +26,7 @@ import org.yocto.sdk.ide.preferences.PreferenceConstants; import org.yocto.sdk.remotetools.CommonHelper; import org.yocto.sdk.remotetools.LocalJob; import org.yocto.sdk.remotetools.Messages; -import org.yocto.sdk.remotetools.remote.RemoteApplication; +import org.yocto.sdk.remotetools.remote.RemoteShellExec; public class OprofileModel extends BaseModel {
@@ -45,17 +45,17 @@ public class OprofileModel extends BaseModel { private void startServer(IProgressMonitor monitor) throws Exception { int exit_code; - RemoteApplication app = new RemoteApplication(host, null, remoteExec, null); + RemoteShellExec exec = new RemoteShellExec(host, remoteExec); String args="start -d oprofile-server"; try { monitor.beginTask("Starting oprofile-server", 2); //starting oprofile-server - app.start(null,args,monitor); + exec.start(null,args,monitor); monitor.worked(1); - exit_code=app.waitFor(monitor); - app.terminate(); + exit_code = exec.waitFor(monitor); + exec.terminate(); if(exit_code!=0) { throw new RuntimeException("Starting oprofile-server failed with exit code " + new Integer(exit_code).toString()); }
@@ -66,15 +66,15 @@ public class OprofileModel extends BaseModel { private void stopServer(IProgressMonitor monitor) throws Exception { - RemoteApplication app = new RemoteApplication(host, null, remoteExec, null); + RemoteShellExec exec = new RemoteShellExec(host, remoteExec); String args = "stop -d oprofile-server"; try { monitor.beginTask("Stopping oprofile-server", 2); - app.start(null,args,monitor); + exec.start(null, args, monitor); monitor.worked(1); //no cancel for stop server - app.waitFor(null); - app.terminate(); + exec.waitFor(null); + exec.terminate(); }finally { monitor.done(); }
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopModel.java +7 -18
@@ -24,7 +24,7 @@ import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.yocto.sdk.remotetools.RSEHelper; -import org.yocto.sdk.remotetools.remote.RemoteApplication; +import org.yocto.sdk.remotetools.remote.RemoteShellExec; import org.yocto.sdk.remotetools.views.BaseFileView; public class PowertopModel extends BaseModel {
@@ -60,22 +60,11 @@ public class PowertopModel extends BaseModel { private void generateData(IProgressMonitor monitor) throws Exception { int exit_code; - RemoteApplication app = new RemoteApplication(host, null, remoteExec, null); - String currentDate=new SimpleDateFormat("yyyyMMddHHmmssSSS").format(Calendar.getInstance().getTime()).toString(); + RemoteShellExec exec = new RemoteShellExec(host, remoteExec); + String currentDate = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(Calendar.getInstance().getTime()).toString(); remoteFile = new String(REMOTE_FILE_PREFIX + currentDate); localFile = new String(remoteFile + LOCAL_FILE_SUFFIX); - ArrayList <String> param= new ArrayList <String>(); - param.add(remoteExec); - param.add("start"); - param.add("-l"); - param.add(remoteFile); - param.add("powertop"); - param.add("-d"); - param.add("-t"); - param.add(time.toString()); - if(showpid) - param.add("-p"); String args = "start -l " + remoteFile + " powertop -d -t " + time.toString(); if(showpid) args += " -p";
@@ -83,11 +72,11 @@ public class PowertopModel extends BaseModel { try { monitor.beginTask("Starting powertop", 2); //starting oprofile-server - app.start(null,args,monitor); + exec.start(null,args,monitor); monitor.worked(1); - exit_code=app.waitFor(monitor); - app.terminate(); - if(exit_code!=0) { + exit_code = exec.waitFor(monitor); + exec.terminate(); + if(exit_code != 0) { throw new Exception("Starting powertop failed with exit code " + new Integer(exit_code).toString()); } }finally {
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2Model.java +9 -9
@@ -26,7 +26,7 @@ import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.rse.core.model.IHost; import org.eclipse.ui.IWorkbenchWindow; -import org.yocto.sdk.remotetools.remote.RemoteApplication; +import org.yocto.sdk.remotetools.remote.RemoteShellExec; public class Ust2Model extends BaseModel {
@@ -57,25 +57,25 @@ public class Ust2Model extends BaseModel { private void generateData(IProgressMonitor monitor) throws Exception { int exit_code; - RemoteApplication app = new RemoteApplication(host, null, remoteExec, null); + RemoteShellExec exec = new RemoteShellExec(host, remoteExec); try { String temp; int idx; monitor.beginTask("Getting remote ust2 trace", 2); //starting usttrace - app.start(null,trace_loc,monitor); + exec.start(null, trace_loc, monitor); monitor.worked(1); - BufferedReader in=new BufferedReader(new InputStreamReader(app.getInputStream())); - while((temp=in.readLine())!=null) { - idx=temp.indexOf(DATAFILE_PREFIX); - if(idx!=-1) { + BufferedReader in = new BufferedReader(new InputStreamReader(exec.getInputStream())); + while((temp = in.readLine())!=null) { + idx = temp.indexOf(DATAFILE_PREFIX); + if(idx != -1) { remoteFile = temp.substring(idx + DATAFILE_PREFIX.length()); break; } } - exit_code=app.waitFor(monitor); - app.terminate(); + exit_code = exec.waitFor(monitor); + exec.terminate(); if(exit_code!=0) { throw new Exception("Getting remote ust2 trace failed with exit code " + new Integer(exit_code).toString()); }
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/remote/RemoteApplication.java deleted +0 -155
155 lines not on this page · raw message
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/remote/RemoteShellExec.java new file +149 -0
149 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v2 7/8 Refactor powertop, oprofile and ust2 models to remove duplicate code
In reply to Ioana Grigoropol- each of the powertop, oprofile and ust2 commands runs a command remote using RemoteShellExec(former RemoteApplication) following these steps:
- start the command
- wait to terminate
- terminate the command
- check exit code
- in order to remove duplicate code in these models
-> move this code stub to BaseModel in the method runRemoteShellExec
-> customize the retrieval of remote file after running the command (special case for ust2)--- .../yocto/sdk/remotetools/actions/BaseModel.java | 19 +++++++++ .../sdk/remotetools/actions/OprofileModel.java | 32 +-------------- .../sdk/remotetools/actions/PowertopModel.java | 20 +--------- .../yocto/sdk/remotetools/actions/Ust2Model.java | 41 +++++++------------- 4 files changed, 37 insertions(+), 75 deletions(-)
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseModel.java +19 -0
@@ -10,6 +10,8 @@ *******************************************************************************/ 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;
@@ -17,6 +19,7 @@ import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.rse.core.model.IHost; import org.yocto.sdk.remotetools.RSEHelper; +import org.yocto.sdk.remotetools.remote.RemoteShellExec; abstract public class BaseModel implements IRunnableWithProgress { protected IHost host;
@@ -41,6 +44,7 @@ abstract public class BaseModel implements IRunnableWithProgress { 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
@@ -101,4 +105,19 @@ abstract public class BaseModel implements IRunnableWithProgress { 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 {} }
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/OprofileModel.java +2 -30
@@ -26,7 +26,6 @@ import org.yocto.sdk.ide.preferences.PreferenceConstants; import org.yocto.sdk.remotetools.CommonHelper; import org.yocto.sdk.remotetools.LocalJob; import org.yocto.sdk.remotetools.Messages; -import org.yocto.sdk.remotetools.remote.RemoteShellExec; public class OprofileModel extends BaseModel {
@@ -44,40 +43,13 @@ public class OprofileModel extends BaseModel { } private void startServer(IProgressMonitor monitor) throws Exception { - int exit_code; - RemoteShellExec exec = new RemoteShellExec(host, remoteExec); String args="start -d oprofile-server"; - - try { - monitor.beginTask("Starting oprofile-server", 2); - //starting oprofile-server - exec.start(null,args,monitor); - monitor.worked(1); - - exit_code = exec.waitFor(monitor); - exec.terminate(); - if(exit_code!=0) { - throw new RuntimeException("Starting oprofile-server failed with exit code " + new Integer(exit_code).toString()); - } - }finally { - monitor.done(); - } + runRemoteShellExec(monitor, args, true); } private void stopServer(IProgressMonitor monitor) throws Exception { - - RemoteShellExec exec = new RemoteShellExec(host, remoteExec); String args = "stop -d oprofile-server"; - try { - monitor.beginTask("Stopping oprofile-server", 2); - exec.start(null, args, monitor); - monitor.worked(1); - //no cancel for stop server - exec.waitFor(null); - exec.terminate(); - }finally { - monitor.done(); - } + runRemoteShellExec(monitor, args, false); } private String getSearchPath()
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopModel.java +1 -19
@@ -13,7 +13,6 @@ package org.yocto.sdk.remotetools.actions; import java.io.File; import java.lang.reflect.InvocationTargetException; import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Calendar; import org.eclipse.core.runtime.IProgressMonitor;
@@ -23,8 +22,6 @@ 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.RSEHelper; -import org.yocto.sdk.remotetools.remote.RemoteShellExec; import org.yocto.sdk.remotetools.views.BaseFileView; public class PowertopModel extends BaseModel {
@@ -59,8 +56,6 @@ public class PowertopModel extends BaseModel { } private void generateData(IProgressMonitor monitor) throws Exception { - int exit_code; - RemoteShellExec exec = new RemoteShellExec(host, remoteExec); String currentDate = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(Calendar.getInstance().getTime()).toString(); remoteFile = new String(REMOTE_FILE_PREFIX + currentDate); localFile = new String(remoteFile + LOCAL_FILE_SUFFIX);
@@ -68,20 +63,7 @@ public class PowertopModel extends BaseModel { String args = "start -l " + remoteFile + " powertop -d -t " + time.toString(); if(showpid) args += " -p"; - - try { - monitor.beginTask("Starting powertop", 2); - //starting oprofile-server - exec.start(null,args,monitor); - monitor.worked(1); - exit_code = exec.waitFor(monitor); - exec.terminate(); - if(exit_code != 0) { - throw new Exception("Starting powertop failed with exit code " + new Integer(exit_code).toString()); - } - }finally { - monitor.done(); - } + runRemoteShellExec(monitor, args, true); } @Override
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2Model.java +15 -26
61 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v2 8/8 Refactor Latencytop and Perf Handler to remove duplicate code
In reply to Ioana Grigoropol- both latencytop and perf handler run the same initialization code
-> moved the common code to TerminalHandler
-> added constants to hold dialog's titles and messages that are different for each handler--- .../sdk/remotetools/actions/IBaseConstants.java | 3 +++ .../sdk/remotetools/actions/LatencytopHandler.java | 22 +++++++------------- .../yocto/sdk/remotetools/actions/PerfHandler.java | 22 +++++++------------- .../sdk/remotetools/actions/TerminalHandler.java | 16 ++++++++++---- 4 files changed, 31 insertions(+), 32 deletions(-)
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/IBaseConstants.java +3 -0
@@ -21,4 +21,7 @@ public interface IBaseConstants { 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$ }
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/LatencytopHandler.java +8 -14
@@ -10,27 +10,21 @@ *******************************************************************************/ package org.yocto.sdk.remotetools.actions; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.handlers.HandlerUtil; public class LatencytopHandler extends TerminalHandler { private static String initCmd="export PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin; cd; sudo latencytop\r"; + @Override protected String getInitCmd() { return initCmd; } - - protected void initialize(ExecutionEvent event) throws ExecutionException { - IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); - shell = window.getShell(); - - setting=new SimpleSettingDialog( - shell, - "Latencytop", - IBaseConstants.CONNECTION_NAME_LATENCYTOP - ); + @Override + protected String getConnnectionName() { + return IBaseConstants.CONNECTION_NAME_LATENCYTOP; + } + @Override + protected String getDialogTitle() { + return IBaseConstants.DIALOG_TITLE_LATENCYTOP; } }
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PerfHandler.java +8 -14
@@ -10,27 +10,21 @@ *******************************************************************************/ package org.yocto.sdk.remotetools.actions; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.handlers.HandlerUtil; public class PerfHandler extends TerminalHandler { private static String initCmd="cd; perf\r"; + @Override protected String getInitCmd() { return initCmd; } - - protected void initialize(ExecutionEvent event) throws ExecutionException { - IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); - shell = window.getShell(); - setting=new SimpleSettingDialog( - shell, - "Perf", - IBaseConstants.CONNECTION_NAME_LATENCYTOP - ); + @Override + protected String getConnnectionName() { + return IBaseConstants.CONNECTION_NAME_PERF; + } + @Override + protected String getDialogTitle() { + return IBaseConstants.DIALOG_TITLE_PERF; } - }
plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/TerminalHandler.java +12 -4
@@ -13,12 +13,11 @@ 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.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.jface.dialogs.ProgressMonitorDialog; import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.swt.widgets.Shell; import org.eclipse.rse.core.model.IHost; import org.eclipse.rse.internal.terminals.ui.TerminalServiceHelper; import org.eclipse.rse.internal.terminals.ui.views.RSETerminalConnector;
@@ -32,10 +31,13 @@ import org.eclipse.rse.ui.SystemBasePlugin; import org.eclipse.swt.custom.CTabItem; import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.widgets.Shell; import org.eclipse.tm.internal.terminal.control.ITerminalViewControl; import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector; -import org.yocto.sdk.remotetools.RSEHelper; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.handlers.HandlerUtil; import org.yocto.sdk.remotetools.CommonHelper; +import org.yocto.sdk.remotetools.RSEHelper; abstract public class TerminalHandler extends AbstractHandler {
@@ -46,7 +48,13 @@ abstract public class TerminalHandler extends AbstractHandler { protected String changeTerm="export TERM=vt100;"; abstract protected String getInitCmd(); - abstract protected void initialize(ExecutionEvent event) throws ExecutionException; + abstract protected String getConnnectionName(); + 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()); + } protected ITerminalShell getTerminalShellFromTab(CTabItem item) { ITerminalShell terminalShell = null;
Signature · 1 line
1.7.9.5