| 1 |
#!/bin/bash |
| 2 |
# |
| 3 |
# HistogramLogProcessor |
| 4 |
# |
| 5 |
# Written by Gil Tene, and released to the public domain, as explained at |
| 6 |
# http://creativecommons.org/publicdomain/zero/1.0/ |
| 7 |
# |
| 8 |
# ******************************************************************** |
| 9 |
# |
| 10 |
# HistogramLogProcessor will process an input log and can generate two |
| 11 |
# different log files from a single histogram log file: a |
| 12 |
# sequential interval log file and a histogram log file. |
| 13 |
# |
| 14 |
# The sequential interval log file logs a single %'ile stats line for |
| 15 |
# each reporting interval. |
| 16 |
# |
| 17 |
# The histogram percentile log file includes a detailed %'ile histogram |
| 18 |
# of the entire log file range processed. |
| 19 |
# |
| 20 |
# HistogramLogProcessor will process an input log file when provided with |
| 21 |
# the -i <filename> option. When no -i option is provided, standard input |
| 22 |
# will be processed. |
| 23 |
# |
| 24 |
# When provided with an output file name <logfile> with the -o option |
| 25 |
# (e.g. "-o mylog"), HistogramLogProcessor will produce both output files |
| 26 |
# under the names <logfile> and <logfile>.hgrm (e.g. mylog and mylog.hgrm). |
| 27 |
# |
| 28 |
# When not provided with an output file name, HistogramLogProcessor will |
| 29 |
# produce [only] the histogram percentile log output to standard output. |
| 30 |
# |
| 31 |
# HistogramLogProcessor accepts optional -start and -end time range |
| 32 |
# parameters. When provided, the output will only reflect the portion |
| 33 |
# of the input log with timestamps that fall within the provided start |
| 34 |
# and end time range parameters. |
| 35 |
# |
| 36 |
# HistogramLogProcessor also accepts and optional -csv parameter, which |
| 37 |
# will cause the output formatting (of both output file forms) to use |
| 38 |
# a CSV file format. |
| 39 |
# |
| 40 |
# Use HistogramLogProcessor -h for more info |
| 41 |
# |
| 42 |
|
| 43 |
# Figure out installed path: |
| 44 |
# On Linux, we'd do the following: |
| 45 |
# PARSED_SCRIPT=`readlink -f $0` |
| 46 |
# INSTALLED_PATH=`dirname $PARSED_SCRIPT` |
| 47 |
# But readlink -f doesn't work the same everywhere (e.g. Mac OS). We use this instead: |
| 48 |
function readlink_f () { _=`pwd`; cd `dirname $1` && echo `pwd` && cd $_; } |
| 49 |
INSTALLED_PATH=$(readlink_f $0) |
| 50 |
|
| 51 |
# Check if running from unpacked distribution archive by assuming HdrHistogram.jar |
| 52 |
# in the same directory as this script. If not, try to search in target/ directory |
| 53 |
# (running from the source repository build). |
| 54 |
HDRHISTOGRAM_JAR_FILE=$INSTALLED_PATH/HdrHistogram.jar |
| 55 |
if [ ! -f $HDRHISTOGRAM_JAR_FILE ] ; then |
| 56 |
HDRHISTOGRAM_JAR_FILE=$INSTALLED_PATH/target/HdrHistogram.jar |
| 57 |
fi |
| 58 |
|
| 59 |
JAVA_BIN=`which java` |
| 60 |
|
| 61 |
if [ $JAVA_HOME ]; then |
| 62 |
JAVA_CMD=$JAVA_HOME/bin/java |
| 63 |
elif [ $JAVA_BIN ]; then |
| 64 |
JAVA_CMD=$JAVA_BIN |
| 65 |
else |
| 66 |
echo "For this command to run, either $JAVA_HOME must be set, or java must be in the path." |
| 67 |
exit 1 |
| 68 |
fi |
| 69 |
|
| 70 |
# Deal with Windows/cygwin path normalization syntax needs: |
| 71 |
# Key Assumption: only cygwin/Windows installations will have a cygpath command... |
| 72 |
cygpath -w $HDRHISTOGRAM_JAR_FILE &> /dev/null |
| 73 |
if [ $? -eq 0 ] ; then |
| 74 |
# if using cygwin, use valid windows-style classpath |
| 75 |
HDRHISTOGRAM_JAR_FILE=`cygpath -w $HDRHISTOGRAM_JAR_FILE` |
| 76 |
echo Windows path for hiccup jar file is $HDRHISTOGRAM_JAR_FILE |
| 77 |
fi |
| 78 |
|
| 79 |
exec $JAVA_CMD -cp $HDRHISTOGRAM_JAR_FILE org.HdrHistogram.HistogramLogProcessor $@ |
| 80 |
#exec $CMD |