author | herrick |
Fri, 08 Nov 2019 15:27:05 -0500 | |
branch | JDK-8200758-branch |
changeset 58995 | de1413ae214c |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
14111 | 1 |
#!/bin/bash |
2 |
# |
|
3 |
# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
|
4 |
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
5 |
# |
|
6 |
# This code is free software; you can redistribute it and/or modify it |
|
7 |
# under the terms of the GNU General Public License version 2 only, as |
|
8 |
# published by the Free Software Foundation. |
|
9 |
# |
|
10 |
# This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 |
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 |
# version 2 for more details (a copy is included in the LICENSE file that |
|
14 |
# accompanied this code). |
|
15 |
# |
|
16 |
# You should have received a copy of the GNU General Public License version |
|
17 |
# 2 along with this work; if not, write to the Free Software Foundation, |
|
18 |
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 |
# |
|
20 |
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
21 |
# or visit www.oracle.com if you need additional information or have any |
|
22 |
# questions. |
|
23 |
# |
|
24 |
||
44465
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
25 |
# Usage: sh shell-tracer.sh <TIME_CMD_TYPE> <TIME_CMD> <OUTPUT_FILE> <shell command line> |
14111 | 26 |
# |
27 |
# This shell script is supposed to be set as a replacement for SHELL in make, |
|
28 |
# causing it to be called whenever make wants to execute shell commands. |
|
27595
cff167b3bfa2
8065914: Various improvements and cleanup of build system
ihse
parents:
14111
diff
changeset
|
29 |
# The <shell command line> is suitable for passing on to the old shell, |
14111 | 30 |
# typically beginning with -c. |
31 |
# |
|
44465
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
32 |
# This script will run the shell command line and it will also store a simple |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
33 |
# log of the the time it takes to execute the command in the OUTPUT_FILE, using |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
34 |
# utility for time measure specified with TIME_CMD option. |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
35 |
# |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
36 |
# Type of time measure utility is specified with TIME_CMD_TYPE option. |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
37 |
# Recognized options values of TIME_CMD_TYPE option: "gnutime", "flock". |
14111 | 38 |
|
44465
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
39 |
TIME_CMD_TYPE="$1" |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
40 |
TIME_CMD="$2" |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
41 |
OUTPUT_FILE="$3" |
14111 | 42 |
shift |
43 |
shift |
|
44 |
shift |
|
44465
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
45 |
if [ "$TIME_CMD_TYPE" = "gnutime" ]; then |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
46 |
# Escape backslashes (\) and percent chars (%). See man for GNU 'time'. |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
47 |
msg=${@//\\/\\\\} |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
48 |
msg=${msg//%/%%} |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
49 |
"$TIME_CMD" -f "[TIME:%E] $msg" -a -o "$OUTPUT_FILE" "$@" |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
50 |
elif [ "$TIME_CMD_TYPE" = "flock" ]; then |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
51 |
# Emulated GNU 'time' with 'flock' and 'date'. |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
52 |
ts=`date +%s%3N` |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
53 |
"$@" |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
54 |
status=$? |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
55 |
ts2=`date +%s%3N` |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
56 |
millis=$((ts2 - ts)) |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
57 |
ms=$(($millis % 1000)) |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
58 |
seconds=$((millis / 1000)) |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
59 |
ss=$(($seconds % 60)) |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
60 |
minutes=$(($seconds / 60)) |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
61 |
mm=$(($minutes % 60)) |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
62 |
hh=$(($minutes / 60)): |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
63 |
[ $hh != "0:" ] || hh= |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
64 |
# Synchronize on this script. |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
65 |
flock -w 10 "$0" printf "[TIME:${hh}${mm}:${ss}.%.2s] %s\n" $ms "$*" >> "$OUTPUT_FILE" || true |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
66 |
exit $status |
14111 | 67 |
else |
44465
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
27595
diff
changeset
|
68 |
"$@" |
14111 | 69 |
fi |