001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: * The Original Software is NetBeans. The Initial Developer of the Original
026: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
027: * Microsystems, Inc. All Rights Reserved.
028: *
029: * If you wish your version of this file to be governed by only the CDDL
030: * or only the GPL Version 2, indicate your decision by adding
031: * "[Contributor] elects to include this software in this distribution
032: * under the [CDDL or GPL Version 2] license." If you do not indicate a
033: * single choice of license, a recipient has the option to distribute
034: * your version of this file under either the CDDL, the GPL Version 2 or
035: * to extend the choice of license to its licensees as provided above.
036: * However, if you add GPL Version 2 code and therefore, elected the GPL
037: * Version 2 license, then the option applies only if the new code is
038: * made subject to such option by the copyright holder.
039: */
040:
041: package org.netbeans.lib.profiler.results.cpu;
042:
043: import java.util.ResourceBundle;
044:
045: /**
046: * A container for all threads merged CPU data. Currently supports/provides only flat profile data.
047: *
048: * @author Misha Dmitriev
049: */
050: public class AllThreadsMergedCPUCCTContainer extends CPUCCTContainer {
051: //~ Static fields/initializers -----------------------------------------------------------------------------------------------
052:
053: // -----
054: // I18N String constants
055: private static final ResourceBundle messages = ResourceBundle
056: .getBundle("org.netbeans.lib.profiler.results.cpu.Bundle"); // NOI18N
057: private static final String ALL_THREADS_STRING = messages
058: .getString("AllThreadsMergedCPUCCTContainer_AllThreadsString"); // NOI18N
059: // -----
060:
061: //~ Instance fields ----------------------------------------------------------------------------------------------------------
062:
063: protected int view;
064:
065: //~ Constructors -------------------------------------------------------------------------------------------------------------
066:
067: public AllThreadsMergedCPUCCTContainer(
068: CPUResultsSnapshot cpuResSnapshot,
069: PrestimeCPUCCTNode[] rootNodeSubNodes, int view) {
070: super (cpuResSnapshot);
071: this .threadId = -1;
072: this .threadName = ALL_THREADS_STRING;
073: this .view = view;
074: collectingTwoTimeStamps = cpuResSnapshot
075: .isCollectingTwoTimeStamps();
076:
077: compactData = new byte[OFS_SUBNODE02];
078: setNCallsForNodeOfs(0, 1); // 1 call for "All threads" node looks more logical than 0 calls
079: rootNode = new PrestimeCPUCCTNodeBacked(this , rootNodeSubNodes);
080:
081: // Calculate the total execution time for all threads by just summing individual thread total times
082: long time = 0;
083:
084: for (int i = 0; i < rootNodeSubNodes.length; i++) {
085: time += rootNodeSubNodes[i].getTotalTime0();
086: }
087:
088: wholeGraphNetTime0 = time;
089: setTotalTime0ForNodeOfs(0, time);
090:
091: if (collectingTwoTimeStamps) {
092: time = 0;
093:
094: for (int i = 0; i < rootNodeSubNodes.length; i++) {
095: time += rootNodeSubNodes[i].getTotalTime1();
096: }
097:
098: wholeGraphNetTime1 = time;
099: setTotalTime1ForNodeOfs(0, time);
100: }
101: }
102:
103: //~ Methods ------------------------------------------------------------------------------------------------------------------
104:
105: public String[] getMethodClassNameAndSig(int methodId) {
106: return cpuResSnapshot.getMethodClassNameAndSig(methodId, view);
107: }
108:
109: protected FlatProfileContainer generateFlatProfile() {
110: preGenerateFlatProfile();
111:
112: PrestimeCPUCCTNode[] children = (PrestimeCPUCCTNode[]) rootNode
113: .getChildren();
114:
115: for (int i = 0; i < children.length; i++) {
116: CPUCCTContainer childContainer = children[i].getContainer();
117: childContainer.timePerMethodId0 = this .timePerMethodId0;
118: childContainer.timePerMethodId1 = this .timePerMethodId1;
119: childContainer.invPerMethodId = this .invPerMethodId;
120:
121: childContainer.addFlatProfTimeForNode(0);
122:
123: childContainer.timePerMethodId0 = childContainer.timePerMethodId1 = null;
124: childContainer.invPerMethodId = null;
125: }
126:
127: return postGenerateFlatProfile();
128: }
129:
130: protected PrestimeCPUCCTNodeFree generateReverseCCT(int methodId) {
131: PrestimeCPUCCTNode[] children = (PrestimeCPUCCTNode[]) rootNode
132: .getChildren();
133:
134: PrestimeCPUCCTNodeFree rev = null;
135:
136: for (int i = 0; i < children.length; i++) {
137: CPUCCTContainer childContainer = children[i].getContainer();
138:
139: if (rev == null) {
140: rev = childContainer.generateReverseCCT(methodId);
141: } else {
142: childContainer.addToReverseCCT(rev, methodId);
143: }
144: }
145:
146: return rev;
147: }
148: }
|