gate.util.reporting
Class PRTimeReporter

java.lang.Object
  extended by gate.util.reporting.PRTimeReporter
All Implemented Interfaces:
BenchmarkReportable

public class PRTimeReporter
extends Object
implements BenchmarkReportable

A reporter class to generate a report on total time taken by each processing element across corpus.


Field Summary
private  File benchmarkFile
          A handle to the input benchmark file (benchmark.txt).
private static int FILE_CHUNK_SIZE
          Chunk size in which file will be read.
private  Hashtable<String,String> globalTotal
          A Hashtable storing the time taken by each pipeline.
private  double globalValue
          Place holder for storing the total time taken by a pipeline.
private  String htmlElementTree
          A String containing the HTML code to generate collapsible tree for processing elements.
private  String htmlTimeInPercentTree
          A String containing the HTML code to generate collapsible tree for time taken by each processing elements (in %).
private  String htmlTimeTree
          A String containing the HTML code to generate collapsible tree for time taken by each processing elements.
private  int level
          A integer to track tree depth level.
private  String logicalStart
          A marker indicating the start of current logical run.
static String MEDIA_HTML
          This string constant when set as print media indicates that the report is printed in HTML format.
static String MEDIA_TEXT
          This string constant when set as print media indicates that the report is printed in TEXT format.
private static String NL
          An OS independent line separator.
 HashSet<String> pipelineNames
          Names of the given pipeline for which the entries are present in given benchmark file.
private  ArrayList<String> printLines
          An ArrayList containing the lines to be printed in the final text report.
private  String printMedia
          Report media.
private  File reportFile
          Path where to save the report file.
static String SORT_EXEC_ORDER
          This string constant when set as sort order indicates that the processing elements are sorted in the order of their execution.
static String SORT_TIME_TAKEN
          This string constant when set as sort order indicates that the processing elements are sorted in the descending order of processing time taken by a particular element.
private  String sortOrder
          A String specifying the sorting order to be used while displaying the report.
private static int STATUS_ERROR
          Status flag for error exit.
private static int STATUS_NORMAL
          Status flag for normal exit.
private  boolean suppressZeroTimeEntries
          Indicate whether or not to show 0 millisecond entries.
 int validEntries
          An integer containing the count of total valid log entries present in input file provided.
 
Constructor Summary
PRTimeReporter()
          No Argument constructor.
PRTimeReporter(String[] args)
          A constructor to be used while executing from the command line.
 
Method Summary
 Object calculate(Object reportContainer)
          Calculates the sub totals at each level.
 void executeReport()
          A single method to execute report (A command line counter part API ).
private  void generateCollapsibleHTMLTree(LinkedHashMap<String,Object> gStore, boolean suppressZeroTimeEntries)
          Creates three tree like ul/li structures 1.
private  void generateReport()
          Calls store, calculate and printReport for generating the actual report.
 File getBenchmarkFile()
           
 String getLogicalStart()
          Returns the marker indicating logical start of a run.
 String getPrintMedia()
          Returns the name of the media on which report will be generated. e.g. text, HTML.
 File getReportFile()
           
 String getSortOrder()
          Returns the sorting order specified for the report (EXEC_ORDER or TIME_TAKEN).
private  int getTotal(LinkedHashMap<String,Object> reportContainer)
          Calculates the total of the time taken by processing element at each leaf level.
 boolean isSuppressZeroTimeEntries()
          Returns the flag indicating whether or not to suppress the processing elements from the report which took 0 milliseconds.
static void main(String[] args)
          A main method which acts as a entry point while executing a report via command line.
private  void organizeEntries(LinkedHashMap<String,Object> store, String[] tokens, String bTime)
          Generates a tree like structure made up of LinkedHashMap containing the processing elements and time taken by each element totaled at leaf level over corpus.
 void parseArguments(String[] args)
          Parses the report arguments.
private  boolean parseLinesFromLast(byte[] bytearray, Vector<String> lastNlines)
          Ensures that the required line is read from the given file part.
private  void prettyPrint(LinkedHashMap<String,Object> gStore, String separator, boolean suppressZeroTimeEntries)
          Prints a processing elements structure in a tree like format with time taken by each element in milliseconds and in %.
 void printReport(Object reportSource, File outputFile)
          Prints a report as per the value provided for print media option.
private  void printToHTML(LinkedHashMap<String,Object> gStore, File outputFile, boolean suppressZeroTimeEntries)
          Prints a report in HTML format.
private  void printToText(Object reportContainer, File outputFile, boolean suppressZeroTimeEntries)
          Prints benchmark report in text format.
 void setBenchmarkFile(File benchmarkFile)
          Sets the input benchmark file from which the report is generated.
 void setLogicalStart(String logicalStart)
          Sets optionally a string indicating the logical start of a run.
 void setPrintMedia(String printMedia)
          Sets the media on which report will be generated.
 void setReportFile(File reportFile)
          If not set, the default is the file name "report.txt/html" in the system temporary directory.
 void setSortOrder(String sortOrder)
          Sets the sorting order of the report.
 void setSuppressZeroTimeEntries(boolean suppressZeroTimeEntries)
          Allow to suppress the processing elements from the report which took 0 milliseconds.
private  LinkedHashMap sortHashMapByValues(LinkedHashMap passedMap)
          Sorts LinkedHashMap by its values(natural descending order). keeps the duplicates as it is.
private  LinkedHashMap<String,Object> sortReport(LinkedHashMap<String,Object> gStore)
          Sorts the processing element entries inside tree like structure made up of LinkedHashMap.
 Object store(File inputFile)
          Stores GATE processing elements and the time taken by them in an in-memory data structure for report generation.
private  long tail(File fileToBeRead, int chunkSize)
          Reads the given file upside down.
static void usage()
          Display a usage message
private  boolean validateLogEntry(String benchmarkIDChain, ArrayList<String> startTokens)
          Ignores the inconsistent log entries from the benchmark file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MEDIA_TEXT

public static final String MEDIA_TEXT
This string constant when set as print media indicates that the report is printed in TEXT format.

See Also:
Constant Field Values

MEDIA_HTML

public static final String MEDIA_HTML
This string constant when set as print media indicates that the report is printed in HTML format.

See Also:
Constant Field Values

SORT_EXEC_ORDER

public static final String SORT_EXEC_ORDER
This string constant when set as sort order indicates that the processing elements are sorted in the order of their execution.

See Also:
Constant Field Values

SORT_TIME_TAKEN

public static final String SORT_TIME_TAKEN
This string constant when set as sort order indicates that the processing elements are sorted in the descending order of processing time taken by a particular element.

See Also:
Constant Field Values

globalTotal

private Hashtable<String,String> globalTotal
A Hashtable storing the time taken by each pipeline.


printLines

private ArrayList<String> printLines
An ArrayList containing the lines to be printed in the final text report.


NL

private static final String NL
An OS independent line separator.


htmlElementTree

private String htmlElementTree
A String containing the HTML code to generate collapsible tree for processing elements.


htmlTimeTree

private String htmlTimeTree
A String containing the HTML code to generate collapsible tree for time taken by each processing elements.


htmlTimeInPercentTree

private String htmlTimeInPercentTree
A String containing the HTML code to generate collapsible tree for time taken by each processing elements (in %).


level

private int level
A integer to track tree depth level.


globalValue

private double globalValue
Place holder for storing the total time taken by a pipeline.


STATUS_NORMAL

private static final int STATUS_NORMAL
Status flag for normal exit.

See Also:
Constant Field Values

STATUS_ERROR

private static final int STATUS_ERROR
Status flag for error exit.

See Also:
Constant Field Values

validEntries

public int validEntries
An integer containing the count of total valid log entries present in input file provided.


FILE_CHUNK_SIZE

private static final int FILE_CHUNK_SIZE
Chunk size in which file will be read.

See Also:
Constant Field Values

pipelineNames

public HashSet<String> pipelineNames
Names of the given pipeline for which the entries are present in given benchmark file.


benchmarkFile

private File benchmarkFile
A handle to the input benchmark file (benchmark.txt).


suppressZeroTimeEntries

private boolean suppressZeroTimeEntries
Indicate whether or not to show 0 millisecond entries.


printMedia

private String printMedia
Report media.


sortOrder

private String sortOrder
A String specifying the sorting order to be used while displaying the report.


reportFile

private File reportFile
Path where to save the report file.


logicalStart

private String logicalStart
A marker indicating the start of current logical run.

Constructor Detail

PRTimeReporter

public PRTimeReporter()
No Argument constructor.


PRTimeReporter

PRTimeReporter(String[] args)
A constructor to be used while executing from the command line.

Parameters:
args - array containing command line arguments.
Method Detail

store

public Object store(File inputFile)
             throws BenchmarkReportInputFileFormatException
Stores GATE processing elements and the time taken by them in an in-memory data structure for report generation.

Specified by:
store in interface BenchmarkReportable
Parameters:
inputFile - A File handle of the input log file.
Returns:
An Object of type LinkedHashMap containing the processing elements (with time in milliseconds) in hierarchical structure. Null if there was an error.
Throws:
BenchmarkReportInputFileFormatException

organizeEntries

private void organizeEntries(LinkedHashMap<String,Object> store,
                             String[] tokens,
                             String bTime)
Generates a tree like structure made up of LinkedHashMap containing the processing elements and time taken by each element totaled at leaf level over corpus.

Parameters:
store - An Object of type LinkedHashMap containing the processing elements (with time in milliseconds) in hierarchical structure.
tokens - An array consisting of remaining benchmarkID tokens except the one being processed.
bTime - time(in milliseconds) of the benchmarkID token being processed.

sortReport

private LinkedHashMap<String,Object> sortReport(LinkedHashMap<String,Object> gStore)
Sorts the processing element entries inside tree like structure made up of LinkedHashMap. Entries will be sorted in descending order of time taken.

Parameters:
gStore - An Object of type LinkedHashMap containing the processing elements (with time in milliseconds) in hierarchical structure.
Returns:
An Object of type LinkedHashMap containing the processing elements sorted in descending order of processing time taken.

sortHashMapByValues

private LinkedHashMap sortHashMapByValues(LinkedHashMap passedMap)
Sorts LinkedHashMap by its values(natural descending order). keeps the duplicates as it is.

Parameters:
passedMap - An Object of type LinkedHashMap to be sorted by its values.
Returns:
An Object containing the sorted LinkedHashMap.

calculate

public Object calculate(Object reportContainer)
Calculates the sub totals at each level.

Specified by:
calculate in interface BenchmarkReportable
Parameters:
reportContainer - An Object of type LinkedHashMap containing the processing elements (with time in milliseconds) in hierarchical structure.
Returns:
An Object containing modified hierarchical structure of processing elements with totals and All others embedded in it.

getTotal

private int getTotal(LinkedHashMap<String,Object> reportContainer)
Calculates the total of the time taken by processing element at each leaf level. Also calculates the difference between the actual time taken by the resources and system noted time.

Parameters:
reportContainer - An Object of type LinkedHashMap containing the processing elements (with time in milliseconds) in hierarchical structure.
Returns:
An integer containing the sub total.

printReport

public void printReport(Object reportSource,
                        File outputFile)
Prints a report as per the value provided for print media option.

Specified by:
printReport in interface BenchmarkReportable
Parameters:
reportSource - An Object of type LinkedHashMap containing the processing elements (with time in milliseconds) in hierarchical structure.
outputFile - Path where to save the report.

printToText

private void printToText(Object reportContainer,
                         File outputFile,
                         boolean suppressZeroTimeEntries)
Prints benchmark report in text format.

Parameters:
reportContainer - An Object of type LinkedHashMap containing the processing elements (with time in milliseconds) in hierarchical structure.
outputFile - An object of type File representing the output report file.
suppressZeroTimeEntries - Indicate whether or not to show 0 millisecond entries.

prettyPrint

private void prettyPrint(LinkedHashMap<String,Object> gStore,
                         String separator,
                         boolean suppressZeroTimeEntries)
Prints a processing elements structure in a tree like format with time taken by each element in milliseconds and in %.

Parameters:
gStore - An Object of type LinkedHashMap containing the processing elements (with time in milliseconds) in hierarchical structure.
separator - A String separator to indent the processing elements in tree like structure.
suppressZeroTimeEntries - Indicate whether or not to show 0 millisecond entries.

printToHTML

private void printToHTML(LinkedHashMap<String,Object> gStore,
                         File outputFile,
                         boolean suppressZeroTimeEntries)
Prints a report in HTML format. The output report will be represented as collapsible ul/li structure.

Parameters:
gStore - An Object of type LinkedHashMap containing the processing elements (with time in milliseconds) in hierarchical structure.
outputFile - An object of type File representing the output report file to which the HTML report is to be written.
suppressZeroTimeEntries - Indicate whether or not to show 0 millisecond entries.

generateCollapsibleHTMLTree

private void generateCollapsibleHTMLTree(LinkedHashMap<String,Object> gStore,
                                         boolean suppressZeroTimeEntries)
Creates three tree like ul/li structures 1. A tree to represent processing elements 2. A tree to represent time taken by processing elements 3. A tree to represent time taken by processing elements in %.

Parameters:
gStore - An Object of type LinkedHashMap containing the processing elements (with time in milliseconds) in hierarchical structure.
suppressZeroTimeEntries - Indicate whether or not to show 0 millisecond entries.

parseLinesFromLast

private boolean parseLinesFromLast(byte[] bytearray,
                                   Vector<String> lastNlines)
Ensures that the required line is read from the given file part.

Parameters:
bytearray - A part of a file being read upside down.
lastNlines - A vector containing the lines extracted from file part.
Returns:
true if marker indicating the logical start of run is found; false otherwise.

tail

private long tail(File fileToBeRead,
                  int chunkSize)
           throws BenchmarkReportInputFileFormatException
Reads the given file upside down.

Parameters:
fileToBeRead - An object of type File representing the file to be read.
chunkSize - An integer specifying the size of the chunks in which file will be read.
Returns:
A long value pointing to the start position of the given file chunk.
Throws:
BenchmarkReportInputFileFormatException

validateLogEntry

private boolean validateLogEntry(String benchmarkIDChain,
                                 ArrayList<String> startTokens)
Ignores the inconsistent log entries from the benchmark file. Entries from modules like pronominal coreferencer which have not been converted to new benchmarking conventions are ignored.

Parameters:
benchmarkIDChain - The chain of benchmark ids. This is the third token in the benchmark file.
startTokens - An array of first tokens in the benchmark id chain.
Returns:
true if valid log entry; false otherwise.

parseArguments

public void parseArguments(String[] args)
Parses the report arguments.

Specified by:
parseArguments in interface BenchmarkReportable
Parameters:
args - A string array containing the command line arguments.

usage

public static void usage()
Display a usage message


main

public static void main(String[] args)
                 throws BenchmarkReportInputFileFormatException
A main method which acts as a entry point while executing a report via command line.

Parameters:
args - A string array containing the command line arguments.
Throws:
BenchmarkReportInputFileFormatException

generateReport

private void generateReport()
                     throws BenchmarkReportInputFileFormatException
Calls store, calculate and printReport for generating the actual report.

Throws:
BenchmarkReportInputFileFormatException

executeReport

public void executeReport()
                   throws BenchmarkReportInputFileFormatException
Description copied from interface: BenchmarkReportable
A single method to execute report (A command line counter part API ). Call this method after setting the report parameters.

Specified by:
executeReport in interface BenchmarkReportable
Throws:
BenchmarkReportInputFileFormatException

isSuppressZeroTimeEntries

public boolean isSuppressZeroTimeEntries()
Returns the flag indicating whether or not to suppress the processing elements from the report which took 0 milliseconds.

Returns:
suppressZeroTimeEntries A boolean indicating whether or not to suppress zero time entries.

setSuppressZeroTimeEntries

public void setSuppressZeroTimeEntries(boolean suppressZeroTimeEntries)
Allow to suppress the processing elements from the report which took 0 milliseconds.

Parameters:
suppressZeroTimeEntries - if true suppress zero time entries. This Parameter is ignored if SortOrder specified is SORT_TIME_TAKEN. True by default.

getPrintMedia

public String getPrintMedia()
Returns the name of the media on which report will be generated. e.g. text, HTML.

Returns:
printMedia A String containing the name of the media on which report will be generated.

setPrintMedia

public void setPrintMedia(String printMedia)
Sets the media on which report will be generated.

Parameters:
printMedia - Type of media on which the report will be generated. Must be MEDIA_TEXT or MEDIA_HTML. The default is MEDIA_HTML.

getSortOrder

public String getSortOrder()
Returns the sorting order specified for the report (EXEC_ORDER or TIME_TAKEN).

Returns:
sortOrder A String containing the sorting order.

setSortOrder

public void setSortOrder(String sortOrder)
Sets the sorting order of the report.

Parameters:
sortOrder - Sorting order of the report. Must be SORT_EXEC_ORDER or SORT_TIME_TAKEN. Default is SORT_EXEC_ORDER.

getLogicalStart

public String getLogicalStart()
Returns the marker indicating logical start of a run.

Returns:
logicalStart A String containing the marker indicating logical start of a run.

setLogicalStart

public void setLogicalStart(String logicalStart)
Sets optionally a string indicating the logical start of a run.

Parameters:
logicalStart - A String indicating the logical start of a run. Useful when you you have marked different runs in your benchmark file with this string at their start. By default the value is null.

getBenchmarkFile

public File getBenchmarkFile()
Returns:
benchmarkFile path to input benchmark file.
See Also:
setBenchmarkFile(java.io.File)

setBenchmarkFile

public void setBenchmarkFile(File benchmarkFile)
Sets the input benchmark file from which the report is generated. By default use the file named "benchmark.txt" from the application execution directory.

Parameters:
benchmarkFile - Input benchmark file.

getReportFile

public File getReportFile()
Returns:
reportFile file path where the report file is written.
See Also:
setReportFile(java.io.File)

setReportFile

public void setReportFile(File reportFile)
If not set, the default is the file name "report.txt/html" in the system temporary directory.

Parameters:
reportFile - file path to the report file to write.