1#!/usr/bin/env bash
2# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15# =============================================================================
16
17# Print build info, including info related to the machine, OS, build tools
18# and TensorFlow source code. This can be used by build tools such as Jenkins.
19# All info is printed on a single line, in JSON format, to workaround the
20# limitation of Jenkins Description Setter Plugin that multi-line regex is
21# not supported.
22#
23# Usage:
24#   print_build_info.sh (CONTAINER_TYPE) (COMMAND)
25#     e.g.,
26#       print_build_info.sh GPU bazel test -c opt --config=cuda //tensorflow/...
27
28# Information about the command
29CONTAINER_TYPE=$1
30shift 1
31COMMAND=("$@")
32
33# Information about machine and OS
34OS=$(uname)
35KERNEL=$(uname -r)
36
37ARCH=$(uname -p)
38PROCESSOR=$(grep "model name" /proc/cpuinfo | head -1 | awk '{print substr($0, index($0, $4))}')
39PROCESSOR_COUNT=$(grep "model name" /proc/cpuinfo | wc -l)
40
41MEM_TOTAL=$(grep MemTotal /proc/meminfo | awk '{print $2, $3}')
42SWAP_TOTAL=$(grep SwapTotal /proc/meminfo | awk '{print $2, $3}')
43
44# Information about build tools
45if [[ ! -z $(which bazel) ]]; then
46  BAZEL_VER=$(bazel version | head -1)
47fi
48
49if [[ ! -z $(which javac) ]]; then
50  JAVA_VER=$(javac -version 2>&1 | awk '{print $2}')
51fi
52
53if [[ ! -z $(which python) ]]; then
54  PYTHON_VER=$(python -V 2>&1 | awk '{print $2}')
55fi
56
57if [[ ! -z $(which g++) ]]; then
58  GPP_VER=$(g++ --version | head -1)
59fi
60
61if [[ ! -z $(which swig) ]]; then
62  SWIG_VER=$(swig -version > /dev/null | grep -m 1 . | awk '{print $3}')
63fi
64
65# Information about TensorFlow source
66TF_FETCH_URL=$(git config --get remote.origin.url)
67TF_HEAD=$(git rev-parse HEAD)
68
69# NVIDIA & CUDA info
70NVIDIA_DRIVER_VER=""
71if [[ -f /proc/driver/nvidia/version ]]; then
72  NVIDIA_DRIVER_VER=$(head -1 /proc/driver/nvidia/version | awk '{print $(NF-6)}')
73fi
74
75CUDA_DEVICE_COUNT="0"
76CUDA_DEVICE_NAMES=""
77if [[ ! -z $(which nvidia-debugdump) ]]; then
78  CUDA_DEVICE_COUNT=$(nvidia-debugdump -l | grep "^Found [0-9]*.*device.*" | awk '{print $2}')
79  CUDA_DEVICE_NAMES=$(nvidia-debugdump -l | grep "Device name:.*" | awk '{print substr($0, index($0,\
80 $3)) ","}')
81fi
82
83CUDA_TOOLKIT_VER=""
84if [[ ! -z $(which nvcc) ]]; then
85  CUDA_TOOLKIT_VER=$(nvcc -V | grep release | awk '{print $(NF)}')
86fi
87
88# Print info
89echo "TF_BUILD_INFO = {"\
90"container_type: \"${CONTAINER_TYPE}\", "\
91"command: \"${COMMAND[*]}\", "\
92"source_HEAD: \"${TF_HEAD}\", "\
93"source_remote_origin: \"${TF_FETCH_URL}\", "\
94"OS: \"${OS}\", "\
95"kernel: \"${KERNEL}\", "\
96"architecture: \"${ARCH}\", "\
97"processor: \"${PROCESSOR}\", "\
98"processor_count: \"${PROCESSOR_COUNT}\", "\
99"memory_total: \"${MEM_TOTAL}\", "\
100"swap_total: \"${SWAP_TOTAL}\", "\
101"Bazel_version: \"${BAZEL_VER}\", "\
102"Java_version: \"${JAVA_VER}\", "\
103"Python_version: \"${PYTHON_VER}\", "\
104"gpp_version: \"${GPP_VER}\", "\
105"swig_version: \"${SWIG_VER}\", "\
106"NVIDIA_driver_version: \"${NVIDIA_DRIVER_VER}\", "\
107"CUDA_device_count: \"${CUDA_DEVICE_COUNT}\", "\
108"CUDA_device_names: \"${CUDA_DEVICE_NAMES}\", "\
109"CUDA_toolkit_version: \"${CUDA_TOOLKIT_VER}\""\
110"}"
111