From c7da892cb23d50d4d85746c9a0b6b14bf570989d Mon Sep 17 00:00:00 2001 From: Adrian Dudau Date: Thu, 26 Jun 2014 13:23:09 +0200 Subject: initial commit for Enea Linux 4.0 Migrated from the internal git server on the daisy-enea branch Signed-off-by: Adrian Dudau --- .../yocto/sdk/remotetools/actions/Ust2Model.java | 166 +++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2Model.java (limited to 'plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2Model.java') 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