summaryrefslogtreecommitdiffstats
path: root/st_draw
blob: 54cf2621d5e90add18f3fb2278610aeae4072392 (plain) (blame)
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
#!/bin/bash
#
#    st_draw --- Draw binary sched_trace traces as nicely formatted PDFs. 
#    Copyright (C) 2008 B. Brandenburg, <bbb@cs.unc.edu>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License along
#    with this program; if not, write to the Free Software Foundation, Inc.,
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


ST_SHOW=st_show
ST2PL=st_convert
ASY=asy
SHOW_PDF=evince

function die {
    echo "(EE) $*"
    exit 1
}

function info {
    echo "(II) $*"
}

KEEP=
NO_SHOW=
NAME=
FROM=
TO=
LENGTH=1000
while true
do
  case "$1" in
      -f | --from)
	  shift
	  FROM=$1
	  shift
	  ;;
      -t | --to)
	  shift
	  TO=$1
	  shift
	  ;;
      -l | --length)
	  shift
	  LENGTH=$1
	  shift
	  ;;
      -k | --keep)
	  KEEP=yes
          shift
	  ;;
      --no-show)
	  NO_SHOW=yes
	  shift
	  ;;
      -n | --name)
	  shift
	  NAME=$1
	  shift
	  ;;
      -h | --help)
	  cat <<EOF
LITMUS^RT Schedule Drawing Utility
(c) 2008 B. Brandenburg <bbb@cs.unc.edu>

Usage: st_draw [OPTIONS] <sched trace file>*

Options:
	-f FROM
	--from FROM	Start at time FROM.
			Time of system release if not specified.

	-l LENGTH
	--length LENGTH	Draw schedule of length LENGTH. (Default: 1000)

	-t TO
	--to TO		Draw schedule up to time TO. (Default: FROM + LENGTH)
			If given, then LENGTH is ignored.

	-n NAME
	--name NAME	Filename to use. If no trace files are specified,
			then st-NAME-*.bin is used instead.

	-k
	--keep		Keep the generated .asy/.pdf files.

	--no-show	Don't start a PDF document viewer.

	-h
	--help		Show this message and exit.
EOF
	  exit 0
	  ;;
      *)
	  break
	  ;;
  esac
done

TRACES=$*
if [ ! -z "$NAME" ] && [ -z "$TRACES" ]
then
    TRACES=`ls st-$NAME-*.bin 2> /dev/null`
fi

if [ -z "$TRACES" ]
then
    die "Trace files missing."
else
    info "Trace files: " $TRACES
fi

if [ -z "$FROM" ]
then
    info "Searching for task system release..."
    FROM=`$ST_SHOW -r -f $TRACES | sed 's/\.[0-9]*ms//'`
    if [ -z "$FROM" ]
    then
	die "No task system release found in trace."
    else
	info "Task system released at $FROM."
	FROM=$((($FROM / 10) * 10))
    fi
fi

if [ -z "$TO" ]
then
    TO=$(($FROM + $LENGTH))
    LAST=`$ST_SHOW $TRACES | tail -1 | awk '{print $2}' | sed 's/]//'`
    LASTB=$((($LAST / 10 + 1) * 10))
    if [ $TO -gt $LASTB ]
    then
	info "Last event  recorded at $LAST."
	TO=$LASTB
    fi
fi

info "Drawing schedule from $FROM to $TO."

if [ ! -z "$NAME" ]
then
    SCHED="${NAME}.asy"
    PDF="${NAME}.pdf"
else
    SCHED=`mktemp`
    PDF="${SCHED}.pdf"
fi

info "Drawing schedule..."
$ST2PL -lasy -f $FROM -t $TO $TRACES > $SCHED || die "$ST2PL failed."
info "Generating PDF..."
$ASY   -f pdf -o $PDF $SCHED || die "$ASY failed."

if [ -z "$NO_SHOW" ]
then
    info $SHOW_PDF $PDF
    $SHOW_PDF $PDF || die "$SHOW_PDF failed."
fi

if [ -z "$KEEP" ]
then
    rm -f $SCHED $PDF
else
    info "ASY: $SCHED"
    info "PDF: $PDF"
fi