blob: e4d7e6957b15e9a062a4afe784c1ce71acca742c [file] [log] [blame]
Jayanth Othayoth9e95f4b2017-07-24 06:42:24 -05001#! /bin/bash
2
3help=$"
4 dreport creates an archive(xz compressed) consisting of the following:
5 * Configuration information
6 * Debug information
7 * A summary report
8 The type parameter controls the content of the data. The generated
9 archive is stored in the user specified location.
10
11usage: dreport [OPTION]
12
13Options:
14 -n, —-name <name> Name to be used for the archive.
15 Default name format obmcdump_<id>_<epochtime>
16 -d, —-dir <directory> Archive directory to copy the compressed report.
17 Default output directory is /tmp/dreport
18 -i, —-id <id> Dump identifier to associate with the archive.
19 Identifiers include numeric characters.
20 Default dump identifier is 0
21 -t, —-type <type> Data collection type. Valid types are
22 "user", "core".
23 Default type is "user" initiated.
24 -f, —-file <file> Optional file to be included in the archive.
25 Absolute path of the file must be passed as
26 parameter. This is useful to include application
27 core in the dump.
28 -s, --size <size> Maximum allowed size(in KB) of the archive.
29 Report will be truncated in case size exceeds
30 this limit. Default size is 500KB.
31 -v, —-verbose Increase logging verbosity.
32 -V, --version Output version information.
33 -q, —-quiet Only log fatal errors to stderr
34 -h, —-help Display this help and exit.
35"
36
Jayanth Othayoth7b774872017-07-26 05:02:53 -050037#CONSTANTS
38declare -r TRUE=1
39declare -r FALSE=0
40declare -r USERINITIATED_TYPE=0
41declare -r APPLICATIONCORED_TYPE=1
42declare -r DUMP_MAX_SIZE=500 #in KB
Jayanth Othayoth6d3ee1c2017-07-26 05:18:31 -050043declare -r SUMMARY_LOG="summary.log"
44declare -r DREPORT_LOG="dreport.log"
45declare -r TMP_DIR="/tmp/dreport"
Jayanth Othayoth7b774872017-07-26 05:02:53 -050046
47#VARIABLES
48declare -x name=$"obmcdump_00000000_$(date +"%s")"
49declare -x dump_dir=$TMP_DIR
Jayanth Othayoth6d3ee1c2017-07-26 05:18:31 -050050declare -x dump_id=0
Jayanth Othayoth7b774872017-07-26 05:02:53 -050051declare -x dump_type=$USERINITIATED_TYPE
52declare -x verbose=$FALSE
53declare -x quiet=$FALSE
54declare -x dump_size=$DUMP_MAX_SIZE
Jayanth Othayoth6d3ee1c2017-07-26 05:18:31 -050055declare -x name_dir="$TMP_DIR/$dump_id/$name"
Jayanth Othayoth7b774872017-07-26 05:02:53 -050056
57# PACKAGE VERSION
58PACKAGE_VERSION="0.0.1"
59
Jayanth Othayoth6d3ee1c2017-07-26 05:18:31 -050060# @brief log the error message
61# @param error message
62function log_error()
63{
64 echo "ERROR: $@" >>"$name_dir/$DREPORT_LOG"
65 if ((quiet != TRUE)); then
66 echo "ERROR: $@" >&2
67 fi
68}
69
70# @brief log warning message
71# @param warning message
72function log_warning()
73{
74 if ((verbose == TRUE)); then
75 echo "WARNING: $@" >>"$name_dir/$DREPORT_LOG"
76 if ((quiet != TRUE)); then
77 echo "WARNING: $@" >&2
78 fi
79 fi
80}
81
82# @brief log info message
83# @param info message
84function log_info()
85{
86 if ((verbose == TRUE)); then
87 echo "INFO: $@" >>"$name_dir/$DREPORT_LOG"
88 if ((quiet != TRUE)); then
89 echo "INFO: $@" >&1
90 fi
91 fi
92}
93
94# @brief log summary message
95# @param message
96function log_summary()
97{
98 echo "$@" >> "$name_dir/$SUMMARY_LOG"
99 if ((quiet != TRUE)); then
100 echo "$@" >&1
101 fi
102}
103
Jayanth Othayoth7b774872017-07-26 05:02:53 -0500104# @brief Main function
105function main()
106{
Jayanth Othayoth6d3ee1c2017-07-26 05:18:31 -0500107 mkdir -p "$TMP_DIR/$dump_id/$name"
108 if [ $? -ne 0 ]; then
109 log_error "Failed to create the temporary directory."
110 exit;
111 fi
112
113 log_summary "Version: $PACKAGE_VERSION"
Jayanth Othayoth7b774872017-07-26 05:02:53 -0500114}
115
116TEMP=`getopt -o n:d:i:t:s:f:vVqh \
117 --long name:,dir:,dumpid:,type:,size:,file:,verbose,version,quiet,help \
118 -- "$@"`
119eval set -- "$TEMP"
120
121while [[ $# -gt 1 ]]; do
122 key="$1"
123 case $key in
124 -n|--name)
125 name=$2
126 shift 2;;
127 -d|--dir)
128 dir=$2
129 shift 2;;
130 -i|--dumpid)
131 dump_id=$2
132 shift 2;;
133 -t|--type)
134 dump_type=$2
135 shift 2;;
136 -s|--size)
137 dump_size=$2
138 shift 2;;
139 -f|--file)
140 dump_file=$2
141 shift 2;;
142 -v|—-verbose)
143 verbose=$TRUE
144 shift;;
145 -V|--version)
146 shift;;
147 -q|—-quiet)
148 quiet=$TRUE
149 shift;;
150 -h|--help)
151 echo "$help"
152 exit;;
153 *) # unknown option
Jayanth Othayoth6d3ee1c2017-07-26 05:18:31 -0500154 log_error "Unknown argument: $1"
155 log_info "$help"
Jayanth Othayoth7b774872017-07-26 05:02:53 -0500156 exit 1;;
157 esac
Jayanth Othayoth9e95f4b2017-07-24 06:42:24 -0500158done
Jayanth Othayoth7b774872017-07-26 05:02:53 -0500159
160main #main program
161exit $?