Introduction

These are light weight tools developed in leisure to be able to generate some metrics related to module states, startup time and memory consumption of GlassFish distributions. The module modularity-scripts contain simple shell scripts that help generate reports on few metrics using glassfish distro. The dependency-analyser module generates a report by analysing the dependencies among OSGI modules and the packages that wire them together. The graphic visualizer tool generates directed graphs which depict dependencies among OSGI bundles using the wires.xml and bundles.xml that is generated by dependency-analyser module.

Download Tools

 The modularity tools are available at the following location. Please check out your local svn copy from here.

  https://svn.java.net/svn/glassfish~svn/trunk/modularity-tools

 Instructions

 Modularity-Scripts

cd ./modularity-tools/modularity-scripts

The scripts contained here are used to collect statistics on paramaeters like number of OSGI modules and their states, startup time and the memory consumed when any distribution of glassfish is run.

Below is a brief explanation on how to run the scripts and the expected parameters to be provided.

GF_HOME = Glassfish home to the depth ~/../../glassfish3/glassfish
TARGET_DIRECTORY = Directory path where results need to be populated
STATS_XML_FILE_NAME = XML file name for collecting OSGI module statistics
TIME_XML_FILE_NAME = XML file name for collecting startup time statistics
MEMORY_XML_FILE_NAME = XML file name for collecting memory statistics
LOG_FILE_NAME = log file name
APP_PATH = path to the archive that needs to be deployed (Sample Applications are bundled in the source under scripts directory)
ID = Any unique identifier for the run
FILE_NAME_MATCH = match the file name for which aggregate report is needed
TYPE = type for which report is needed; allowed types are "MODULE/TIME/MEMORY/STATE"
OUTPUT_DIR = output directory for aggregated reports
OUTPUT_XML_FILE_NAME = file name for aggregated report
OUTPUT_HTML_FILE_NAME = file name for HTML graph visulaization

1. startup_stats.sh

The script collects parameters on OSGI modules, startup time and memory when Glassfish starts up.

Usage: ./startup_stats.sh GF_HOME ID(REVISION) TARGET_DIRECTORY STATS_XML_FILE_NAME TIME_XML_FILE_NAME MEMORY_XML_FILE_NAME LOG_FILE_NAME

2. deploy_stats.sh

The script collects parameters on OSGI modules, deployment time and memory when an application is deployed.

Usage: ./deploy_stats.sh GF_HOME ID(REVISION) TARGET_DIRECTORY STATS_XML_FILE_NAME TIME_XML_FILE_NAME MEMORY_XML_FILE_NAME LOG_FILE_NAME APP_PATH

3. generate_xml_html.sh

The script collects parameters from all previous runs and prepares a summary HTML report of all parameters and also graphic visualization of the same.

Usage: ./generate_xml_html.sh TARGET_DIRECTORY FILE_NAME_MATCH TYPE OUTPUT_DIR OUTPUT_XML_FILE_NAME OUTPUT_HTML_FILE_NAME

Sample Applications are also bundled here for usage with script deploy_stats.sh. The bundled applications includes a simple webapp, an EJB app and also a full fledged enterprise application.

 Dependency-Analyser

cd ./modularity-tools/dependency-analyser

To analyse OSGi metadata of various bundles in a glassfish distribution. 

mvn clean install

 ./run-package-analyser.sh path-to-glassfish-modules-directory bundles.xml wires.xml duplicate.txt unused.txt
 
where,
 
1) bundles.xml: For each bundle, it contains symbolic name, exported package details and imported package details. Exported packages are further divided into two segments: used and unused. If an exported package is not imported by any other module than the exporter, it is considered an unused package.
2) duplicate.txt: Contains packages that are duplicated in various bundles.

3) wires.xml: Tries to match importers with exporters. There is a wires.xsl as well. So, if you open this file in a browser, you will get a nice tabular report. The wiring details may not be totally correct, because I just try to match package names without considering version constraint or attribute matching.

4) unused.txt: Contains list of exported packages that are never imported by anyone other the exporting bundle. We have quite a large number of such packages (do a wc on the file to know the number). As I write, almost two thirds of our exported packages are unused.

Maven Plugin

The tool is part of modularity-maven-plugin. The goal name is analyse-packages. To invoke the maven plugin, you need to use one of the distribution (e.g., nucleus/web/glassfish) pom.xml.

e.g.   mvn -f /space/workspace/glassfish/trunk/main/appserver/distributions/glassfish/pom.xml org.glassfish.modularity:modularity-maven-plugin:analyse-packages

For more information on this module please read this wiki page: https://wikis.oracle.com/display/GlassFish/OsgiPkgDepAnalyser

 Dependency-Visualizer

This module reads a wires.xml and bundles.xml file generated by the dependency-analyser and outputs a dot file. Uses [GraphViz](http://www.graphviz.org/) to create images from the generated dot file. The tool helps visualizing the wiring dependencies between packages.The tool also supports viewing the dependencies of only a subset of the packages, a set of modules given in a file as input, a single module by name and also a an XML file report containing metrics.

*To use the tool*
0. Install graphviz(http://www.graphviz.org/) in your machine.
1. Follow the steps below:

    - run mvn clean install

   - run mvn assembly:assembly to generate the visualizer jar

    - generate a wires.xml and bundles.xml using the dependency-verifier project for the modules that needs to be analyzed
  

 To visualize the dependencies of packages that have the word "web" in them,

run "./subset.sh web".

 To visualize the dependencies among a set of bundles either within themselves or the rest of the bundles use options set/all like below. Please note the module names in file should be new line separated.

run "./file.sh file_name set/all"

 To visualize the dependencies  of a bundle with other bundles use options imports/exports/both with script below below.

run "./module.sh module_name imports/exports/both"

 To generate an XML report containing a number of useful metrics run the script below.

run "./generateXML.sh"

 To draw diagrams for all bundles in given wires.xml; collect all module names in a file named "ModuleNames.txt" and run the script below. You can easily collect all module names by using the following command ./../glassfish4/glassfish/bin/asadmin list-modules | grep 'OSGiModuleImpl:: Bundle' | sed "s/^.Bundle = [//" | sed "s/ [.$//" > ModuleNames.txt

run "./DrawAll.sh"