Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 119991 - Seeing negative time when importing a trace from 1 agent
Summary: Seeing negative time when importing a trace from 1 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 major (vote)
Target Milestone: ---   Edit
Assignee: Ruth Lee CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 148491
  Show dependency tree
 
Reported: 2005-12-08 15:55 EST by Robert Danek CLA
Modified: 2016-05-05 10:47 EDT (History)
3 users (show)

See Also:


Attachments
trcxml that causes negative time to appear (24.06 KB, application/octet-stream)
2006-01-04 12:05 EST, Robert Danek CLA
no flags Details
Patch as figured out by Marius (6.96 KB, patch)
2006-07-10 18:40 EDT, Ruth Lee CLA
no flags Details | Diff
Patch as described in the previous comment. (3.01 KB, patch)
2006-07-13 16:54 EDT, Ruth Lee CLA
no flags Details | Diff
The final patch that was checked in. (5.10 KB, patch)
2006-07-18 16:43 EDT, Ruth Lee CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Danek CLA 2005-12-08 15:55:34 EST
We're running into an issue with TPTP displaying negative time. What's bizarre is that

a) This is _not_ a distributed scenario. All the data is generated from one machine. 
b) The negative time only appears when we do a file import (after having profiled to file), NOT when we collect the data "live". 

Sent Marius a trace file that causes the negative time to appear when it's imported.
Comment 1 Valentina Popescu CLA 2006-01-03 21:44:32 EST
Rob, please attach the trace file to the defect
Comment 2 Robert Danek CLA 2006-01-04 12:05:58 EST
Created attachment 32467 [details]
trcxml that causes negative time to appear
Comment 3 Ruth Lee CLA 2006-03-23 14:51:39 EST
See also bug # 123628. I see the negative time when I use the "full" import but not the "compressed" import.
Comment 4 Robert Danek CLA 2006-05-12 15:51:40 EDT
Upping to blocker since this defect is an absolute must fix in tptp 4.2. 
Comment 5 Ruth Lee CLA 2006-05-15 14:03:30 EDT
Hi Rob,

Can you provide some details on what has changed that prompted you to upgrade this defect from "normal" to "blocker", please? 

Thanks,
Ruth.
Comment 6 Robert Danek CLA 2006-05-15 14:39:17 EDT
We discovered after initially opening the defect that negative time not only appears when profiling to file and then doing an import, but it also appears on occasion when doing 'live' profiling. Given that negative time implies that there is something seriously wrong with the code that TPTP uses for calculating the method timings, and that we don't want to ship our product with the possibility of the user seeing method timings that are completely wrong, we thought we should raise this to blocker to ensure that the problem is fixed in the 4.2 release of TPTP. 
Comment 7 Ruth Lee CLA 2006-05-18 17:21:50 EDT
Rob, would it be possible for you to send me a copy of the program so that I can profile it on my machine and see if the profiling file that I get has the same problem? I want to eliminate the possibility that there's some environment issue.
Comment 8 Robert Danek CLA 2006-05-18 18:53:28 EDT
Responded with details in email. 
Comment 9 Ruth Lee CLA 2006-05-19 16:52:53 EDT
The trace file is constructed incorrectly.

The InvocationContext is supposed to be used only between traces, not within the same trace. You can see that the attached trcxml file is constructed incorrectly because there is at least one method (ticket="8499135027028111448") that is at stack depth 2 that is calling another method that is at stack depth 1. 

Comment 10 Ruth Lee CLA 2006-05-25 15:59:46 EDT
Reopening as per our meeting. Workaround needs to be checked in for 4.2 and Ashish will be opening an enhancement for 4.3 for a more permanent solution.
Comment 11 Ruth Lee CLA 2006-06-02 14:12:17 EDT
As per discussion with Rob, reducing from 'blocking' to 'major' for 4.2 because Rob needs this fix post-4.2.
Comment 12 Ruth Lee CLA 2006-06-12 10:20:17 EDT
Moving to 4.2.1 because that's the version that the originator needs the fix in.
Comment 13 Robert Danek CLA 2006-06-29 15:11:26 EDT
Ruth, 

Can you attach the patch to this defect? 

Thanks. 
Comment 14 Ruth Lee CLA 2006-07-10 18:40:46 EDT
Created attachment 46053 [details]
Patch as figured out by Marius

The previous patch had been made on the 0520 version of TPTP, so I checked out the HEAD version, re-made the patch and tested it. It works as before.

That said, while working on the fix for bugzilla #123628, I saw a condition that is legal yet the 119991 patch would treat as illegal. That is, 119991 looks at every intermediate delta time calculated and if it's negative sets the delta to 0. During 123628 I saw a case where an intermediate negative time was legal because the overhead of the child method was larger than the (end time of parent method - end time of child method). Because part of the time calculation was negative the correct result was reported rather than a result that was too large. 

Thus, rather than proposing this patch be applied as-is, I am going to create another workspace and put the fix for both bugzilla #119991 and bugzilla #123628 and see if a regression occurs. If it does then the patch for 119991 will have to be adjusted and retested by Ashish/Rob.
Comment 15 Ruth Lee CLA 2006-07-11 13:35:22 EDT
An update...

The patch that Marius figured out should not be put in at all because it breaks/causes a regression in the time calculation of a basic test case. I've been looking to see if there's another way to satisfy 119991 that doesn't break an existing test case. Rob/Ashish had suggested looking to see if the InvocationContext is within the same agent - I'll look and see if that's possible. (Marius' fix was slightly different - it looked at the process rather than the agent and InvocationContext.)

Background: The basic test imports a profiling file in full data and in execution statistics mode. The base time etc., despite the different algorithms for each mode, is supposed to be the same for both modes when the import completes. However, when the patch for 119991 is applied, the full data time is completely wrong and the execution statistics is slightly wrong. By removing the "if(deltaTime < 0)" if statements that I expressed concern about in comment #14, the execution statistics time returns to normal, the 119991 negative time problem is resolved, but the full data time remains completely wrong. 



Comment 16 Ruth Lee CLA 2006-07-13 16:53:25 EDT
After investigating, it looks like there's no way to retrieve the InvocationContext for a particular TRCFullMethodInvocation. That's probably why Marius chose to make a patch by looking at the process & location on the stack.

At this point the only hack that I can think of is to check if the size of the children's cumulative time is greater than the size of the invoking method's cumulative time, and if so to not factor the children's cumulative time into the equation. While this 'negative' test should not be done in the execution statistics import mode, it should be safe in full data mode because all of the calculation for a particular call is done at the same time in the one method. 

I've made a quick patch with this fix and it does not cause a regression in the simple test case that was regressed before. Attaching that patch to this defect.

That said, there are some limitations of this patch. Because I can't think of anything that I can do to prevent negative times in the execution statistics mode, it's possible that you will see negative time when that type of import is used. I've also noticed an intermittent defect that happens around half the time when the attached trcxml file is imported: the base, cumulative etc. times for the package are smaller than the times of the profiled class. I have not seen this problem when importing the simple test case. At this point I don't know if the problem is because this is a specialized trace file or if it's more generic and just easier to trigger with this particular trace.


Comment 17 Ruth Lee CLA 2006-07-13 16:54:05 EDT
Created attachment 46267 [details]
Patch as described in the previous comment.
Comment 18 Ruth Lee CLA 2006-07-18 16:43:33 EDT
Created attachment 46477 [details]
The final patch that was checked in.
Comment 19 Ruth Lee CLA 2006-07-18 16:43:48 EDT
Fix checked in.
Comment 20 Ashish Patel CLA 2006-11-16 14:26:27 EST
Closing.