summaryrefslogtreecommitdiff
path: root/ndb/home/bin/signallog2html.sh
blob: 5665275807cbabf864b668e234dc7d5195812960 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
#!/bin/sh
# NAME
#   signallog2html.sh
#
# SYNOPSIS
#   signallog2html.sh [ -b <block_name | ALL> ] [ -s <signal_id> ] -f signal_log_file
#
# DESCRIPTION
#   Creates a signal sequence diagram in HTML format that can be
#   viewed from a web browser.  The HTML file is created from a signal
#   log file and it contains a big table with jpeg files in every
#   table cell. Every row in the table is a signal.  The block_name
#   could be one of the following: CMVMI MISSRA NDBFS NDBCNTR DBACC
#   DBDICT DBLQH DBDIH DBTC DBTUP QMGR ALL. The signal_id is a
#   number. If no block_name or signal_id is given the default
#   block_name "ALL" is used.
#
#
#
# OPTIONS
#
# EXAMPLES
#   
#   
# ENVIRONMENT
#   NDB_PROJ_HOME                Home dir for ndb
#   
# FILES
#   $NDB_PROJ_HOME/lib/funcs.sh  General shell script functions.
#   uniq_blocks.awk              Creates a list of unique blocks 
#                                in the signal_log_file.
#   signallog2list.awk           Creates a list file from the signal_log_file.
#   empty.JPG                    Jpeg file, must exist in the HTML file 
#                                directory for viewing.
#   left_line.JPG
#   line.JPG
#   right_line.JPG
#   self_line.JPG
#
#
# SEE ALSO
#   
# DIAGNOSTICTS
#   
# VERSION   
#   1.0
#   
# DATE
# 011029
#
# AUTHOR
#   Jan Markborg
#

progname=`basename $0`
synopsis="signallog2html.sh [ -b <block_name | ALL> ] [ -s <signal_id> ] -f signal_log_file"
block_name=""
signal_id=""
verbose=yes
signal_log_file=""

: ${NDB_PROJ_HOME:?}		 # If undefined, exit with error message

: ${NDB_LOCAL_BUILD_OPTIONS:=--} # If undef, set to --. Keeps getopts happy.
			         # You may have to experiment a bit  
                                 # to get quoting right (if you need it).


. $NDB_PROJ_HOME/lib/funcs.sh    # Load some good stuff

# defaults for options related variables 
#
report_date=`date '+%Y-%m-%d'`

# Option parsing for the the command line.
#

while getopts f:b:s: i 
do
    case $i in
	f)      signal_log_file=$OPTARG;;
	b)      block_name=$OPTARG;;
	s)      signal_id=$OPTARG;;
	\?)	syndie ;;    # print synopsis and exit
    esac
done

# -- Verify
trace "Verifying signal_log_file $signal_log_file"

if [ x$signal_log_file = "x" ]
then
    syndie "Invalid signal_log_file name: $signal_log_file not found"
fi


if [ ! -r $signal_log_file ]
then
    syndie "Invalid signal_log_file name: $signal_log_file not found"
fi



if [ blocknameSET = 1 ]
then

    trace "Verifying block_name"
    case $block_name  in
	CMVMI| MISSRA| NDBFS| NDBCNTR| DBACC| DBDICT| DBLQH| DBDIH| DBTC| DBTUP| QMGR);;
	ALL)    trace "Signals to/from every block will be traced!";;
	*)      syndie "Unknown block name: $block_name";;
    esac
fi

if [ block_name="" -a signal_id="" ]
then
    block_name=ALL
    trace "block_name = $block_name"
fi

trace "Arguments OK"

###
#
# General html functions
header(){
    cat <<EOF
<html><head><title>$*</title></head>
<body>
EOF
}

footer(){
    cat <<EOF
</body></html>
EOF
}

heading(){
    h=$1; shift
    cat <<EOF
<h$h>$*</h$h>
EOF
}

table(){
    echo "<table $*>"
}

table_header(){
    echo "<th>$*</th>"
}

end_table(){
    echo "</table>"
}

row(){
    echo "<tr>"
}

end_row(){
    echo "</tr>"
}

c_column(){
    cat <<EOF
<td valign=center align=center>$*</td>
EOF
}

bold(){
    cat <<EOF
<b>$*</b>
EOF
}

column(){
    cat <<EOF
<td align=left>$*</td>
EOF
}

para(){
    cat <<EOF
<p></p>
EOF
}

hr(){
    cat <<EOF
<hr>
EOF
}

img_column(){
    cat <<EOF
<td><center><$* height=100% width=100%></center></td>
EOF
}

# Check the direction of arrow.
# arrowDirection(){ $columnarray $sendnode$sendblock $recnode$recblock
arrowDirection(){
if [ $2 = $3 ]
then
    arrow=SELF
    return;
else
    for x in $1
    do  
	if [ $x = $2 ]
	then
	    arrow=RIGHT
	    break
	elif [ $x = $3 ]
	then
	    arrow=LEFT  
	    break
	fi
    done   
fi
}

drawImages(){
for x in $columnarray
do
    	case $arrow in
	    SELF)
		if [ $x = $sendnode$sendblock ]
		then	
		    img_column img SRC=\"self_line.JPG\" 
		else
		    img_column img SRC=\"empty.JPG\"
		fi;;    
		
	    RIGHT)
		if [ $x = $recnode$recblock ]
		then
		    img_column img SRC=\"right_line.JPG\"
		    weHavePassedRec=1
		elif [ $x = $sendnode$sendblock ]
		then
		    img_column img SRC=\"empty.JPG\"
		    weHavePassedSen=1
		elif [ $weHavePassedRec = 1 -o $weHavePassedSen = 0 ]
		then
		    img_column img SRC=\"empty.JPG\"
		elif  [ $weHavePassedRec = 0  -a $weHavePassedSen = 1 ]
		then
		    img_column img SRC=\"line.JPG\"
		fi;;
		
	    LEFT)
		if [ $x = $recnode$recblock ]
		then
		    img_column img SRC=\"empty.JPG\"
		    weHaveJustPassedRec=1
		    weHavePassedRec=1
		    continue
		fi
		if [ $x = $sendnode$sendblock -a $weHaveJustPassedRec = 1 ]
		then
		    img_column img SRC=\"left_line.JPG\"
		    weHaveJustPassedRec=0
		    weHavePassedSen=1
		    continue
		fi
		if [ $x = $sendnode$sendblock ]
		then
		    img_column img SRC=\"line.JPG\"
		    weHavePassedSen=1
		    continue
		fi
		if [ $weHaveJustPassedRec = 1 ]
		then
		    img_column img SRC=\"left_line.JPG\"
		    weHaveJustPassedRec=0
		    continue
		fi
		if [ $weHavePassedSen = 1 -o $weHavePassedRec = 0 ]
		then
		    img_column img SRC=\"empty.JPG\"
		    continue
		fi

		if [ $weHavePassedRec = 1 -a $weHavePassedSen = 0 ]
		then
		    img_column img SRC=\"line.JPG\"
		    continue
		
		fi
		column ERROR;;

	    *)
		echo ERROR;;
	esac
done
column $signal
}

### Main
trace "Making HTML file"
(
    header  "Signal sequence diagram $report_date"
    heading 1 "Signal sequence diagram $report_date"

    trace "Making list file"
    #make a signal list file from the signal log file.
    `awk -f /home/ndb/bin/signallog2html.lib/signallog2list.awk SIGNAL_ID=$signal_id BLOCK_ID=$block_name $signal_log_file > $signal_log_file.list`

    COLUMNS=`awk -f /home/ndb/bin/signallog2html.lib/uniq_blocks.awk $signal_log_file.list | wc -w`
   
    table "border=0 cellspacing=0 cellpadding=0 cols=`expr $COLUMNS + 1`"

    columnarray=`awk -f /home/ndb/bin/signallog2html.lib/uniq_blocks.awk $signal_log_file.list`
    
    row
    column #make an empty first column!
    for col in $columnarray
    do
    table_header $col
    done

    grep "" $signal_log_file.list | \
    while read direction sendnode sendblock recnode recblock signal sigid recsigid delay
    do
 	if [ $direction = "R" ]
	then
	    row 
	    weHavePassedRec=0
	    weHavePassedSen=0
	    weHaveJustPassedRec=0
	    arrow=""
	    
	    # calculate the direction of the arrow.
	    arrowDirection "$columnarray" "$sendnode$sendblock" "$recnode$recblock"
	    
	    # Draw the arrow images.
	    drawImages
	    end_row
 	fi
    done
    end_table

    footer
)  > $signal_log_file.html

exit 0