diff options
Diffstat (limited to 'plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/OprofileModel.java')
-rw-r--r-- | plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/OprofileModel.java | 171 |
1 files changed, 171 insertions, 0 deletions
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 @@ | |||
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.FileReader; | ||
16 | import java.io.IOException; | ||
17 | import java.lang.reflect.InvocationTargetException; | ||
18 | |||
19 | import org.eclipse.core.runtime.IProgressMonitor; | ||
20 | import org.eclipse.core.runtime.SubProgressMonitor; | ||
21 | import org.eclipse.jface.preference.IPreferenceStore; | ||
22 | import org.eclipse.rse.core.model.IHost; | ||
23 | import org.eclipse.ui.IWorkbenchWindow; | ||
24 | import org.yocto.remote.utils.CommonHelper; | ||
25 | import org.yocto.sdk.ide.YoctoSDKPlugin; | ||
26 | import org.yocto.sdk.ide.preferences.PreferenceConstants; | ||
27 | import org.yocto.sdk.remotetools.LocalJob; | ||
28 | import org.yocto.sdk.remotetools.Messages; | ||
29 | |||
30 | public class OprofileModel extends BaseModel { | ||
31 | |||
32 | private static final String REMOTE_EXEC = "/tmp/yocto_tool.sh"; | ||
33 | private static final String LOCAL_SCRIPT = "resources/yocto_tool.sh"; | ||
34 | |||
35 | private static final String LOCAL_EXEC = "oprofile-viewer"; | ||
36 | |||
37 | private static final String TASK_NAME = "oprofile command"; | ||
38 | |||
39 | private IWorkbenchWindow window; | ||
40 | public OprofileModel(IHost host, IWorkbenchWindow window) { | ||
41 | super(host, TASK_NAME, LOCAL_SCRIPT, REMOTE_EXEC); | ||
42 | this.window = window; | ||
43 | } | ||
44 | |||
45 | private void startServer(IProgressMonitor monitor) throws Exception { | ||
46 | String args="start -d oprofile-server"; | ||
47 | runRemoteShellExec(monitor, args, true); | ||
48 | } | ||
49 | |||
50 | private void stopServer(IProgressMonitor monitor) throws Exception { | ||
51 | String args = "stop -d oprofile-server"; | ||
52 | runRemoteShellExec(monitor, args, false); | ||
53 | } | ||
54 | |||
55 | private String getSearchPath() | ||
56 | { | ||
57 | try | ||
58 | { | ||
59 | String search=null; | ||
60 | IPreferenceStore store = YoctoSDKPlugin.getDefault().getPreferenceStore(); | ||
61 | String env_script=store.getString(PreferenceConstants.TOOLCHAIN_ROOT) + | ||
62 | "/" + | ||
63 | "environment-setup-" + | ||
64 | store.getString(PreferenceConstants.TOOLCHAIN_TRIPLET); | ||
65 | File file = new File(env_script); | ||
66 | |||
67 | if (file.exists()) { | ||
68 | BufferedReader input = new BufferedReader(new FileReader(file)); | ||
69 | |||
70 | try | ||
71 | { | ||
72 | String line = null; | ||
73 | |||
74 | while ((line = input.readLine()) != null) | ||
75 | { | ||
76 | if (!line.startsWith("export")) | ||
77 | continue; | ||
78 | String sKey = line.substring("export".length() + 1, line.indexOf('=')); | ||
79 | if(!sKey.equals("PATH")) | ||
80 | continue; | ||
81 | String sValue = line.substring(line.indexOf('=') + 1); | ||
82 | if (sValue.startsWith("\"") && sValue.endsWith("\"")) | ||
83 | sValue = sValue.substring(sValue.indexOf('"') + 1, sValue.lastIndexOf('"')); | ||
84 | /* If PATH ending with $PATH, we need to join with current system path */ | ||
85 | if (sKey.equalsIgnoreCase("PATH")) { | ||
86 | if (sValue.lastIndexOf("$PATH") >= 0) | ||
87 | sValue = sValue.substring(0, sValue.lastIndexOf("$PATH")) + System.getenv("PATH"); | ||
88 | } | ||
89 | search=sValue; | ||
90 | //System.out.printf("get env key %s value %s\n", sKey, sValue); | ||
91 | } | ||
92 | |||
93 | } | ||
94 | finally { | ||
95 | input.close(); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | return search; | ||
100 | |||
101 | } | ||
102 | catch (IOException e) | ||
103 | { | ||
104 | e.printStackTrace(); | ||
105 | return null; | ||
106 | } | ||
107 | |||
108 | } | ||
109 | |||
110 | @Override | ||
111 | public void process(IProgressMonitor monitor) | ||
112 | throws InvocationTargetException, InterruptedException { | ||
113 | |||
114 | boolean stopServer=true; | ||
115 | |||
116 | try { | ||
117 | try { | ||
118 | monitor.beginTask("Starting oprofile", 100); | ||
119 | //start oprofile-server | ||
120 | monitor.subTask("Starting oprofile-server"); | ||
121 | startServer(new SubProgressMonitor(monitor,80)); | ||
122 | |||
123 | //start local oprofile-viewer | ||
124 | monitor.subTask("oprofile-viewer is running locally"); | ||
125 | String searchPath=getSearchPath(); | ||
126 | |||
127 | new LocalJob("oprofile-viewer", | ||
128 | (searchPath!=null) ? | ||
129 | new String[] {LOCAL_EXEC,"-h",host.getHostName(),"-s",searchPath} : | ||
130 | new String[] {LOCAL_EXEC,"-h",host.getHostName()}, | ||
131 | null, | ||
132 | null, | ||
133 | window).schedule(); | ||
134 | //we can't stop server because the oprofile-viewer is running asynchronously | ||
135 | stopServer=false; | ||
136 | |||
137 | }catch (InterruptedException e) { | ||
138 | throw e; | ||
139 | }finally { | ||
140 | //stop oprofile-server | ||
141 | if(stopServer) { | ||
142 | monitor.subTask("Stopping oprofile-viewer"); | ||
143 | stopServer(new SubProgressMonitor(monitor,30)); | ||
144 | } | ||
145 | } | ||
146 | }catch (InterruptedException e){ | ||
147 | throw e; | ||
148 | }catch (InvocationTargetException e) { | ||
149 | throw e; | ||
150 | }catch (Exception e){ | ||
151 | throw new InvocationTargetException(e, e.getMessage()); | ||
152 | }finally { | ||
153 | monitor.done(); | ||
154 | } | ||
155 | } | ||
156 | |||
157 | static public boolean checkAvail() { | ||
158 | boolean ret=CommonHelper.isExecAvail(LOCAL_EXEC); | ||
159 | |||
160 | if(ret==false) { | ||
161 | CommonHelper.showErrorDialog("Oprofile", null,Messages.ErrorOprofileViewer); | ||
162 | }else { | ||
163 | ret=CommonHelper.isExecAvail("opreport"); | ||
164 | if(ret==false) { | ||
165 | CommonHelper.showErrorDialog("Oprofile", null,Messages.ErrorOprofile); | ||
166 | } | ||
167 | } | ||
168 | return ret; | ||
169 | } | ||
170 | |||
171 | } | ||