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.ui.cpu;
042:
043: import org.netbeans.lib.profiler.results.cpu.CPUResultsSnapshot;
044: import org.netbeans.lib.profiler.results.cpu.FlatProfileContainer;
045: import org.netbeans.lib.profiler.ui.UIUtils;
046: import org.netbeans.lib.profiler.ui.components.FilterComponent;
047: import java.awt.image.BufferedImage;
048:
049: /**
050: * A display containing a flat profile (always appears together with CCT)
051: *
052: * @author Misha Dmitriev
053: * @author Ian Formanek
054: * @author Jiri Sedlacek
055: */
056: public class SnapshotFlatProfilePanel extends FlatProfilePanel
057: implements ScreenshotProvider {
058: //~ Instance fields ----------------------------------------------------------------------------------------------------------
059:
060: private CPUResultsSnapshot snapshot;
061:
062: //~ Constructors -------------------------------------------------------------------------------------------------------------
063:
064: public SnapshotFlatProfilePanel(
065: CPUResUserActionsHandler actionsHandler) {
066: this (actionsHandler, null);
067: }
068:
069: public SnapshotFlatProfilePanel(
070: CPUResUserActionsHandler actionsHandler,
071: CPUSelectionHandler selectionHandler) {
072: super (actionsHandler, selectionHandler);
073: }
074:
075: //~ Methods ------------------------------------------------------------------------------------------------------------------
076:
077: public BufferedImage getCurrentViewScreenshot(
078: boolean onlyVisibleArea) {
079: if (resTable == null) {
080: return null;
081: }
082:
083: if (onlyVisibleArea) {
084: return UIUtils.createScreenshot(jScrollPane);
085: } else {
086: return UIUtils.createScreenshot(resTable);
087: }
088: }
089:
090: /**
091: * This method is supposed to be used for displaying data obtained in a snapshot. threadId is either an actual
092: * threadId >= 0, or -1 to mean "display data for all threads". When data is initialized in this way, all operations
093: * such as switching views (aggregation level), obtaining reverse call graph, going to method's source, are allowed.
094: */
095: public void setDataToDisplay(CPUResultsSnapshot snapshot,
096: int threadId, int view) {
097: this .snapshot = snapshot;
098: this .currentView = view;
099: this .threadId = threadId;
100: this .flatProfileContainer = null;
101: collectingTwoTimeStamps = snapshot.isCollectingTwoTimeStamps();
102: }
103:
104: public String getDefaultViewName() {
105: return "cpu-hotspots";
106: }
107:
108: public CPUResultsSnapshot getSnapshot() {
109: return snapshot;
110: }
111:
112: public boolean fitsVisibleArea() {
113: return !jScrollPane.getVerticalScrollBar().isEnabled();
114: }
115:
116: protected String[] getMethodClassNameAndSig(int methodId,
117: int currentView) {
118: return snapshot.getMethodClassNameAndSig(methodId, currentView);
119: }
120:
121: protected void obtainResults() {
122: if (snapshot != null) {
123: flatProfileContainer = snapshot.getFlatProfile(threadId,
124: currentView);
125: }
126:
127: // If a now-inapplicable setting remained from previous run, reset it
128: if ((snapshot == null)
129: || (!collectingTwoTimeStamps && (sortBy == FlatProfileContainer.SORT_BY_SECONDARY_TIME))) {
130: sortBy = FlatProfileContainer.SORT_BY_TIME;
131: }
132:
133: // Reinit bar max value here - operations necessary for correct bar representation of results
134: flatProfileContainer.filterOriginalData(FilterComponent
135: .getFilterStrings(filterString), filterType,
136: valueFilterValue);
137: flatProfileContainer.sortBy(sortBy, sortOrder); // This will actually create the below-used percent()
138: // thing for proper timer
139:
140: setResultsAvailable(true);
141: }
142:
143: protected void showReverseCallGraph(int threadId, int methodId,
144: int currentView, int sortingColumn, boolean sortingOrder) {
145: actionsHandler.showReverseCallGraph(snapshot, threadId,
146: methodId, currentView, sortingColumn, sortingOrder);
147: }
148:
149: protected boolean supportsReverseCallGraph() {
150: return true;
151: }
152:
153: protected boolean supportsSubtreeCallGraph() {
154: return false;
155: }
156:
157: protected void updateResults() {
158: if (threadId < -1) {
159: return; // -1 is reserved for all threads merged flat profile; non-negative numbers are actual thread ids
160: }
161:
162: int currentColumnCount = collectingTwoTimeStamps ? 5 : 4;
163:
164: if (columnCount != currentColumnCount) {
165: initColumnsData();
166: } else {
167: if (resTable != null) {
168: saveColumnsData();
169: }
170: }
171:
172: flatProfileContainer.sortBy(sortBy, sortOrder);
173:
174: jScrollPane.setViewportView(resTable);
175: jScrollPane.getViewport().setBackground(
176: resTable.getBackground());
177: }
178: }
|