/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
* add the following below this CDDL HEADER, with the fields enclosed
* by brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2008 Sun Microsystems, Inc.
* Portions Copyright 2012 ForgeRock AS
*/
/**
* This class defines a Directory Server utility that may be used to view
* profile information that has been captured by the profiler plugin. It
* supports viewing this information in either a command-line mode or using a
* simple GUI.
*/
public class ProfileViewer
implements TreeSelectionListener
{
// The root stack frames for the profile information that has been captured.
// A set of stack traces indexed by class and method name.
// The editor pane that will provide detailed information about the selected
// stack frame.
// The GUI tree that will be used to hold stack frame information;
// The total length of time in milliseconds for which data is available.
private long totalDuration;
// The total number of profile intervals for which data is available.
private long totalIntervals;
/**
* Parses the command-line arguments and creates an instance of the profile
* viewer as appropriate.
*
* @param args The command-line arguments provided to this program.
*/
{
// Define the command-line arguments that may be used with this program.
// Create the command-line argument parser for use with this program.
new ArgumentParser("org.opends.server.plugins.profiler.ProfileViewer",
toolDescription, false);
// Initialize all the command-line argument types and register them with the
// parser.
try
{
useGUI = new BooleanArgument(
"usegui", 'g', "useGUI",
displayUsage = new BooleanArgument(
"help", 'H', "help",
}
catch (ArgumentException ae)
{
}
// Parse the command-line arguments provided to this program.
try
{
}
catch (ArgumentException ae)
{
}
// If we should just display usage or versionn information,
// then print it and exit.
if (argParser.usageOrVersionDisplayed())
{
}
// Create the profile viewer and read in the data files.
{
try
{
}
catch (Exception e)
{
}
}
// Write the captured information to standard output or display it in a GUI.
{
viewer.displayGUI();
}
else
{
}
}
/**
* Creates a new profile viewer object without any data. It should be
* populated with one or more calls to <CODE>processDataFile</CODE>
*/
public ProfileViewer()
{
totalDuration = 0;
totalIntervals = 0;
}
/**
* Reads and processes the information in the provided data file into this
* profile viewer.
*
* @param filename The path to the file containing the data to be read.
*
* @throws IOException If a problem occurs while trying to read from the
* data file.
*
* @throws ASN1Exception If an error occurs while trying to decode the
* contents of the file into profile stack objects.
*/
throws IOException, ASN1Exception
{
// Try to open the file for reading.
try
{
// The first element in the file must be a sequence with the header
// information.
// The remaining elements will contain the stack frames.
while (reader.hasNextElement())
{
if (pos < 0)
{
continue;
}
methodNames[pos]);
if (existingFrame == null)
{
}
{
}
}
}
finally
{
try
{
} catch (Exception e) {}
}
}
/**
* Retrieves an array containing the root frames for the profile information.
* The array will be sorted in descending order of matching stacks. The
* elements of this array will be the leaf method names with sub-frames
* holding information about the callers of those methods.
*
* @return An array containing the root frames for the profile information.
*/
{
return frames;
}
/**
* Retrieves the total number of sample intervals for which profile data is
* available.
*
* @return The total number of sample intervals for which profile data is
* available.
*/
public long getTotalIntervals()
{
return totalIntervals;
}
/**
* Retrieves the total duration in milliseconds covered by the profile data.
*
* @return The total duration in milliseconds covered by the profile data.
*/
public long getTotalDuration()
{
return totalDuration;
}
/**
* Prints the profile information to standard output in a human-readable
* form.
*/
public void printProfileData()
{
{
}
}
/**
* Prints the provided stack frame and its subordinates using the provided
* indent.
*
* @param frame The stack frame to be printed, followed by recursive
* information about all its subordinates.
* @param indent The number of tabs to indent the stack frame information.
*/
{
for (int i=0; i < indent; i++)
{
}
if (frame.hasSubFrames())
{
{
}
}
}
/**
* Displays a simple GUI with the profile data.
*/
public void displayGUI()
{
"</BODY></HTML>";
{
return;
}
{
}
splitPane.setOneTouchExpandable(true);
appWindow.setVisible(true);
}
/**
* Recursively adds subordinate nodes to the provided parent node with the
* provided information.
*
* @param parentFrame The stack frame whose children are to be added as
* subordinate nodes of the provided tree node.
* @param parentNode The tree node to which the subordinate nodes are to be
* added.
*/
{
{
return;
}
{
if (hasChildren)
{
}
}
}
/**
* Formats the provided count, padding with leading spaces as necessary.
*
* @param count The count value to be formatted.
* @param length The total length for the string to return.
*
* @return The formatted count string.
*/
{
{
}
}
/**
* Indicates that a node in the tree has been selected or deselected and that
* any appropriate action should be taken.
*
* @param tse The tree selection event with information about the selection
* or deselection that occurred.
*/
{
try
{
{
// Nothing is selected, so we'll use use an empty panel.
return;
}
if (selectedNode == null)
{
// No tree node is selected, so we'll just use an empty panel.
return;
}
// It is possible that this is the root node, in which case we'll empty
// the info pane.
if (! (selectedObject instanceof ProfileStackFrame))
{
return;
}
// There is a tree node selected, so we should convert it to a stack
// frame and display information about it.
{
{
}
{
}
else
{
}
if (count == 1)
{
}
else
{
}
}
{
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
/**
* Appends an HTML representation of the provided stack to the given buffer.
*
* @param stack The stack trace to represent in HTML.
* @param html The buffer to which the HTML version of
* the stack should be appended.
* @param highlightClassAndMethod The name of the class and method that
* should be highlighted in the stack frame.
*/
{
{
{
{
}
{
}
else
{
}
}
else
{
{
}
{
}
else
{
}
}
}
}
}