#!/bin/bash # # st_draw --- Draw binary sched_trace traces as nicely formatted PDFs. # Copyright (C) 2008 B. Brandenburg, # # 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 < Usage: st_draw [OPTIONS] * 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