Skip to content

Commit

Permalink
Cleanup of system profiling scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunsuresh committed Aug 7, 2024
1 parent a004592 commit 88f14fc
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 20 deletions.
8 changes: 5 additions & 3 deletions script/app-mlperf-inference/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,14 +465,16 @@ def postprocess(i):
power_end_time = pd.Timestamp(datetime.strptime(match_end, '%m-%d-%Y %H:%M:%S.%f')).replace(tzinfo=timezone.utc)
#converts timestamp key value to datetime objects
sys_utilisation_log['timestamp'] = pd.to_datetime(sys_utilisation_log['timestamp'])
'''
for i in range(len(sys_utilisation_log['timestamp'])):
print(f"{sys_utilisation_log['timestamp'][i]} {power_begin_time}")
print(sys_utilisation_log['timestamp'][i]>=power_begin_time)
print(f"{sys_utilisation_log['timestamp'][0]} {power_begin_time}")
print(sys_utilisation_log['timestamp'][0]>=power_begin_time)
'''
#print(f"{sys_utilisation_log['timestamp'][0]} {power_begin_time}")
#print(sys_utilisation_log['timestamp'][0]>=power_begin_time)
filtered_log = sys_utilisation_log[(sys_utilisation_log['timestamp'] >= power_begin_time) &
(sys_utilisation_log['timestamp'] <= power_end_time)]
print(filtered_log)
#print(filtered_log)
# Calculate average of cpu_utilisation and used_memory_gb
system_utilisation_info_dump["avg_cpu_utilisation"] = filtered_log['cpu_utilisation'].mean()
system_utilisation_info_dump["avg_used_memory_gb"] = filtered_log['used_memory_gb'].mean()
Expand Down
13 changes: 7 additions & 6 deletions script/benchmark-program/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,20 @@ def preprocess(i):
elif env.get('CM_MLPERF_DEVICE', '') == "cpu":
env['CM_SYS_UTILISATION_SCRIPT_TAGS'] += ',_cpu'
# this section is for supplying the input arguments/tags
env['CM_SYS_UTILISATION_SCRIPT_TAGS'] += ' --log_dir=\"' + logs_dir + '\"' # specify the logs directory
env['CM_SYS_UTILISATION_SCRIPT_TAGS'] += ' --log_dir=\'' + logs_dir + '\'' # specify the logs directory
if env.get('CM_SYSTEM_INFO_MEASUREMENT_INTERVAL', '') != '': # specifying the interval in which the system information should be measured
env['CM_SYS_UTILISATION_SCRIPT_TAGS'] += ' --interval=\"' + env['CM_SYSTEM_INFO_MEASUREMENT_INTERVAL'] + '\"'

# generate the pre run cmd - recording runtime system infos
pre_run_cmd = ""
if env.get('CM_PROFILE_NVIDIA_POWER', '') == "on":
pass
#pass
# Note: To be fixed
# running the script as a process in background
# pre_run_cmd = pre_run_cmd + '\"' + 'cm run script --tags=runtime,system,utilisation' + env['CM_SYS_UTILISATION_SCRIPT_TAGS'] + ' &\" '
pre_run_cmd = pre_run_cmd + 'cm run script --tags=runtime,system,utilisation' + env['CM_SYS_UTILISATION_SCRIPT_TAGS'] + ' --quiet & '
# obtain the command if of the background process
# pre_run_cmd += 'cmd_pid=$!' + ' && ' + 'echo $cmd_pid' + ' && '
pre_run_cmd += ' cmd_pid=\$!' + ' && ' + 'echo CMD_PID=\$cmd_pid'
#pre_run_cmd += ' && '
# # check whether the command is running or not
# pre_run_cmd += "ps -p $cmd_pid || { echo 'Process $cmd_pid is not running, exiting'; exit 1; }"
env['CM_PRE_RUN_CMD'] = pre_run_cmd
Expand All @@ -77,8 +78,8 @@ def preprocess(i):
# generate the post run cmd - for killing the process that records runtime system infos
post_run_cmd = ""
if env.get('CM_PROFILE_NVIDIA_POWER', '') == "on":
pass
# post_run_cmd += "echo 'killing process ${cmd_pid}' && kill -TERM ${cmd_pid} && test $? -eq 0 || exit $? "
#pass
post_run_cmd += "echo 'killing process \${cmd_pid}' && kill -TERM \${cmd_pid}"
env['CM_POST_RUN_CMD'] = post_run_cmd
print(f"Post run command for killing the process that measures the runtime system information: {post_run_cmd}")

Expand Down
4 changes: 3 additions & 1 deletion script/benchmark-program/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ else
test $exitstatus -eq 0 || $exitstatus
fi

eval ${CM_POST_RUN_CMD}
test $? -eq 0 || exit $?

test $exitstatus -eq 0 || $exitstatus


eval ${CM_POST_RUN_CMD}
46 changes: 36 additions & 10 deletions script/detect-cpu/run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
#!/bin/bash

# Function to extract a field from /proc/cpuinfo
extract_field() {
local key="$1"
local default="$2"
# Use awk to find the first occurrence and extract the value
local value=$(awk -F: -v key="$key" '$1 ~ key {print $2; exit}' /proc/cpuinfo | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')

# Check if value is empty and assign default if needed
echo "${value:-$default}"
}

if [[ ${CM_HOST_OS_FLAVOR} == "macos" ]]; then
sysctl -a | grep hw > tmp-lscpu.out
else
Expand All @@ -8,15 +19,30 @@ else
echo "CM_HOST_MEMORY_CAPACITY=$memory_capacity">>tmp-run-env.out
disk_capacity=`df -h --total -l |grep total |tr -s ' '|cut -d' ' -f2`
echo "CM_HOST_DISK_CAPACITY=$disk_capacity">>tmp-run-env.out

# extract cpu information which are not there in lscpu
cpuinfo=$(cat /proc/cpuinfo)
echo "CM_HOST_CPU_WRITE_PROTECT_SUPPORT=$(echo "$cpuinfo" | grep -m 1 "wp" | cut -d ':' -f 2 | xargs)">>tmp-run-env.out
echo "CM_HOST_CPU_MICROCODE=$(echo "$cpuinfo" | grep -m 1 "microcode" | cut -d ':' -f 2 | xargs)">>tmp-run-env.out
echo "CM_HOST_CPU_FPU_SUPPORT=$(echo "$cpuinfo" | grep -m 1 "fpu" | cut -d ':' -f 2 | xargs)">>tmp-run-env.out
echo "CM_HOST_CPU_FPU_EXCEPTION_SUPPORT=$(echo "$cpuinfo" | grep -m 1 "fpu_exception" | cut -d ':' -f 2 | xargs)">>tmp-run-env.out
echo "CM_HOST_CPU_BUGS=$(echo "$cpuinfo" | grep -m 1 "bugs" | cut -d ':' -f 2 | xargs)">>tmp-run-env.out
echo "CM_HOST_CPU_TLB_SIZE=$(echo "$cpuinfo" | grep -m 1 "TLB size" | cut -d ':' -f 2 | xargs)">>tmp-run-env.out
echo "CM_HOST_CPU_CFLUSH_SIZE=$(echo "$cpuinfo" | grep -m 1 "clush size" | cut -d ':' -f 2 | xargs)">>tmp-run-env.out
echo "CM_HOST_CACHE_ALLIGNMENT_SIZE=$(echo "$cpuinfo" | grep -m 1 "cache_alignment" | cut -d ':' -f 2 | xargs)">>tmp-run-env.out
echo "CM_HOST_POWER_MANAGEMENT=$(echo "$cpuinfo" | grep -m 1 "power management" | cut -d ':' -f 2 | xargs)">>tmp-run-env.out
CM_HOST_CPU_WRITE_PROTECT_SUPPORT=$(extract_field "wp" "Not Found")
CM_HOST_CPU_MICROCODE=$(extract_field "microcode" "Not Found")
CM_HOST_CPU_FPU_SUPPORT=$(extract_field "fpu" "Not Found")
CM_HOST_CPU_FPU_EXCEPTION_SUPPORT=$(extract_field "fpu_exception" "Not Found")
CM_HOST_CPU_BUGS=$(extract_field "bugs" "Not Found")
CM_HOST_CPU_TLB_SIZE=$(extract_field "TLB size" "Not Found")
CM_HOST_CPU_CFLUSH_SIZE=$(extract_field "clflush size" "Not Found")
CM_HOST_CACHE_ALIGNMENT_SIZE=$(extract_field "cache_alignment" "Not Found")
CM_HOST_POWER_MANAGEMENT=$(extract_field "power management" "Not Found")

# Write results to a file
{
echo "CM_HOST_CPU_WRITE_PROTECT_SUPPORT=$CM_HOST_CPU_WRITE_PROTECT_SUPPORT"
echo "CM_HOST_CPU_MICROCODE=$CM_HOST_CPU_MICROCODE"
echo "CM_HOST_CPU_FPU_SUPPORT=$CM_HOST_CPU_FPU_SUPPORT"
echo "CM_HOST_CPU_FPU_EXCEPTION_SUPPORT=$CM_HOST_CPU_FPU_EXCEPTION_SUPPORT"
echo "CM_HOST_CPU_BUGS=$CM_HOST_CPU_BUGS"
echo "CM_HOST_CPU_TLB_SIZE=$CM_HOST_CPU_TLB_SIZE"
echo "CM_HOST_CPU_CFLUSH_SIZE=$CM_HOST_CPU_CFLUSH_SIZE"
echo "CM_HOST_CACHE_ALIGNMENT_SIZE=$CM_HOST_CACHE_ALIGNMENT_SIZE"
echo "CM_HOST_POWER_MANAGEMENT=$CM_HOST_POWER_MANAGEMENT"
} >> tmp-run-env.out
fi


0 comments on commit 88f14fc

Please sign in to comment.