shell-tracer.sh revision 1236:bebfcf0b68ea
133965Sjdp#!/bin/bash
2218822Sdim#
3218822Sdim# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
433965Sjdp# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
533965Sjdp#
6218822Sdim# This code is free software; you can redistribute it and/or modify it
733965Sjdp# under the terms of the GNU General Public License version 2 only, as
8218822Sdim# published by the Free Software Foundation.
9218822Sdim#
10218822Sdim# This code is distributed in the hope that it will be useful, but WITHOUT
11218822Sdim# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1233965Sjdp# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13218822Sdim# version 2 for more details (a copy is included in the LICENSE file that
14218822Sdim# accompanied this code).
15218822Sdim#
16218822Sdim# You should have received a copy of the GNU General Public License version
1733965Sjdp# 2 along with this work; if not, write to the Free Software Foundation,
18218822Sdim# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19218822Sdim#
20218822Sdim# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2133965Sjdp# or visit www.oracle.com if you need additional information or have any
22218822Sdim# questions.
2333965Sjdp#
2433965Sjdp
25218822Sdim# Usage: sh shell-tracer.sh <TIME_CMD> <OUTPUT_FILE> <OLD_SHELL> <shell command line>
2677298Sobrien#
2733965Sjdp# This shell script is supposed to be set as a replacement for SHELL in make,
2833965Sjdp# causing it to be called whenever make wants to execute shell commands.
2933965Sjdp# The <shell command line> is suitable for passing on to the old shell,
3077298Sobrien# typically beginning with -c.
31130561Sobrien#
3233965Sjdp# This script will make sure the shell command line is executed with
3333965Sjdp# OLD_SHELL -x, and it will also store a simple log of the the time it takes to
3433965Sjdp# execute the command in the OUTPUT_FILE, using the "time" utility as pointed
3533965Sjdp# to by TIME_CMD. If TIME_CMD is "-", no timestamp will be stored.
3633965Sjdp
3733965SjdpTIME_CMD="$1"
3833965SjdpOUTPUT_FILE="$2"
3933965SjdpOLD_SHELL="$3"
4033965Sjdpshift
4133965Sjdpshift
4233965Sjdpshift
4333965Sjdpif [ "$TIME_CMD" != "-" ]; then
4433965Sjdp"$TIME_CMD" -f "[TIME:%E] $*" -a -o "$OUTPUT_FILE" "$OLD_SHELL" -x "$@"
4533965Sjdpelse
4633965Sjdp"$OLD_SHELL" -x "$@"
4733965Sjdpfi
4833965Sjdp