Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 197176

Summary: Method Invocation Details: cannot understand "invoked by" and "invokes" columns
Product: z_Archived Reporter: changzhouwang <changzhouwang>
Component: TPTPAssignee: Ritwik Lodhiya <ritwikl>
Status: CLOSED FIXED QA Contact:
Severity: critical    
Priority: P1 CC: analexee, chris.l.elford, ewchan, jkubasta, mikhail.sennikovskiy, paulslau
Version: unspecifiedKeywords: plan
Target Milestone: ---Flags: paulslau: review-
analexee: review+
ewchan: review+
Hardware: PC   
OS: Windows XP   
Whiteboard: closed460
Bug Depends on:    
Bug Blocks: 208746    
Attachments:
Description Flags
trace file from running hello world type app with sun vm (win32)
none
patch moved from 208746
none
4 Pics in jpg
none
showing failure with 4.5I4
none
Europa plus Alex patch showing same situation
none
Unable to properly open the profiling file
none
Some more Screenshots
none
Proposed Patch
none
screen shot shows problem in ascd sort
none
screen shot shows problem in desc sort
none
Proposed Patch v2.0
none
Patch for different plugin
none
Example trcxml that fails with 4.5 I5
none
fix for incorrect representation of trace attached by Chris none

Description changzhouwang CLA 2007-07-19 13:05:23 EDT
The documentation does not clearly specify the exact meaning of these columns. In the following example, it shows m3 "invokes" m4 twice, but all other "invokes" are 1. Also, all "invoked by" columns are 1. That's a mystery to me.

/*******************************************************************************
 * Copyright (c) 2007 The Boeing Company. All rights reserved.
 * 
 * This program and the accompanying materials are made available under the 
 * terms of the Eclipse Public License v1.0, which accompanies this 
 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html.
 * 
 * Author: Changzhou Wang
 * Created: Jul 19, 2007 9:37:33 AM
 ******************************************************************************/
package com.boeing.cmap.basic;

public class TestProfiler {
    public static void main(String[] args) {
        int n = 0;
        for (int i=1; i<=2; i++) {
            n += m1(i);
        }
        for (int i=1; i<=2; i++) {
            n += m2(i);
        }
        for (int i=1; i<=2; i++) {
            n += m2(i);
        }
        System.out.println(n);
    }
    private static int m1(int i) {
        System.out.println("m1("+i+")");
        int n = 0;
        for (int j=1; j<=i+i; j++) {
            n+= m3(j);
        }
        return n;
    }
    private static int m2(int i) {
        System.out.println("  m2("+i+")");
        int n = 0;
        for (int j=1; j<=i+i; j++) {
            n+= m3(j);
        }
        for (int j=1; j<=i+i; j++) {
            n+= m4(j);
        }
        return n;
    }
    private static int m3(int i) {
        System.out.println("    m3("+i+")");
        int n = 0;
        for (int j=1; j<=i+i; j++) {
            n+= m4(j);
        }
        return n;
    }
    private static int m4(int k) {
        System.out.println("      m4("+k+")");
        return k*k;
    }
}
Comment 1 changzhouwang CLA 2007-07-19 13:09:39 EDT
I thought for each selected method, the total number of calls equal to the sum of "Invoked by" numbers. But this is definitely not true. 

Comment 2 Chris Elford CLA 2007-10-30 19:24:07 EDT
Created attachment 81668 [details]
trace file from running hello world type app with sun vm (win32)

sample showing problem
Comment 3 Chris Elford CLA 2007-10-30 19:27:55 EDT
I believe this is something significantly more serious than a documentation flaw.  I think it is a serious problem in the view or import into the data model.  i've attached a sample trace file.  If you take the most frequently called method and look at the invocation stats, you will see that the invoked by column in the middle section is off by several orders of magnitude from the total call count.  Looking thru the xml file indicates that the total call count is correct.

I'm downloading TPTP 4.3 and will load the trace there to see if this is a 4.4 regression.

Thx,
Chris
Comment 4 Chris Elford CLA 2007-10-30 20:19:22 EDT
Note that I have verified that this has the same behavior importing in to TPTP the 4.3.1 release.  Thus, it does not appear to be a recent regression.

Thx,
Chris
Comment 5 Eugene Chan CLA 2007-10-31 10:27:45 EDT
Joanna, would you please take a look into this problem?
Comment 6 Chris Elford CLA 2007-10-31 21:07:18 EDT
I see [part of] what is causing part of the problem....

It looks like the method invocation details view is not designed around aggregated records but instead assumes that each stack corresponds to a single instance.

In the the trace that I uploaded, charAt() is invoked 1226 times.  There are 43 distinct stacks/callchains documented in the aggregated file (grep 65552 trace-sun.trcxml | grep Entry | wc).  If you sum up the invokedby column, you see that it adds to 43.  So it looks like each distinct stack/callchain increments the invoked by by 1 instead of by the "count" associated with each aggregated record.  I'm guessing that the invokes data at the bottom of the view is similar.

Looking thru the view code, I believe the view part of the issue is in MethodDetailsStatistic.java (dev.eclipse.org\trace\org.eclipse.hyades.trace.views\src\org\eclipse\hyades\trace\views\internal)

-------------

		       Iterator iterator = method.getInvocations().iterator();
		       while(iterator.hasNext())
		       {
		       	  TRCMethodInvocation inv = (TRCMethodInvocation) iterator.next();
		       	  
		       	   if(inv.getInvokedBy() == null)
		       	   	continue;
		       	   
			  	 TRCMethod m = inv.getInvokedBy().getMethod();
			  	 
			  	 Object value = tmpMap.get(m);
			  	 if(value != null)   
			  	 {	
			  	 	 int i = ((Integer)value).intValue()+1;
		    	  	 tmpMap.put(m, new Integer(i));
			  	 }
			  	 else
			  	 	tmpMap.put(m, new Integer(1));
		        }

------------------
If I read this correctly (and I'm not sure I do... :-), if a new invoker is found, it installs 1 in the map, if a duplicate is found, it increments it by one.  This should work fine in non-aggregating mode.  In aggregating mode, I believe that the value should be inserted or added by the COUNT of the aggregation record instead of by 1.  I'm not certain this data is in the model but I assume it is in there somewhere...  I was assuming that it would be a field in AggregatedInvocation but I don't see it there...   I'm somewhat worried that the count might not exist in the model at all...  Though if that is true, one wonders how the total adds up correctly to 1226 at the top of the view that shows total invocations of the method.

I started looking at this from the data loader perspective to see if the data is loaded into the model but haven't gotten too far there yet.  

-------------------

This is turning out to be a blocker for an Asia summit presentation that we're trying to wrap up to demonstrate how to use TPTP to optimize Harmony.  We need to run some of or stuff without filters because we're trying to find Harmony classlibs that need optimization (requiring us to use aggregated mode).
Comment 7 Chris Elford CLA 2007-10-31 21:27:54 EDT
I don't suppose we'd be so lucky that the TRCMethod.getCalls() has the count for the stack instance versus the total count of times that that method was called and the following would magically work?

while(iterator.hasNext())
		       {
		       	  TRCMethodInvocation inv = (TRCMethodInvocation) iterator.next();
		       	  
		       	   if(inv.getInvokedBy() == null)
		       	   	continue;
		       	   
			  	 TRCMethod m = inv.getInvokedBy().getMethod();
			  	 
			  	 Object value = tmpMap.get(m);
			  	 if(value != null)   
			  	 {	
			  	 	 int i = ((Integer)value).intValue()+m.getCalls();
		    	  	 tmpMap.put(m, new Integer(i));
			  	 }
			  	 else
			  	 	tmpMap.put(m, new Integer(m.getCalls()));
		        }

If I could build, I might try it just to see what would happen...

----

Note that I have verified that the callee section seems to have the same basic code so I really do suspect it has the same problem...
Comment 8 Chris Elford CLA 2007-11-01 19:08:50 EDT
Guru gave me a little tuturial on building the necessary plugins. 

Unfortunately, this mod doesn't help for several reasons.  One being that it doesn't actually show up in the view after the change...  I tweaked it a bit to dump some information to System.out.  It appears at this point m.getCount() only has the count from the last call stack.  So if 2 different callstacks can result in a() calling b(), I get 2*the_count_of_second(a()->b()) instead of the_count_of_first(a()->b())+the_count_of_second(a()->b()).  I wonder if the information that is needed is in the model at all.
Comment 9 Chris Elford CLA 2007-11-02 21:46:11 EDT
Please raise priority!

Note that the codepath below doesn't do anything useful.  I did find the "right" place to tweak the code...

It is in MethodStatisticLabelProvider


								TRCMethodInvocation mi = ((TRCMethodInvocation)i.next()).getInvokedBy();
								if(mi != null && mi.getMethod().equals(m)) 
									nb++;

I tweaked the body to be:
{
if(mi instanceof TRCAggregatedMethodInvocation) {
  nb+=((TRCAggregatedMethodInvocation)mi).getCount();
} else {
									nb++;
}
}

Unfortunately, this just makes the column equivalent to the "calls" column.  i suspect the issue to be both here and in the loader.  I went tweaking the loader of aggregatedmethodenter records but didn't find anything that actually causes anything to change.

The views seem to have some issues.  I'm not sure if its just because we're using the same code for TI and PI or if its something more fundamental.  Joanna, Is supporting the view code one of the things that you will have a resource starting for in a few months?
Comment 10 jkubasta CLA 2007-11-03 10:26:26 EDT
Yes, resource will be on board in January
Comment 11 Alexander N. Alexeev CLA 2007-11-13 03:46:44 EST
*** Bug 208746 has been marked as a duplicate of this bug. ***
Comment 12 Alexander N. Alexeev CLA 2007-11-13 03:48:12 EST
Created attachment 82737 [details]
patch moved from 208746
Comment 13 Ritwik Lodhiya CLA 2008-01-21 18:16:54 EST
Created attachment 87456 [details]
4 Pics in jpg 

I checked this bug and tried various ways to see if the program produces a mistake. I could not reproduce the error that was reported with the TestProfiler program. 

I have screenshots for methods m1, m2, m3, m4 in jpg format. I'm pretty sure that the resuts given by the "invoked by" and "invokes" columns are correct. 

Mr. Changzhou Wang, can you please try to reproduce the error and see if you still get the same results? 

I used Windows XP Opersting System with TPTP-4.5.0-200712211700
Comment 14 Ritwik Lodhiya CLA 2008-01-21 18:24:30 EST
PS - sorry I forgot to mention this in my previous post, but I used JDK 1.5 to test the program. 
Comment 15 Chris Elford CLA 2008-01-21 19:42:23 EST
Created attachment 87463 [details]
showing failure with 4.5I4

Note that when I tried the version with Alex's patch the problem was resolved and it does not look like the patch has been integrated as of TPTP-4.5.0-200712211700.

Can you load the trace that is the first attachment, load it and look at method invocation details for java.lang.String.charAt(int) char.  

Screenshot attached.
Comment 16 Chris Elford CLA 2008-01-21 19:47:12 EST
Created attachment 87464 [details]
Europa plus Alex patch showing same situation

This one shows the same trace file loaded with Alex' patch (this was a Europa base)
Comment 17 Chris Elford CLA 2008-01-21 19:49:00 EST
note that the values don't add up in the "good" screenshot because there is a scrollbar to show the remaining invokers.  When I add them up they do indeed add to the number of times that charAt was invoked. -- thx, Chris
Comment 18 Ritwik Lodhiya CLA 2008-01-22 14:47:41 EST
Created attachment 87550 [details]
Unable to properly open the profiling file

Hi Chris, 

I'm having difficulty reproducing the error still. Can you please tell me how you got the screen you have shown in the screenshots? When I tried to view the trace file from the 1st attachment, I did not get anything on my screen (I have attached my screenshot for reference). 

I took the following steps, please indicate if I should've done something differently:
1) File -> Import... -> Profiling and Logging -> Profiling File
2) Browse trace-sun.trcxml 
3) Select Full for Range, and Show Full Data
4) Select No Filters
Comment 19 Chris Elford CLA 2008-01-22 14:54:22 EST
when you try to open full details I think it defaults to UML trace.

import->profiling file->
full range, no filters, show full data

openwith->execution statistics
browse to java.lang.String.Charat (open package java.lang, open class string, click CharAt)
choose method invocationdetails tab.


Comment 20 Ritwik Lodhiya CLA 2008-01-22 18:40:38 EST
Created attachment 87584 [details]
Some more Screenshots 

Hello, 

I tried applying Alex's patch and it seems to solve the problem. The charAt method shows the right number in the "invoked by" column. 

I also used the patch to try and see if it addresses the problem of the initial program TestProfiler and it turns out that it works fine as well. I have the screenshots for the 2 tests in the zipped attachment. 

Alex's patch works but there is one situation which needs to be addressed. If you notice the screenshot charAt(int).jpg, its clear that the function that sorts the number of "invoked by" calls is not correct. I believe that is the last thing that has to be fixed before bug 197176 can be resolved.
Comment 21 Chris Elford CLA 2008-01-22 18:54:24 EST
Yes, I noticed some anomolies with sorting on that column after the patch as well.  I was able to make forward progress with the immediate analysis I was trying to do even with that flaw.  It would be great for the sort to work correctly.  Should be a simple tweak.  I suspect its sorting based on the original incorrect number instead of the correct number that the patch calculates.

I'd actually run into this problem independent of the TestProfiler test in this bug and found this one searching bugzilla before filing a new bug.  Its good to see independent confirmation that it was indeed the same bug...  :-)

Thx, Chris

Comment 22 Ritwik Lodhiya CLA 2008-01-24 16:25:31 EST
Created attachment 87807 [details]
Proposed Patch

Infact, that's exactly what the problem was. 

I have attached a patch which primarily addresses the problem of bad sorting. However, Alex's patch is included as a part of this patch just to keep it simple and fix the defect internally, and on display.
Comment 23 jkubasta CLA 2008-01-30 10:31:10 EST
Cutoff for i5 defect check in is Friday.  Please review the latest patch before then. Thanks.
Comment 24 Paul Slauenwhite CLA 2008-01-30 12:25:47 EST
I reviewed the patch and everything looks fine (my only comment would be updating the copyright date on the source file).  However, I am not familiar with the code so I recommend Eugene review the patch as well.
Comment 25 Alexander N. Alexeev CLA 2008-01-31 06:09:16 EST
I think that commented snippets of code worth to remove.
We always can use CVS history to restore.
Comment 26 Eugene Chan CLA 2008-01-31 15:19:26 EST
-1. 

I found a problem with the sorting function.

Profile the original testprofiler application, create a new filter set and add java.lang* * INCLUDE to the default filters.

in execution statistic tab of view, double click on main() method, invocation detail view is opened, sort in 'Selected method invokes' 'Invokes' column, the value is not sorting correctly.

I will attach screen shots.
Comment 27 Eugene Chan CLA 2008-01-31 15:20:59 EST
Created attachment 88452 [details]
screen shot shows problem in ascd sort
Comment 28 Eugene Chan CLA 2008-01-31 15:21:16 EST
Created attachment 88453 [details]
screen shot shows problem in desc sort
Comment 29 Ritwik Lodhiya CLA 2008-01-31 16:58:40 EST
Created attachment 88475 [details]
Proposed Patch v2.0  

I believe this patch addresses the problems. 
1) Now both "invokes" and "invoked by" columns show correct numbers with proper sorting
2) All commented snippets of codes have been removed
3) Copyright information is updated

If this patch is approved, then this patch will have patched the patch which was meant to have patched a patch that was not meant for this bug :).
Comment 30 Eugene Chan CLA 2008-02-01 14:16:03 EST
The latest path loods good. Good Work Ritwik!
Comment 31 jkubasta CLA 2008-02-01 15:12:55 EST
The affected plugin was moved to the trace project and so the patch cannot be applied as is.  Ritwik can you apply the same changes to org.eclipse.hyades.trace.views?
Comment 32 Ritwik Lodhiya CLA 2008-02-01 15:59:26 EST
Created attachment 88631 [details]
Patch for different plugin

Please review this one, because I have a small concern 
In an empty workspace, I checked out the org.eclipse.hyades.trace.views plugin from trace project and made the necessary modifications on MethodDetailsStatistics.java file. I made the patch and posted it. 

When I checked the patch, it looks exactly the same as the previous patch I had posted. Should I patch differently to accomodate for the change in the plugin's project?
Comment 33 jkubasta CLA 2008-02-01 17:02:15 EST
Patch applied to Head.  Thx Ritwik.
Comment 34 Chris Elford CLA 2008-03-11 17:55:58 EDT
Created attachment 92241 [details]
Example trcxml that fails with 4.5 I5

Should this be working in 4.5 I5?  The attached is a trcxml is from running hello world under 4.5 I5 with a certain set of filters.

Note:

  java.io.ByteArrayOutputStream.write(int) void is called 131114 times.   Its "invokedby section" states that it was invoked by java.util.jar.InitManifest.nextChunk(java.io.InputStream,java...) all 131114 times.  If I go look at java.util.jar.InitManifest.nextChunk and look at its "invokes section", it says that it only invoked java.io.ByteArrayOutputStream.write(int) 1229 times (once for each time it was called).

Similarly, in the display for java.io.ByteArrayOutputStream.write(int), it says that it invokes java.io.ByteArrayOutputStream.expand(int) 131114 times but java.io.ByteArrayOutputStream claims to only have been invoked a total of 2 times.

Thx,
Chris
Comment 35 Alexander N. Alexeev CLA 2008-03-12 06:33:27 EDT
On M5 problem reproduced with Chris's trace
Comment 36 Alexander N. Alexeev CLA 2008-03-12 07:21:08 EDT
Created attachment 92292 [details]
fix for incorrect representation of trace attached by Chris
Comment 37 Chris Elford CLA 2008-03-12 17:58:42 EDT
I have confirmed that this patch works for me.  The numbers for invoked view seem to be consistent now with the numbers for the invokes().

This will make my demo at EclipseCon much more easily explained... :-)

Thx!
Chris
Comment 38 Alexander N. Alexeev CLA 2008-03-16 09:38:40 EDT
change target to current itaration
Comment 39 Alexander N. Alexeev CLA 2008-04-16 09:35:45 EDT
patch for Chris's bug committed to the head.
Record can be closed  
Comment 40 Paul Slauenwhite CLA 2009-06-30 14:01:10 EDT
As of TPTP 4.6.0, TPTP is in maintenance mode and focusing on improving quality by resolving relevant enhancements/defects and increasing test coverage through test creation, automation, Build Verification Tests (BVTs), and expanded run-time execution. As part of the TPTP Bugzilla housecleaning process (see http://wiki.eclipse.org/Bugzilla_Housecleaning_Processes), this enhancement/defect is verified/closed by the Project Lead since this enhancement/defect has been resolved and unverified for more than 1 year and considered to be fixed. If this enhancement/defect is still unresolved and reproducible in the latest TPTP release (http://www.eclipse.org/tptp/home/downloads/), please re-open.