Skip to content

Commit

Permalink
Add OS Info script for Linux
Browse files Browse the repository at this point in the history
  * Add simple script that grabs some information about CPU, memory, etc (everything that doesn't require root privileges)
  • Loading branch information
Civil committed Jan 4, 2022
1 parent c1818db commit 8b9e88b
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 3 deletions.
59 changes: 59 additions & 0 deletions src/cpu_info_linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash

source common.sh
RESULT_DIR="../results/${current_arch}"
mkdir -p "${RESULT_DIR}"

echo "Recording output of uname"
uname -mrsv > "${RESULT_DIR}/linux_uname.log"

if [[ -d /sys/devices/system/cpu/ ]]; then
echo "Obtaining cpu information from /sys"
for i in /sys/devices/system/cpu/cpu[0-9]*; do
CPU=$(basename "${i}")
if [[ -d "${i}/cache" ]]; then
for idx in ${i}/cache/index*; do
IDX_NAME=$(basename ${idx})
LEVEL=$(cat "${idx}/level")
TYPE=$(cat "${idx}/type")
for parameter in ${idx}/*; do
p_base="$(basename ${parameter})"
if [[ "${p_base}" == "uevent" ]] || [[ "${p_base}" == "level" ]] || [[ "${p_base}" == "type" ]]; then
continue
fi
echo -n "${CPU}_L${LEVEL}${TYPE}_${p_base}=" >> "${RESULT_DIR}/linux_cpu_sys.log"
cat "${parameter}" >> "${RESULT_DIR}/linux_cpu_sys.log"
done
done
fi
if [[ -d "${i}/cpufreq" ]]; then
for freq in cur_freq max_freq min_freq; do
echo -n "${CPU}_${freq}=" >> "${RESULT_DIR}/linux_cpu_sys.log"
cat "${i}/cpufreq/scaling_${freq}" >> "${RESULT_DIR}/linux_cpu_sys.log"
done
fi
done
fi

echo "Saving numactl information..."
numactl -H &>> "${RESULT_DIR}/linux_numactl.log"

echo "Getting information from current compiler"
cc --version >> "${RESULT_DIR}/linux_compiler.log"

# compile test code and do heruistics to detect cpu frequency
echo "Compiling code to detect CPU frequency..."
cc -ocpu_freq -std=gnu99 -Wall -Wextra -O2 utilities/cpu_freq.c -lpthread
echo "Running tool to attempt to detect real sustained frequency... This might take a while..."
echo "To make results more accurate please don't touch your computer while tools are running"
CORES=${cpus_count}
rm -f "${RESULT_DIR}/linux_freq.log"
for i in $(seq 1 "${CORES}"); do
echo "Running code to detect CPU frequency for ${i} cores"
nice -19 ./cpu_freq "${i}" >> "${RESULT_DIR}/linux_freq.log"
echo >> "${RESULT_DIR}/linux_freq.log"
done
echo "Saving cpuinfo and meminfo"
cat /proc/cpuinfo > "${RESULT_DIR}/linux_cpuinfo.log"
cat /proc/meminfo > "${RESULT_DIR}/linux_meminfo.log"

18 changes: 15 additions & 3 deletions src/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,24 @@ RESULT_DIR="../results/${current_arch}"
mkdir -p "${RESULT_DIR}"

if [[ ${os_name} == "mac" ]]; then
./cpu_info_mac.sh
echo "Will gather system information"
./cpu_info_mac.sh
fi

if [[ ${os_name} == "Linux" ]]; then
echo "Will gather system information"
./cpu_info_linux.sh
fi

BIN_DIR="../bin/${os_name}/${current_arch}"
for BINARY in $(ls ${BIN_DIR}/); do
BINARY_LIST="$(ls ${BIN_DIR}/)"
if [[ "${#@}" -eq 1 ]]; then
BINARY=${1}
BINARY_LIST="$(ls ${BIN_DIR}/ | grep ${BINARY})"
fi
for BINARY in ${BINARY_LIST}; do
[[ ! -x "${BIN_DIR}/${BINARY}" ]] && continue ||:
echo "Running ${BINARY}"
"${BIN_DIR}/${BINARY}" &> "${RESULT_DIR}/${BINARY}.stdout_stderr.log"
BASE_BINARY_NAME="$(cut -d_ -f 1 <<< ${BINARY})"
"${BIN_DIR}/${BINARY}" ${binaryExtraArgs[${BASE_BINARY_NAME}]} &> "${RESULT_DIR}/${BINARY}.stdout_stderr.log"
done

0 comments on commit 8b9e88b

Please sign in to comment.