Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 187090 - [regr] [Attach] Profile data of ReAttach agent is sent to the PreAttach agent
Summary: [regr] [Attach] Profile data of ReAttach agent is sent to the PreAttach agent
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: TPTP (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P1 blocker (vote)
Target Milestone: ---   Edit
Assignee: Guru Nagarajan CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 192555 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-05-15 15:33 EDT by Eugene Chan CLA
Modified: 2016-05-05 10:48 EDT (History)
6 users (show)

See Also:
guru.nagarajan: review? (slavescu)


Attachments
Team Project set to debug the problem (569 bytes, text/plain)
2007-06-07 21:41 EDT, Marius Slavescu CLA
no flags Details
Patch to debug the connection/XMLTraceDataProcessor reuse problem (3.74 KB, patch)
2007-06-07 21:45 EDT, Marius Slavescu CLA
no flags Details | Diff
stdout from debug session (13.64 KB, text/plain)
2007-06-07 21:52 EDT, Marius Slavescu CLA
no flags Details
stdout from TPTP 4.2.2 debug session (20.44 KB, text/plain)
2007-06-07 22:51 EDT, Marius Slavescu CLA
no flags Details
Agent.detach behavior in 4.2.2 (31.09 KB, text/plain)
2007-06-08 09:45 EDT, Marius Slavescu CLA
no flags Details
Attach.debug behavior in TPTP 4.4 (22.66 KB, text/plain)
2007-06-08 09:49 EDT, Marius Slavescu CLA
no flags Details
Attach.debug behavior in TPTP 4.4 (22.66 KB, text/plain)
2007-06-08 09:49 EDT, Marius Slavescu CLA
no flags Details
Patch for Execution Framework and the TI Client to resolve the dataprocessor loader issue (9.65 KB, patch)
2007-06-13 14:44 EDT, Guru Nagarajan CLA
no flags Details | Diff
Updated patch and clean up of errors (11.72 KB, patch)
2007-06-14 10:52 EDT, Guru Nagarajan CLA
no flags Details | Diff
Proposed fix (14.83 KB, patch)
2007-06-15 06:59 EDT, Ruslan Scherbakov CLA
no flags Details | Diff
Here is the output from the Test I did to validate 187090. (247.00 KB, application/octet-stream)
2007-06-15 16:42 EDT, Guru Nagarajan CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Eugene Chan CLA 2007-05-15 15:33:14 EDT
Driver: tptp.sdk-TPTP-4.4.0-200705080100B

Using JVMPI, with IAC and mentioned driver.
1.Launch an Java application outside of workbench and attach to it from workbench 'Attach to Agent' launch configuration
2.Start profile, verify data is shown in view of agent(a1). Detach from agent(a1)
3.Reattach to process, a new Profiling agent(a2) is shown and continue profile.
Note profile data are sent to the a1 instead of a2.
Comment 1 Eugene Chan CLA 2007-05-15 15:47:50 EDT
same problem with RAC
Comment 2 Eugene Chan CLA 2007-05-18 10:59:00 EDT
problem exists in both PI and TI attach.
Comment 3 Eugene Chan CLA 2007-06-04 17:27:17 EDT
I think we should try to resolved this bug in 4.4 as it's a regression.
Comment 4 Eugene Chan CLA 2007-06-06 16:33:46 EDT
Marius, The attach and reattach agent are basically with the same attribute (including the runtimeID). Would the loader load everything to the same Agent in such case?

example
org.eclipse.hyades.models.hierarchy.impl.TRCAgentProxyImpl@69246924 (name: Java Profiling Agent, type: Profiler, runtimeId: e271cff5-f09d-4513-bf7a-188b783537d2, startTime: 1.181161789241E9, stopTime: 0.0, collectionMode: EXECUTION_STATISTICS_ONLY, active: true, attached: true, collectionData: false, monitored: false, profileFile: null, deltaTime: 0.0)

org.eclipse.hyades.models.hierarchy.impl.TRCAgentProxyImpl@361c361c (name: Java Profiling Agent, type: Profiler, runtimeId: e271cff5-f09d-4513-bf7a-188b783537d2, startTime: 1.181161829769E9, stopTime: 0.0, collectionMode: EXECUTION_STATISTICS_ONLY, active: true, attached: true, collectionData: false, monitored: false, profileFile: null, deltaTime: 0.0)
Comment 5 Eugene Chan CLA 2007-06-06 16:36:41 EDT
I captured the last example in the AttachListener.AgentActive method. Assuming the attach and detach is working properly, attached: collectionData: and Monitored: attributes should be updated correspondingly . Would the loader be able to load to the agent that is attach=true and monitored=true among all agent of the same runtimeId?
Comment 6 Guru Nagarajan CLA 2007-06-07 10:33:51 EDT
Why is this defect a critical. This ought to be a blocker.
Comment 7 Marius Slavescu CLA 2007-06-07 21:41:26 EDT
Created attachment 70621 [details]
Team Project set to debug the problem
Comment 8 Marius Slavescu CLA 2007-06-07 21:45:46 EDT
Created attachment 70622 [details]
Patch to debug the connection/XMLTraceDataProcessor reuse problem

I suppose on detach the data connection should be closed and XMLTraceDataProcessor should be cleaned-up, see the next attachement for debug output that showcases the problem.
Comment 9 Marius Slavescu CLA 2007-06-07 21:52:23 EDT
Created attachment 70623 [details]
stdout from debug session

The output is from a session where I attached, collected some events, detached, reattach, collected some events (on the original connection/XMLTraceDataProcessor), terminated the process, started the process again and repeated the attach/reattach 3 times again with some event generated/collected between each operation (the same XMLTraceDataProcessor was used).

This problem might be the reason for the memory leaks described in bug 186711 and the thread leaks in bug 179157 (because XMLTraceDataProcessor.cleanup() is not called).
Comment 10 Marius Slavescu CLA 2007-06-07 21:57:51 EDT
Ali and Eugene please take a look at what changes were done in 4.4 in the attach/lunch configurations that triggers this behavior.

I'll also continue to investigate and try to find a fix for this problem (which might fix indirectly the other 2 bugs mentioned above).
Comment 11 Marius Slavescu CLA 2007-06-07 22:51:15 EDT
Created attachment 70627 [details]
stdout from TPTP 4.2.2 debug session

As I suspected the behavior in attach/detach/reattach has been changed since TPTP 4.2.2.
In TPTP 4.2.2 the connection was closed on detach (so the XMLTraceDataProcessor has been cleaned up correctly and all the required deregistration was invoked) and on reattach the TRACE/node/processCreate/agentCreate events were resent.

One other thing that I've noticed is that the old agent client framework uses the loadEvent by stream (where the connection input stream is wrapped with a filter stream that will strip out of the data message headers and then is passed to the XMLLoader parser, the XML parsing is done in the same thread) where the new agent client framework uses the old method loadEvent by event (one by one and the XML parsing is done in the parserThread).

Guru please take a look at this and if is not possible to use the TCPDataProcessorNew input stream mode (which is fairly old and stable) in 4.4 we should follow up on this post 4.4.
Comment 12 Marius Slavescu CLA 2007-06-08 09:45:51 EDT
Created attachment 70680 [details]
Agent.detach behavior in 4.2.2

I've run a profiling session in TPTP 4.2.2 (using JVMPI) on PerformanceExample with Attach->Detach->ReAttach(from Profiling Monitor->Terminate the application from outside operations.
See how the data connection stream was closed (Connection closed!) after the AgentImpl.detach method was called.
Comment 13 Marius Slavescu CLA 2007-06-08 09:49:24 EDT
Created attachment 70681 [details]
Attach.debug behavior in TPTP 4.4

I've run the same scenario as above in TPTP 4.4 (using JVMPI) on PerformanceExample.
See how the data connection stream was closed (Connection closed!) only when I terminated the application (after second attach), and the same XMLTraceDataProcessor was used in both attach operation (in TPTP 4.2.2 a different XMLTraceDataProcessor was used in each attach operation).
Comment 14 Marius Slavescu CLA 2007-06-08 09:49:28 EDT
Created attachment 70682 [details]
Attach.debug behavior in TPTP 4.4

I've run the same scenario as above in TPTP 4.4 (using JVMPI) on PerformanceExample.
See how the data connection stream was closed (Connection closed!) only when I terminated the application (after second attach), and the same XMLTraceDataProcessor was used in both attach operation (in TPTP 4.2.2 a different XMLTraceDataProcessor was used in each attach operation).
Comment 15 Marius Slavescu CLA 2007-06-08 10:04:56 EDT
Guru,

I'll transfer this defect to you for further investigation, as I explained above the AgentImpl.detach behavior changed in 4.4 vs 4.2.2 (the data connection input stream is not closed on detach).

Althogh a data connection stream is created for each attach operation (search for XMLTraceDataProcessor.incommingStream) the data is sent through the first data connection in both cases.

Please let me know if you need any help.
Comment 16 Guru Nagarajan CLA 2007-06-12 16:35:16 EDT
Marius,
  I am explicitly calling DataProcessor.cleanUp but despite this on re-attach the XMLLoader is loading into the old data processor.

I am using the new Execution framework. In the Agent.StopMonitoring (equiv of Detach) the data server connection is closed and the data listeners are removed. Despite this the loader is not loading data into the new registered data processor.

Pls investigate
Comment 17 Guru Nagarajan CLA 2007-06-13 14:27:14 EDT
Marius 
 I think I found the issue. I have the patch being tested now. Will attach it for review. I have the attach scenario working fine now.

Comment 18 Guru Nagarajan CLA 2007-06-13 14:44:03 EDT
Created attachment 71220 [details]
Patch for Execution Framework and the TI Client to resolve the dataprocessor loader issue

Test case is to profile the Eclipse Workbench using MemoryANalysis.
with the current build. Following the 6/13 candidate build you can test with all the types of collectors
Comment 19 jkubasta CLA 2007-06-13 15:34:51 EDT
Marius, is there someone else who can review this patch while you work on your defect fixes?
Comment 20 Marius Slavescu CLA 2007-06-13 17:03:03 EDT
Guru,
It seems that the patch it still doesn't fix the problem, I applied the patch on the build where I tested initially (0607). I'll try again with the latest TPTP build.

Looking at the patch I'm not sure if by calling the dataProcessor.cleanup() you solve the problem, instead of calling that directly it should be called from DataServerListener.dataServerExited which should be called when the data connection is closed.

Regarding the testcase I've being using was to start PerformanceExample with:
java -Xrunpiagent:server=controlled PerformanceExample
then attach from the TPTP workbench (using JVMPI execution time analysis with graphical details enabled) and then I did a detach and reattach, then clicked Add button in PerformanceExample.

I'm not familiar with the agent client code, beside the TCPDataServer class, and I don't know how different is the new client code, but it might be easier to take a look at how this was done in 4.2 (or 4.3), it should follow the same approach.

The way I see it is that the detach method should trigger the close of data connection input stream which would trigger the dataServerExited (search for ".dataServerExited()" in org.eclipse.hyades.internal.execution.local.common.TCPDataServer class) which would trigger the cleanup.

You need to match the sequence from TPTP 4.2.2 detach behavior output
(https://bugs.eclipse.org/bugs/attachment.cgi?id=70680):

java.lang.Throwable: AgentImpl.detach() = org.eclipse.hyades.internal.execution.local.control.AgentImpl@50145014
	at org.eclipse.hyades.internal.execution.local.control.AgentImpl.detach(AgentImpl.java:199)
	at org.eclipse.hyades.trace.ui.internal.util.PDCoreUtil.detachAgent(PDCoreUtil.java:308)

...

TCPDataServerNew.done(): entered - Thread[TCPDataFiller,6,main]
java.lang.Throwable: TCPDataServerNew.done(): Connection closed ! Thread[TCPDataFiller,6,main]
	at org.eclipse.hyades.internal.execution.local.common.TCPDataServer$TCPDataProcessorNew.done(TCPDataServer.java:848)
	at org.eclipse.hyades.internal.execution.local.common.TCPDataServer$TCPDataProcessorNew.access$1(TCPDataServer.java:839)
	at org.eclipse.hyades.internal.execution.local.common.TCPDataServer$TCPDataProcessorNew$1.read(TCPDataServer.java:622)
	at org.eclipse.hyades.trace.ui.internal.piclient.XMLTraceDataProcessor$4.read(XMLTraceDataProcessor.java:1035)

...

	at org.eclipse.hyades.loaders.util.XMLLoader.cleanUp(XMLLoader.java:250)
	at org.eclipse.hyades.trace.ui.internal.piclient.XMLTraceDataProcessor.cleanUp(XMLTraceDataProcessor.java:1135)
	at org.eclipse.hyades.trace.ui.internal.piclient.XMLTraceDataProcessor.dataServerExited(XMLTraceDataProcessor.java:327)
	at org.eclipse.hyades.internal.execution.local.common.TCPDataServer$TCPDataProcessorNew.run(TCPDataServer.java:772)
Comment 21 Guru Nagarajan CLA 2007-06-13 17:12:30 EDT
Marius 
 I have changes in two areas 

a) In the execution framework since we are using ephemeral ports the dataserver is explicitly shutdown and memory is released. (These are the changes in the execution framework part of the patch)
b) Secondly, by forcing the DataProcessor.cleanup - I am releasing the processor resources to address the data server shutdown delay. If I do not have the clean up - the data is not loaded by the new processor even if the dataserver is shutdown. Try this with the MemoryAnalysis since that this the best barometer of this.

I have tested it substantially and it works fine with the patch attached. Makesure to refresh your CVS sources and test against atleast the 6/11 AC.
Comment 22 Guru Nagarajan CLA 2007-06-13 17:15:58 EDT
BTW the data server code is in the new execution framework and this differs slightly with the old (hyades) execution framework/
Comment 23 Guru Nagarajan CLA 2007-06-14 01:22:59 EDT
*** Bug 192555 has been marked as a duplicate of this bug. ***
Comment 24 Marius Slavescu CLA 2007-06-14 10:22:24 EDT
Guru, you need to call dataServerExited (avoid calling cleanup directly) in order to make sure all the cleanup and deregistration is done.

Make sure the JVMPI works also, it didn't work for me.

Comment 25 Guru Nagarajan CLA 2007-06-14 10:52:26 EDT
Created attachment 71321 [details]
Updated patch and clean up of errors

Ruslan 
  Pls use this patch for the testing. 
Also look at the Execution Stat - not sending data on the attach.

The Memory and Thread are working good.
Comment 26 Ruslan Scherbakov CLA 2007-06-15 06:59:15 EDT
Created attachment 71432 [details]
Proposed fix

These fix extends patch #71321 to enable exec data collection:
 1. collection mode to be copied from old to new tiAgent (which affect displaying of data)
 2. added extra polling calls on attach in order to enable data update in the view

Review these patch please.
Comment 27 Guru Nagarajan CLA 2007-06-15 12:48:39 EDT
Patch reviewed and tested and it looks good. The attach functionality is now working well.
Comment 28 jkubasta CLA 2007-06-15 13:18:37 EDT
Please submit approval request as patched build will be done this afternoon
Comment 29 Eugene Chan CLA 2007-06-15 13:22:33 EDT
Guru/Ruslan,

Would you please attach a patched plug-in jar for testing with the 0614 build?

Thanks a lot!
Comment 30 Guru Nagarajan CLA 2007-06-15 13:39:29 EDT
Joanna,
 You mean to attach a jar of the plugins in context.
Comment 31 jkubasta CLA 2007-06-15 13:42:44 EDT
I think that is a question for Eugene...
Comment 32 jkubasta CLA 2007-06-15 14:43:46 EDT
Marius, please confirm this patch fixes 186711
Comment 33 Eugene Chan CLA 2007-06-15 15:29:04 EDT
(In reply to comment #31)
> I think that is a question for Eugene...
> 

that's correct.

Also I try to verify the patch with my development workbench. problem stills shown with 1) PI reattach of an detached process that is started outside of workbench, and 2) TI launch from WB and reattach within same WB.
Comment 34 Guru Nagarajan CLA 2007-06-15 15:36:54 EDT
Eugene I am unable to recreate the issue called out in the last comment reg. TI. We just went thru the cases for TI and we were not able to recreate it. 
Please check if you are running the workbench with the latest patch applied.

Thanks
Comment 35 Marius Slavescu CLA 2007-06-15 15:42:27 EDT
(In reply to comment #32)
> Marius, please confirm this patch fixes 186711
> 

I'm still testing the patch, please see my note on the platform mailing list.

This defect is for both PI and TI and if it doesn't both we should split it into two defects, although we should fix both problems at once.
Comment 36 Marius Slavescu CLA 2007-06-15 15:44:34 EDT
(In reply to comment #34)
> Eugene I am unable to recreate the issue called out in the last comment reg.
> TI. We just went thru the cases for TI and we were not able to recreate it. 
> Please check if you are running the workbench with the latest patch applied.
> 
> Thanks
> 

We have tested on CoreDuo or Core2Duo systems, I'll test also on a single CPU and update the status.
Comment 37 Guru Nagarajan CLA 2007-06-15 16:42:53 EDT
Created attachment 71517 [details]
Here is the output from the Test I did to validate 187090. 

Here is the output from the Test I did to validate 187090. I do not see any issues. 
Eugene, Joanna – Let me know if you have any questions.
Comment 38 Eugene Chan CLA 2007-06-15 16:51:22 EDT
Hi Guru,
You are right, If I wait long enough, I will see data refresh with values. However, I see some problem in your screen captures, In the second Attach, why do main() and remove() events show in table as they are not invoked since the second attach, Also I see problem of bug 192300 when I test this scenario which I believe is not a UI problem at all. The execution framework does not respect the stop monitoring event from the workbench side at all.
Comment 39 Marius Slavescu CLA 2007-06-15 16:58:25 EDT
(In reply to comment #37)

Guru, please can you specify the CPU type also (solo, hyper-threaded, coreduo or core2duo).

Please add the following line before first line in the XMLTraceDataProcessor.cleanUp() method:

ModelDebugger.log("XMLTraceDataProcessor.cleanUp - before, this="+this+", scanner="+scanner);
		
and after last line in the same method add:
ModelDebugger.log("XMLTraceDataProcessor.cleanUp - after, this="+this+", scanner="+scanner);

also change the org.eclipse.hyades.models.util.ModelDebugger.exceptionDepth to 10.

run your scenario and attach the output here.
Comment 40 Marius Slavescu CLA 2007-06-15 17:00:16 EDT
(In addiction to comment #39)
Please profile execution and heap in both statistical and full graphical details modes and provide the debug output.
Comment 41 Marius Slavescu CLA 2007-06-15 17:03:55 EDT
(In reply to comment #38)
> Hi Guru,
> You are right, If I wait long enough, I will see data refresh with values.
> However, I see some problem in your screen captures, In the second Attach, why
> do main() and remove() events show in table as they are not invoked since the
> second attach, Also I see problem of bug 192300 when I test this scenario which
> I believe is not a UI problem at all. The execution framework does not respect
> the stop monitoring event from the workbench side at all.
> 

I've seen the same delay when testing on a T40 (single CPU).

Another problem is that Eclipse attach/launch is not working, I've waited a few minutes and no data was coming from TI agent, PI seems to work.

Comment 42 Marius Slavescu CLA 2007-06-16 10:56:36 EDT
Guru and Ruslan please add the info mentioned in comment #39, I will try to add today my debug output also for that scenario. Use PerformanceExample if possible.
Make sure you add also the following line in XMLLoader.startElement before running the profiling sessions:
 	public void startElement(String elementName, boolean hasAttributes, boolean isEmpty) {
System.out.println("XMLLoader.startElement() "+this.toString()+" = "+elementName);

As I said on the mailing list if cleanup is not called (in both cases PI and TI) on detach we will see memory and thread leaks (already mentioned in other critical bugs). 

Before 4.4 dataServerExited was called (as you can easily see in https://bugs.eclipse.org/bugs/attachment.cgi?id=70680) when there was no data expected to come from the agent, without that call I wouldn't know when to stop the XML parser and refresh threads.
Comment 43 Guru Nagarajan CLA 2007-06-16 12:17:42 EDT
Marius,
  I am calling DataProcessor.cleanUp method.
This is called on AgentDetach.

See the patch section
===================================================================
RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.jvmti.client/src/org/eclipse/tptp/platform/jvmti/client/internal/TIUtility.java,v
retrieving revision 1.3
diff -u -r1.3 TIUtility.java
--- src/org/eclipse/tptp/platform/jvmti/client/internal/TIUtility.java	27 Feb 2007 06:05:25 -0000	1.3
+++ src/org/eclipse/tptp/platform/jvmti/client/internal/TIUtility.java	15 Jun 2007 10:57:24 -0000
@@ -87,7 +87,13 @@
 	{
 		if (trcAgentProxy == null || !trcAgentProxy.isToProfileFile())
 			return;
+		
 		final ACDataProcessorAdapter dataProcessor = (ACDataProcessorAdapter) LoadersUtils.locateDataProcessor(trcAgentProxy);
+		if (dataProcessor != null && dataProcessor.getProfileFileName() == null)
+		{
+			dataProcessor.cleanUp();
+		}
+			
 		if (dataProcessor != null && dataProcessor.getProfileFileName() != null)
 		{
 			/* Start a thread that will periodically check the activity of the processor.  If it does not detect any activity
Comment 44 Marius Slavescu CLA 2007-06-16 18:17:03 EDT
(In reply to comment #43)
> Marius,
>   I am calling DataProcessor.cleanUp method.
> This is called on AgentDetach.
Guru, I've seen that you call it in the patch, but I've haven't seen the method being called, I think somehow that code is not touched.
Please attach the debug output requested above, that way you can confirm that the method is called and the XMLLoader.scanner is made null.
Comment 45 Guru Nagarajan CLA 2007-06-17 01:18:34 EDT
Fixed
Comment 46 Sorin Stoian CLA 2007-06-18 12:29:40 EDT
Can anyone provide a list of files that are affected by this defect? I see 3 patches and some files are modified in more than one patch. I need this list to patch the candidate build.
Comment 47 Guru Nagarajan CLA 2007-06-18 13:04:31 EDT
Sorin, 
  The patch to be applied is https://bugs.eclipse.org/bugs/attachment.cgi?id=71432. 
Comment 48 Eugene Chan CLA 2007-07-16 14:24:32 EDT
verified and close bug