Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 148461 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/tptp/platform/instrumentation/ui/internal/launcher/deleg/application/InstrumentAttachDelegate.java (-1 / +1 lines)
Lines 124-130 Link Here
124
		
124
		
125
		LoadersUtils.registerAgentListener(agentProxy, listener);
125
		LoadersUtils.registerAgentListener(agentProxy, listener);
126
		listener.setLaunchMode(InstrumentProcessListener.ATTACH_LAUNCH_MODE);
126
		listener.setLaunchMode(InstrumentProcessListener.ATTACH_LAUNCH_MODE);
127
		listener.addAgentAttach(agent, agentProxy);
127
		listener.setCollectionMode(agent, agentProxy);
128
		process.addProcessListener(listener);
128
		process.addProcessListener(listener);
129
		agent.addAgentListener(listener);
129
		agent.addAgentListener(listener);
130
		
130
		
(-)src/org/eclipse/tptp/platform/instrumentation/ui/internal/launcher/listener/InstrumentProcessListener.java (-9 / +166 lines)
Lines 20-25 Link Here
20
import java.util.ArrayList;
20
import java.util.ArrayList;
21
import java.util.HashMap;
21
import java.util.HashMap;
22
import java.util.Iterator;
22
import java.util.Iterator;
23
import java.util.List;
24
import java.util.Vector;
23
25
24
import org.eclipse.core.resources.IResourceStatus;
26
import org.eclipse.core.resources.IResourceStatus;
25
import org.eclipse.core.resources.ResourcesPlugin;
27
import org.eclipse.core.resources.ResourcesPlugin;
Lines 36-43 Link Here
36
import org.eclipse.hyades.internal.execution.local.control.Agent;
38
import org.eclipse.hyades.internal.execution.local.control.Agent;
37
import org.eclipse.hyades.internal.execution.local.control.AgentConfiguration;
39
import org.eclipse.hyades.internal.execution.local.control.AgentConfiguration;
38
import org.eclipse.hyades.internal.execution.local.control.AgentListener;
40
import org.eclipse.hyades.internal.execution.local.control.AgentListener;
41
import org.eclipse.hyades.internal.execution.local.control.AgentPeerListener;
39
import org.eclipse.hyades.internal.execution.local.control.InactiveAgentException;
42
import org.eclipse.hyades.internal.execution.local.control.InactiveAgentException;
40
import org.eclipse.hyades.internal.execution.local.control.InactiveProcessException;
43
import org.eclipse.hyades.internal.execution.local.control.InactiveProcessException;
44
import org.eclipse.hyades.internal.execution.local.control.Node;
41
import org.eclipse.hyades.internal.execution.local.control.Process;
45
import org.eclipse.hyades.internal.execution.local.control.Process;
42
import org.eclipse.hyades.internal.execution.local.control.ProcessImpl;
46
import org.eclipse.hyades.internal.execution.local.control.ProcessImpl;
43
import org.eclipse.hyades.internal.execution.local.control.ProcessListener;
47
import org.eclipse.hyades.internal.execution.local.control.ProcessListener;
Lines 51-65 Link Here
51
import org.eclipse.hyades.models.hierarchy.util.EMFUtil;
55
import org.eclipse.hyades.models.hierarchy.util.EMFUtil;
52
import org.eclipse.hyades.models.hierarchy.util.SaveUtil;
56
import org.eclipse.hyades.models.hierarchy.util.SaveUtil;
53
import org.eclipse.hyades.trace.ui.ProfileEvent;
57
import org.eclipse.hyades.trace.ui.ProfileEvent;
58
import org.eclipse.hyades.trace.ui.ProfileUIManager;
54
import org.eclipse.hyades.trace.ui.UIPlugin;
59
import org.eclipse.hyades.trace.ui.UIPlugin;
60
import org.eclipse.hyades.trace.ui.internal.util.AttachConfigurationDetail;
55
import org.eclipse.hyades.trace.ui.internal.util.PDCoreUtil;
61
import org.eclipse.hyades.trace.ui.internal.util.PDCoreUtil;
56
import org.eclipse.hyades.trace.ui.internal.util.TString;
62
import org.eclipse.hyades.trace.ui.internal.util.TString;
57
import org.eclipse.hyades.trace.ui.internal.util.TraceMessages;
63
import org.eclipse.hyades.trace.ui.internal.util.TraceMessages;
58
import org.eclipse.jface.dialogs.ErrorDialog;
64
import org.eclipse.jface.dialogs.ErrorDialog;
65
import org.eclipse.jface.preference.IPreferenceStore;
59
import org.eclipse.osgi.util.NLS;
66
import org.eclipse.osgi.util.NLS;
60
import org.eclipse.swt.widgets.Display;
67
import org.eclipse.swt.widgets.Display;
61
import org.eclipse.swt.widgets.Shell;
68
import org.eclipse.swt.widgets.Shell;
69
import org.eclipse.tptp.platform.common.internal.CommonPlugin;
62
import org.eclipse.tptp.platform.common.ui.internal.CommonUIConstants;
70
import org.eclipse.tptp.platform.common.ui.internal.CommonUIConstants;
71
import org.eclipse.tptp.platform.common.ui.trace.internal.CommonUITraceConstants;
63
import org.eclipse.tptp.platform.instrumentation.ui.internal.InstrumentConstants;
72
import org.eclipse.tptp.platform.instrumentation.ui.internal.InstrumentConstants;
64
import org.eclipse.tptp.platform.instrumentation.ui.internal.LogHelper;
73
import org.eclipse.tptp.platform.instrumentation.ui.internal.LogHelper;
65
import org.eclipse.tptp.platform.instrumentation.ui.internal.launcher.DummyDataProcessor;
74
import org.eclipse.tptp.platform.instrumentation.ui.internal.launcher.DummyDataProcessor;
Lines 75-81 Link Here
75
 * @since TPTP 4.2
84
 * @since TPTP 4.2
76
 */
85
 */
77
public class InstrumentProcessListener implements ProcessListener,
86
public class InstrumentProcessListener implements ProcessListener,
78
		AgentListener {
87
		AgentListener, AgentPeerListener {
79
	
88
	
80
	public static final int ATTACH_LAUNCH_MODE = 0;
89
	public static final int ATTACH_LAUNCH_MODE = 0;
81
	public static final int NORMAL_LAUNCH_MODE = 1;
90
	public static final int NORMAL_LAUNCH_MODE = 1;
Lines 130-142 Link Here
130
     * @param process the trc process proxy
139
     * @param process the trc process proxy
131
     */
140
     */
132
    public InstrumentProcessListener(TRCNode node, TRCProcessProxy process) {
141
    public InstrumentProcessListener(TRCNode node, TRCProcessProxy process) {
133
    	trcNode = node;
142
    	this(node, process, null);
134
    	trcProcessProxy = process;
135
    	showAgents = new ArrayList();
136
    	fileList = new ArrayList();
137
    	agentProxyMap = new HashMap();
138
    	armAnlysisType = false;
139
    	profileOnServer = false;
140
    }
143
    }
141
	
144
	
142
    /**
145
    /**
Lines 156-161 Link Here
156
    	armAnlysisType = false;
159
    	armAnlysisType = false;
157
    }
160
    }
158
161
162
    /*
163
     * (non-Javadoc)
164
     * @see org.eclipse.hyades.trace.ui.internal.piclient.PIProcessListener#peerWaiting(org.eclipse.hyades.internal.execution.local.control.Agent, org.eclipse.hyades.internal.execution.local.control.Agent)
165
     */
166
    public synchronized void peerWaiting(Agent agent, Agent peer) {
167
        /*
168
         * Check if we're already attached to this agent. If so,
169
         * don't try to attach again.
170
         */
171
        if (!peer.isAttached() && trcProcessProxy != null && trcProcessProxy.getNode() != null) {
172
	        /*
173
	         * Find the TRCAgentProxy associated with the agent, in
174
	         * order to match the settings on the new TRCAgentProxy.
175
	         */
176
	        TRCAgentProxy trcAgent = null;
177
	        Iterator iter = trcProcessProxy.getAgentProxies().iterator();
178
	        while (iter.hasNext()) {
179
	            TRCAgentProxy agentProxy = (TRCAgentProxy)iter.next();
180
	            Object obj = LoadersUtils.locateAgentInstance(agentProxy);
181
	            if (obj == agent) {
182
	                trcAgent = agentProxy;
183
	                break;
184
	            }
185
	        }
186
	        
187
	        /*
188
	         * Set the default project, monitor, and profile file.
189
	         */
190
			IPreferenceStore store = UIPlugin.getDefault().getPreferenceStore();
191
			String projectName = store.getString(CommonUITraceConstants.TRACE_PROJECT_NAME);
192
			String monitorName = store.getString(CommonUITraceConstants.TRACE_MONITOR_NAME);
193
			
194
			// bug 95689: if agent is currently profile to file, the peer agent will also be profile to file.
195
			String profileFile = (agent!=null? agent.getProfileFile():null);
196
			String peerProfileFile = null;
197
			if (profileFile!=null) {
198
				
199
				StringBuffer suffix = new StringBuffer().append("_").
200
					append(trcAgent.getProcessProxy().getNode().getName()).append("_").
201
					append(trcAgent.getProcessProxy().getPid()).append("_").
202
					append(trcAgent.getRuntimeId()).append(".trcxml"); //$NON-NLS-1$
203
				
204
				int ext = profileFile.lastIndexOf(".trcxml"); //$NON-NLS-1$
205
				if (ext>0) {
206
					peerProfileFile = new StringBuffer(profileFile.substring(0,ext)).append(suffix).toString();
207
				}
208
				else {
209
					peerProfileFile =  new StringBuffer(profileFile).append(suffix).toString();
210
				}
211
			}
212
	
213
	        /*
214
	         * If the peer agent can be found, match the values on the
215
	         * newly discovered agent.
216
	         */
217
	        if (trcAgent != null) {
218
	            TRCProcessProxy trcProcess = trcAgent.getProcessProxy();
219
	            if (trcProcess != null) {
220
	                TRCNode trcNode = trcProcess.getNode();
221
	                if (trcNode != null) {
222
	                    TRCMonitor trcMonitor = trcNode.getMonitor();
223
	                    if (trcMonitor != null) {
224
//	                        IResource folder = HyadesUtil.getSelectionFolder(trcMonitor);
225
	                    	URI projectPath = trcMonitor.eResource().getURI();
226
	                        String fullProjectPath =  projectPath.trimSegments(1).path();
227
	                        fullProjectPath = fullProjectPath.substring(fullProjectPath.indexOf('/', 1));
228
	                        fullProjectPath = fullProjectPath.replaceAll("%20", " ");
229
	                        if (fullProjectPath != null) {
230
	                            monitorName = trcMonitor.getName();
231
	                            projectName = fullProjectPath;
232
	                        }
233
	                    }
234
	                }
235
	            }
236
	        }
237
	        
238
	        try {
239
	            Node node = peer.getProcess().getNode();
240
	            final String hostname = node.getName();
241
	            String port = String.valueOf(node.getConnection().getPort());
242
	            Vector agents = new Vector();
243
	            agents.add(peer);
244
245
	            /*
246
	             * Add Analysis Type
247
	             */
248
        		LauncherUtility.associateAnalysisType(peer, InstrumentConstants.ARM_ANALYSIS_TYPE);
249
        		
250
	            /*
251
	             * Copy the agent options to the newly discovered
252
	             * agent.
253
	             */
254
	            Vector options = new Vector();
255
	            AgentConfiguration conf = agent.getConfiguration();
256
	            for (int i=0;i<conf.size();++i) {
257
	                options.add(conf.getEntryAt(i));
258
	            }
259
	            
260
	            /*
261
	             * Force the connection to be established before attaching.
262
	             * This will avoid the delay in re-establishing when start
263
	             * monitoring, which freezes the UI.
264
	             */
265
	            PDCoreUtil.profileConnect(hostname, port);
266
	            
267
	            /*
268
	             * Attach to the newly discovered agent.
269
	             */
270
	            AttachConfigurationDetail attachConfigurationDetail = new AttachConfigurationDetail();
271
	            attachConfigurationDetail.setHostName(hostname);
272
	            attachConfigurationDetail.setAgents(agents);
273
	            attachConfigurationDetail.setOptions(options);
274
	            attachConfigurationDetail.setProject(projectName);
275
	            attachConfigurationDetail.setMonitor(monitorName);
276
	            attachConfigurationDetail.setPortNumber(port);
277
	            attachConfigurationDetail.setProfileFile(peerProfileFile);
278
	            attachConfigurationDetail.setSwitchPerspective(false);
279
	            
280
	            List trcAgents = PDCoreUtil.attach(attachConfigurationDetail);
281
	            
282
	            if (trcAgents != null)
283
	            {
284
		            for (int i = 0, agentsCount = trcAgents.size(); i < agentsCount; i++)
285
					{
286
		            	TRCAgentProxy currentAgentProxy = (TRCAgentProxy)trcAgents.get(i);
287
		            	Object currentAgent = LoadersUtils.locateAgentInstance(currentAgentProxy);
288
		            	if (currentAgent instanceof Agent)
289
		            	{
290
		            		/* Set Collection mode */		            		
291
		            		setCollectionMode((Agent)currentAgent, currentAgentProxy);
292
		            		
293
		            		/* attach */
294
		            		PDCoreUtil.doAttach((Agent)currentAgent, currentAgentProxy);
295
		            	}
296
					}
297
		            
298
		            if (trcAgents.size() == 1) {
299
		                final Object obj = trcAgents.get(0);
300
		                if (obj instanceof TRCAgentProxy) {
301
		                    Display.getDefault().syncExec(new Runnable() {
302
		                        public void run() {
303
		    			            ProfileUIManager.getInstance().startMonitoring((TRCAgentProxy)obj);
304
		                        }
305
		                    });
306
		                }
307
		            }	            	
308
	            }
309
	        }
310
	        catch (Exception e) {
311
	        	CommonPlugin.logError(e);
312
	        }
313
        }
314
    }
315
    
159
    /**
316
    /**
160
     * Invoked when a process is exited.
317
     * Invoked when a process is exited.
161
     * 
318
     * 
Lines 341-347 Link Here
341
	 *  
498
	 *  
342
	 * @param agent The agent
499
	 * @param agent The agent
343
	 */
500
	 */
344
	public void addAgentAttach(Agent agent, TRCAgentProxy agentProxy) {
501
	public void setCollectionMode(Agent agent, TRCAgentProxy agentProxy) {
345
		agentProxy.setCollectionMode(TRCCollectionMode.HEAP_AND_EXECUTION_FULL_LITERAL);
502
		agentProxy.setCollectionMode(TRCCollectionMode.HEAP_AND_EXECUTION_FULL_LITERAL);
346
		agentProxy.getAgent().setCollectionMode(TRCCollectionMode.HEAP_AND_EXECUTION_FULL_LITERAL);
503
		agentProxy.getAgent().setCollectionMode(TRCCollectionMode.HEAP_AND_EXECUTION_FULL_LITERAL);
347
	}
504
	}
(-)src/org/eclipse/tptp/trace/ui/internal/launcher/core/LauncherUtility.java (-1 / +11 lines)
Lines 1023-1029 Link Here
1023
	 * @return The configuration entry that is associated with the agent.
1023
	 * @return The configuration entry that is associated with the agent.
1024
	 */
1024
	 */
1025
	public static AgentConfigurationEntry associateAnalysisType(Agent agent, String id)
1025
	public static AgentConfigurationEntry associateAnalysisType(Agent agent, String id)
1026
	{		
1026
	{	
1027
		String name = LauncherConstants.ANALYSIS_TYPE_ASSOCIATION + "(" + id + ")";
1028
		String value = id;
1029
		
1030
		/* return existing analysis type if it exists */
1031
		for (int i=0; agent != null && i < agent.getConfiguration().size(); i++) {
1032
			AgentConfigurationEntry entry = agent.getConfiguration().getEntryAt(i);
1033
			if (entry.getName().equals(name) && entry.getValue().equals(value))
1034
				return entry;
1035
		}
1036
		
1027
		AgentConfigurationEntry entry = createAgentConfigurationEntry(LauncherConstants.ANALYSIS_TYPE_ASSOCIATION + "(" + id + ")", id);		
1037
		AgentConfigurationEntry entry = createAgentConfigurationEntry(LauncherConstants.ANALYSIS_TYPE_ASSOCIATION + "(" + id + ")", id);		
1028
		if (agent != null)
1038
		if (agent != null)
1029
			agent.getConfiguration().addEntry(entry);
1039
			agent.getConfiguration().addEntry(entry);

Return to bug 148461