diff options
Diffstat (limited to 'plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2Model.java')
-rw-r--r-- | plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2Model.java | 166 |
1 files changed, 166 insertions, 0 deletions
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 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 Intel Corporation. | ||
3 | * All rights reserved. This program and the accompanying materials | ||
4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
5 | * which accompanies this distribution, and is available at | ||
6 | * http://www.eclipse.org/legal/epl-v10.html | ||
7 | * | ||
8 | * Contributors: | ||
9 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools.actions; | ||
12 | |||
13 | import java.io.BufferedReader; | ||
14 | import java.io.File; | ||
15 | import java.io.IOException; | ||
16 | import java.io.InputStream; | ||
17 | import java.io.InputStreamReader; | ||
18 | import java.lang.reflect.InvocationTargetException; | ||
19 | |||
20 | import org.eclipse.core.resources.IFolder; | ||
21 | import org.eclipse.core.resources.IProject; | ||
22 | import org.eclipse.core.resources.IResource; | ||
23 | import org.eclipse.core.resources.IWorkspaceRoot; | ||
24 | import org.eclipse.core.resources.ResourcesPlugin; | ||
25 | import org.eclipse.core.runtime.IPath; | ||
26 | import org.eclipse.core.runtime.IProgressMonitor; | ||
27 | import org.eclipse.core.runtime.Path; | ||
28 | import org.eclipse.core.runtime.SubProgressMonitor; | ||
29 | import org.eclipse.rse.core.model.IHost; | ||
30 | import org.eclipse.ui.IWorkbenchWindow; | ||
31 | |||
32 | public class Ust2Model extends BaseModel { | ||
33 | |||
34 | private static final String REMOTE_EXEC = "/tmp/ust_tar.sh"; | ||
35 | private static final String LOCAL_SCRIPT = "resources/ust_tar.sh"; | ||
36 | |||
37 | private static final String LOCAL_FILE_SUFFIX = ".local.tar"; | ||
38 | private static final String REMOTE_FILE_SUFFIX = ".tar"; | ||
39 | private static final String LOCAL_EXEC = "lttv-gui"; | ||
40 | private static final String TRACE_FOLDER_NAME = "Traces"; | ||
41 | private static final String DATAFILE_PREFIX = "ustfile:"; | ||
42 | |||
43 | private static final String TASK_NAME = "ust2trace command"; | ||
44 | |||
45 | private String trace_loc; | ||
46 | |||
47 | private String prj_name; | ||
48 | |||
49 | private IWorkbenchWindow window; | ||
50 | |||
51 | public Ust2Model(IHost host, String trace, String project, IWorkbenchWindow window) { | ||
52 | super(host, TASK_NAME, LOCAL_SCRIPT, REMOTE_EXEC); | ||
53 | trace_loc = trace; | ||
54 | |||
55 | prj_name = project; | ||
56 | this.window = window; | ||
57 | } | ||
58 | |||
59 | @Override | ||
60 | protected void checkTerminate(InputStream is) throws IOException { | ||
61 | String temp; | ||
62 | BufferedReader in = new BufferedReader(new InputStreamReader(is)); | ||
63 | while((temp = in.readLine())!=null) { | ||
64 | int idx = temp.indexOf(DATAFILE_PREFIX); | ||
65 | if(idx != -1) { | ||
66 | remoteFile = temp.substring(idx + DATAFILE_PREFIX.length()); | ||
67 | break; | ||
68 | } | ||
69 | } | ||
70 | } | ||
71 | |||
72 | private void generateData(IProgressMonitor monitor) throws Exception { | ||
73 | runRemoteShellExec(monitor, trace_loc, true); | ||
74 | if(remoteFile == null) | ||
75 | throw new Exception("Ust: null remote data file"); | ||
76 | if(remoteFile.endsWith(REMOTE_FILE_SUFFIX)==false) | ||
77 | throw new Exception("Wrong ust data file " + remoteFile); | ||
78 | |||
79 | localFile = new String(remoteFile.substring(0, remoteFile.length()-4) + LOCAL_FILE_SUFFIX); | ||
80 | } | ||
81 | |||
82 | private void importToProject(IProgressMonitor monitor) throws Exception { | ||
83 | ProcessBuilder pb = new ProcessBuilder("tar", "fx", localFile); | ||
84 | pb.directory(new File("/tmp")); | ||
85 | Process p=pb.start(); | ||
86 | if(p.waitFor()!=0) | ||
87 | throw new Exception("extract ust data files failed"); | ||
88 | |||
89 | String traceName = localFile.substring(0,localFile.length()-LOCAL_FILE_SUFFIX.length()); | ||
90 | |||
91 | IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot(); | ||
92 | IPath full_path = wsroot.getFullPath(); | ||
93 | IProject project = wsroot.getProject(prj_name); | ||
94 | IFolder traceFolder = project.getFolder(TRACE_FOLDER_NAME); | ||
95 | if (!traceFolder.exists()) { | ||
96 | throw new Exception("Can't find file trace folder in selected project."); | ||
97 | } | ||
98 | |||
99 | String trace_str = traceName.substring(0, traceName.indexOf('-')); | ||
100 | traceFolder.createLink(new Path(trace_str), IResource.REPLACE, monitor); | ||
101 | for (IResource resource:traceFolder.members()) { | ||
102 | String extension = resource.getFileExtension(); | ||
103 | if (extension != null) | ||
104 | continue; | ||
105 | else { | ||
106 | //traceFolder.setPersistentProperty(TmfCommonConstants.TRACETYPE, "org.eclipse.linuxtools.tmf.ui.type.ctf"); | ||
107 | //resource.setPersistentProperty(TmfCommonConstants.TRACETYPE, "org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace"); | ||
108 | //traceFolder.setPersistentProperty(TmfCommonConstants.TRACEICON, "icons/obj16/garland16.png"); | ||
109 | //traceFolder.touch(null); | ||
110 | } | ||
111 | } | ||
112 | } | ||
113 | |||
114 | private String[] generateViewerParam() throws Exception { | ||
115 | String viewerParam=new String(LOCAL_EXEC); | ||
116 | int i; | ||
117 | |||
118 | ProcessBuilder pb = new ProcessBuilder("tar", "fx", localFile); | ||
119 | pb.directory(new File("/tmp")); | ||
120 | Process p=pb.start(); | ||
121 | if(p.waitFor()!=0) | ||
122 | throw new Exception("extract ust data files failed"); | ||
123 | File f=new File(localFile.substring(0,localFile.length()-LOCAL_FILE_SUFFIX.length())); | ||
124 | File []subdir=f.listFiles(); | ||
125 | |||
126 | for (i=0;i<subdir.length;i++) { | ||
127 | if(subdir[i].isDirectory()) { | ||
128 | viewerParam=viewerParam.concat(" -t " + subdir[i].getAbsolutePath()); | ||
129 | } | ||
130 | } | ||
131 | |||
132 | return viewerParam.split(" "); | ||
133 | } | ||
134 | |||
135 | @Override | ||
136 | public void process(IProgressMonitor monitor) | ||
137 | throws InvocationTargetException, InterruptedException { | ||
138 | // TODO Auto-generated method stub | ||
139 | |||
140 | String datafile; | ||
141 | |||
142 | monitor.beginTask("Running ust", 100); | ||
143 | try { | ||
144 | //preparing remote trace | ||
145 | |||
146 | monitor.subTask("Preparing user space lttng data file remotely"); | ||
147 | generateData(new SubProgressMonitor(monitor,30)); | ||
148 | |||
149 | //download datafile to local | ||
150 | monitor.subTask("Downloading user space lttng data file"); | ||
151 | getDataFile(new SubProgressMonitor(monitor,30)); | ||
152 | |||
153 | //extract datafile and import to lttng project | ||
154 | importToProject(new SubProgressMonitor(monitor,30)); | ||
155 | |||
156 | }catch (InterruptedException e){ | ||
157 | throw e; | ||
158 | }catch (InvocationTargetException e) { | ||
159 | throw e; | ||
160 | }catch (Exception e){ | ||
161 | throw new InvocationTargetException(e, e.getMessage()); | ||
162 | }finally { | ||
163 | monitor.done(); | ||
164 | } | ||
165 | } | ||
166 | } | ||