Count and Size different in API and UI

Questions about YourKit Java Profiler
Post Reply
jagadeesh
Posts: 5
Joined: Wed Nov 17, 2004 11:29 pm

Count and Size different in API and UI

Post by jagadeesh »

I used API to collect >200 snapshots. I wrote code to print out the object count, shallow size, and the retained size for four packages:
  • *
    com.smp.common.coremodel.*,
    com.smp.common.performance.*,
    com.mcdata.mpii.*
from all these snapshots. My plan is to cut-and-paste this comma generated content into an excel sheet and plot the growth over time.

Except for the coremodel package, the statistics for the other packages check out correctly with the numbers in the profiler UI. The object count, the shallow size, and the retained size from API for the coremodel package consistently do not match with the numbers in the profiler UI.

I checked my code and the profiler UI carefully many times. I can not find a mistake in my code. What else can I check or do to make progress?

I am enclosing the analysis code in case you are in a magnanimous mood today. I am looking for some possible causes that I have not considered yet and some troubleshooting tips.

Thanks
Jagadeesh

Code: Select all

    public void analysis()
    {
        final String all = "<objects class=\"*\"/>";
        final String coremodel = "<objects class=\"com.smp.common.coremodel.*\"/>";
        final String coremodelretained = "<retained-objects>" + coremodel + "</retained-objects>";
        final String performance = "<objects class=\"com.smp.common.performance.*\"/>";
        final String performanceretained = "<retained-objects>" + performance + "</retained-objects>";
        final String mpii = "<objects class=\"com.mcdata.mpii.*\"/>";
        final String mpiiretained = "<retained-objects>" + mpii + "</retained-objects>";

        System.out.println("Total Count, Total Shallow, CM count, CM Shallow, CM Retained, Perf count, Perf Shallow, Perf Retained, mpii count, mpii Shallow, mpii Retained, file name");
        for(int i=0; max == -1 || i<max; i++) {
            String snapshotFileName = snapshotName(i)+".memory";
            File snapshotFile = new File(snapshotFileName);
            if (!snapshotFile.exists()) {
                // end of snapshots..
                System.out.println("File "+snapshotFileName+" does not exist");
                break;
            }
            try {
                // Load snapshot for analysis
                final MemorySnapshot snapshot = new MemorySnapshot(snapshotFile, null, null);

                // Get and print some statistics
                System.out.print(""+i+",");
                System.out.print("" + snapshot.getObjectCount(all));
                System.out.print(",");
                System.out.print("" + snapshot.getShallowSize(all));
                System.out.print(",");
                System.out.print("" + snapshot.getObjectCount(coremodel));
                System.out.print(",");
                System.out.print("" + snapshot.getShallowSize(coremodel));
                System.out.print(",");
                System.out.print("" + snapshot.getShallowSize(coremodelretained));
                System.out.print(",");
                System.out.print("" + snapshot.getObjectCount(performance));
                System.out.print(",");
                System.out.print("" + snapshot.getShallowSize(performance));
                System.out.print(",");
                System.out.print("" + snapshot.getShallowSize(performanceretained));
                System.out.print(",");
                System.out.print("" + snapshot.getObjectCount(mpii));
                System.out.print(",");
                System.out.print("" + snapshot.getShallowSize(mpii));
                System.out.print(",");
                System.out.print("" + snapshot.getShallowSize(mpiiretained));
                System.out.print(",");
                System.out.print(snapshotFileName);
                System.out.println();
            }
            catch (Exception ex) {
                System.out.println("Cannot load captured snapshot. Reason: " + ex.getMessage());
                ex.printStackTrace();
            }
        }
    }
jagadeesh
Posts: 5
Joined: Wed Nov 17, 2004 11:29 pm

Another question: the package count in UI vs API

Post by jagadeesh »

No one added any bit of information to this. Let me ask a more specific question.

Assume a package pkgA.
pkgA contains three classes c1, c2, c3

A point-in-time memory snapshot of an application is taken that contains instances from these classes. Upon opening the snapshot in the profiler UI, in the All Objects tab, 'class tree' is selected and it is noticed that pkgA has one instance with some retained memory. Expanding the pkgA tree shows that c1 owns that instance.

Using the API, the object count for "pkgA.*" is determined to be, say 100.

What explains this difference? Why does the UI not show the number of instances of the other classes (except those of c1) in the pkgA? Could it be because their retained memory is insignificant?

Thanks.
Post Reply