shell-tracer.sh revision 492:e64f2cb57d05
1246145Shselasky#!/bin/bash 2246145Shselasky# 3246145Shselasky# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 4246145Shselasky# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5246145Shselasky# 6246145Shselasky# This code is free software; you can redistribute it and/or modify it 7246145Shselasky# under the terms of the GNU General Public License version 2 only, as 8246145Shselasky# published by the Free Software Foundation. 9246145Shselasky# 10246145Shselasky# This code is distributed in the hope that it will be useful, but WITHOUT 11246145Shselasky# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12246145Shselasky# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13246145Shselasky# version 2 for more details (a copy is included in the LICENSE file that 14246145Shselasky# accompanied this code). 15246145Shselasky# 16246145Shselasky# You should have received a copy of the GNU General Public License version 17246145Shselasky# 2 along with this work; if not, write to the Free Software Foundation, 18246145Shselasky# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19246145Shselasky# 20246145Shselasky# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21246145Shselasky# or visit www.oracle.com if you need additional information or have any 22246145Shselasky# questions. 23246145Shselasky# 24246145Shselasky 25246145Shselasky# Usage: sh shell-tracer.sh <TIME_CMD> <OUTPUT_FILE> <OLD_SHELL> <shell command line> 26246145Shselasky# 27246145Shselasky# This shell script is supposed to be set as a replacement for SHELL in make, 28246145Shselasky# causing it to be called whenever make wants to execute shell commands. 29246145Shselasky# The <shell command line> is suitable for passing on to the old shell, 30246145Shselasky# typically beginning with -c. 31246145Shselasky# 32246145Shselasky# This script will make sure the shell command line is executed with 33246145Shselasky# OLD_SHELL -x, and it will also store a simple log of the the time it takes to 34246145Shselasky# execute the command in the OUTPUT_FILE, using the "time" utility as pointed 35246145Shselasky# to by TIME_CMD. If TIME_CMD is "-", no timestamp will be stored. 36246145Shselasky 37246145ShselaskyTIME_CMD="$1" 38246145ShselaskyOUTPUT_FILE="$2" 39246145ShselaskyOLD_SHELL="$3" 40246145Shselaskyshift 41246145Shselaskyshift 42246145Shselaskyshift 43246145Shselaskyif [ "$TIME_CMD" != "-" ]; then 44246145Shselasky"$TIME_CMD" -f "[TIME:%E] $*" -a -o "$OUTPUT_FILE" "$OLD_SHELL" -x "$@" 45246145Shselaskyelse 46246145Shselasky"$OLD_SHELL" -x "$@" 47246145Shselaskyfi 48246145Shselasky