Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # USAGE:
- # start without parameters: (normal SC2-start with usual tweaks)
- # creates Variables.txt-backup, starts SC2, changes kernel parameters/modules, changes process priority/affinity/... and undoes all the changes afterwards.
- #
- # start with "-b" flag: (benchmark-mode. SC2-start with tweaks, gathers performance information)
- # only gathers performance information in the background and prints the results in "$sc_appdata_path"bench-logs/bench-result when SC2 is terminated.
- #
- # start with "-b -t" flag: (automated benchmark-mode. SC2-start, gathers performance information, automatically starts a replay and quits SC2 to have a reproducible workload)
- #
- #
- # ADJUSTMENTS:
- # (text-search for the listed things and you will find the right place to edit. there might be several of it.)
- # things, you should check/adjust in order to make make a normal SC2-start:
- # - path variables - to: wine-prefix, SC2-executable, SC2-appdata-folder
- # - SC2-executable (+commands)
- # - cpu-governor settings
- # - cpu core number
- # - cpu core affinity
- #
- # further things you could customize: (the script should work fine without adjusting these)
- # - kernel parameters - these were my initial reason to write this script. i highly recommend you, to find out on your own if you want to use my values because they are still very experimental.
- # - kernel-modules - these modules will be removed before and added back after SC2.
- # - process attributes - if you are unhappy with my settings (nice, schedule policy ...).
- #
- # things you need to adjust for the benchmark-mode: (if "-b" is passed)
- # - probed benchmark data - but, by changing this, you will for sure break the benchmark data analysis.
- # -- NOTE: right now, this script will only handle "bench-sample_fps" files, the parts that calculate the average cpu-/gpu-load are missing but gathering the data is possible.
- #
- # things you need to adjust for the automated benchmark-mode: (if "-b -t" is passed)
- # - install the package "xautomation". it ("xte") makes automated key-inputs and clicks from enter password over start replay to set player-camera.
- # - click-coordinates - you need to change the x- and y- coordinates several times for a variety of buttons. (xte 'mousemove X Y')
- # -- im running SC2 with a resolution of 1024x768. if you use a different one, you must adjust the coordinates.
- # - battle.net account-password - you save your password in this script so you dont need to enter it manually all the time.
- #
- # this script is not finished yet. there are quite some possibilies to improve it.
- # e.g. the benchmark results will always the saved in $sc_appdata_path/bench-logs/bench-result
- clear
- sudo -v # gets the preemptive super user privileges to execute only certain commands later on. dont panic, it wont start SC2 with sudo.
- sleep 2s # this also gives you the opportunity to kill the script with CTRL + C
- # --- VARIABLES:
- declare -i i; i=0
- declare -i j; j=0
- # --- following 4 lines randomly set k/l to 1/2 or 2/1 to assign the SC2/wineserver process randomly to cpu core number 1/2 or 2/1. i wanted to have some rotation in that. if you want a static core assignment or you have more than 2 cores (so randomly k!=l & k/l = [1-4]), you might adjust this.
- declare -i k; k=$RANDOM
- let "k %= 2","k += 1"
- declare -i l; if [ $k -eq 1 ]; then
- l=2; else l=1; fi
- declare sc_date; sc_date=`date +%Y-%m-%d_%H-%M-%S`
- # --- these 3 path variables ($sc_wine_pref, $sc_exec_path, $sc_appdata_path) point to the folders of ... just look at them.
- # ---- note: there are no " or ' quotes around them. i dont know why quotes break the script neither do i why it runs without them :) - just stay with the syntax ("space" = "\ ").
- declare sc_wine_pref; sc_wine_pref=~/.wine/
- declare sc_exec_path; sc_exec_path=~/.wine/drive_c/Program\ Files/StarCraft\ II/Support/SC2Switcher.exe
- declare sc_appdata_path; sc_appdata_path=~/StarCraft\ II/
- # --- following array defines the kernel parameters and the new values, to which the script will change them before SC2-start and set them back to default afterwards.
- : ' <--- commented out, just delete this and the last line of this chapter to enable it.
- declare -a kp_var
- declare -a kp_var_bak
- kp_var=(
- # --- scheduler parameters
- kernel.sched_child_runs_first=1
- kernel.sched_time_avg=250
- kernel.sched_rt_period_us=957500
- kernel.sched_rt_runtime_us=-1
- kernel.sched_nr_migrate=48
- kernel.sched_latency_ns=8000000
- kernel.yama.ptrace_scope=0
- kernel.sched_wakeup_granularity_ns=25000000
- kernel.sched_min_granularity_ns=4000000
- vm.overcommit_memory=2
- vm.overcommit_ratio=50
- kernel.ftrace_enabled=0
- kernel.perf_event_paranoid=-1
- kernel.io_delay_type=3
- kernel.watchdog=0
- kernel.nmi_watchdog=0
- # --- network parameters
- net.core.rmem_max=67108864
- net.core.wmem_max=67108864
- "net.ipv4.tcp_rmem=4096 3932160 62914560"
- "net.ipv4.tcp_wmem=4096 196608 3145728"
- net.ipv4.tcp_mtu_probing=1
- net.ipv4.tcp_timestamps=0
- )
- ' #<--- remove this line to enable this chapter.
- # --- these are the the kernel-modules that will be remove and added back again after SC2 is terminated.
- : ' <--- commented out, just delete this and the last line of this chapter to enable it.
- declare -a km_var
- km_var=(
- rfcomm
- bnep
- bluetooth
- psmouse
- joydev
- ppdev
- sparse_keymap
- uvcvideo
- videodev
- v4l2_compat_ioctl32
- serio_raw
- video
- acer_wmi
- mxm_wmi
- wmi
- sdhci_pci
- sdhci
- iwlwifi
- mac80211
- cfg80211
- snd_seq_midi
- snd_rawmidi
- snd_seq_midi_event
- 'lp'
- parport_pc
- parport
- pcmcia
- yenta_socket
- pcmcia_rsrc
- pcmcia_core
- )
- ' #<--- remove this line to enable this chapter.
- # --- this part stores the battle.net account-password for the automatic login. if you like, you can save your password in this file.
- if [ "$1" == "-b" ] && [ "$2" == "-t" ]; then
- #declare acc_pw; acc_pw="PASSWORD" # <- save your pw here
- if [ ! $acc_pw ]; then
- declare acc_pw
- echo "Please enter Battle.net Account Password"
- read acc_pw
- history -c; reset
- fi
- fi
- # --- "if" declares the all needed vars when benchmark mode is turned on.
- if [ "$1" == "-b" ]; then
- declare bv_line; bv_line=0
- declare -a bv_clean_data
- declare bv_results; bv_results=0
- # --- "if" checks if a "bench-log" directory exists in $sc_appdata_path and creates one if not.
- if [ ! -d "$sc_appdata_path"bench-logs ]; then
- echo "BENCH-LOG DIR DOESNT EXIST ... CREATING NEW ONE"; sleep 2s
- mkdir "$sc_appdata_path"bench-logs
- fi
- fi
- # --- "if" checks if the SC2 settings has been changed and creates new backup if so.
- if diff "$sc_appdata_path"Variables.txt "`ls -r "$sc_appdata_path"Variables.txt.bak.* | head -n1 | sed 's_ _\\ _g'`" >/dev/null; then
- echo "VARIABLES MATCHING BACKUP"
- else
- echo "VARIABLES ALTERED ... CREATING NEW BACKUP"
- cp "$sc_appdata_path"Variables.txt "$sc_appdata_path"Variables.txt.bak.$sc_date; sleep 2s
- fi
- chmod -w "$sc_appdata_path"Variables.txt # write-protect the SC2 settings to prevent any unintended changes by SC2. changed back to writable when SC2 is closed.
- # --- you can ignore the following lines. used to be an experiment what i never removed.
- sudo atieventsd --nosyslog
- sudo sync; sleep 2s
- echo "CACHE CLEARED"
- # --- this loop changes the kernel-parameters to the defined values in $kp_var and saves the original values in $kp_var_bak
- if [ ${#kp_var[@]} -gt 0 ]; then
- echo "CHANGING KERNEL PARAMETERS"
- for ((i=0; i<=${#kp_var[@]} - 1; i++)); do
- kp_var_bak[$i]=`sysctl -n $(echo ${kp_var[$i]:0:\`expr index "${kp_var[$i]}" "="\`} | sed -e 's_\=__g')`
- sudo sysctl -w "${kp_var[$i]}"
- done
- else
- unset kp_var kp_var_bak
- fi
- # --- this loop checks if the listed kernel-modules exist and if not, removes them from the array. after that, the selected modules will be removed
- if [ ${#km_var[@]} -gt 0 ]; then
- echo "REMOVING KERNEL MODULES"
- for ((i=0; i<=${#km_var[@]} - 1; i++)); do
- if ! lsmod | grep "${km_var[$i]} " >/dev/null; then
- echo "${km_var[$i]} kernel-module is not loaded"
- unset km_var[$i]
- fi
- done
- sudo modprobe -r ${km_var[@]}
- fi
- # --- cpu-governor settings to max performance (for my 2 cpu cores). "man cpufreq-set" for details.
- echo "SETTING CPU GOVERNOR: PERFORMANCE"
- sudo cpufreq-set -c 0 -g performance -d 2000000 -u 2000000
- sudo cpufreq-set -c 1 -g performance -d 2000000 -u 2000000
- # --- starts SC2-executable (+commands). notice the "wine64" and the arguments i pass to SC2 and change it if desired.
- echo -e "\nSTARTING SC2 NOW"
- wine --version; sleep 1s
- sleep 1s; xrandr -s 1024x768; sleep 1s
- if [ "$1" == "-b" ]; then
- echo "----------------"; echo "-BENCHMARK MODE-"; echo "----------------";
- WINEDEBUG="-all,+fps" wine64 "$sc_exec_path" -opengl -fullproc -skipopenal -confinecursor -Leaks &> "$sc_appdata_path"bench-logs/bench-sample_fps.$sc_date
- else
- WINEDEBUG="-all" wine64 "$sc_exec_path" -opengl -fullproc -skipopenal -confinecursor -Leaks
- fi
- sleep 15s
- # --- these commands change some process attributes.
- sudo renice -n -18 `pidof SC2.exe` # increases the priority of SC2 and wineserver process.
- sudo renice -n -18 `pidof wineserver`
- sudo taskset -p $k `pidof SC2.exe` # sets SC2 to one of my cpu cores and wineserver to the other one, cpu core affinity might need to be adjusted.
- sudo taskset -p $l `pidof wineserver`
- sudo chrt -f -p 80 `pidof SC2.exe` # changes the scheduler priority and policy to FIFO (First in First out) for SC2 and wineserver.
- sudo chrt -f -p 70 `pidof wineserver`
- chrt -p `pidof SC2.exe`
- chrt -p `pidof wineserver`
- sudo ionice -c2 -n0 -p`pidof SC2.exe` # increases IO priority of SC2 and wineserver.
- sudo ionice -c2 -n0 -p`pidof wineserver`
- echo -e "ionice: $(pidof SC2.exe): $(sudo ionice -p `pidof SC2.exe`)\nionice: $(pidof wineserver): $(sudo ionice -p `pidof wineserver`)\n"
- #sudo schedtool -1 -p 90
- # --- this part enters the $acc_pw, starts the "BENCHMARK.SC2Replay" and sets player-camera.
- # --- its a very ugly solution though, you need to adjust the click-coordinates and and put a replay in the "vs AI" replay-folder. the first one in the list will be started.
- if [ "$1" == "-b" ] && [ "$2" == "-t" ]; then
- sleep 25s # wait for SC2 login screen
- xte "str $acc_pw"; sleep 1s; xte 'key Return' # enters password
- unset acc_pw
- sleep 20s # wait for SC2 menu
- xte 'mousemove 320 120'; sleep 1s; xte 'mouseclick 1'; sleep 3s # click on replay-button
- xte 'mousemove 150 370'; sleep 1s; xte 'mouseclick 1'; sleep 3s # click on "VS AI"-button
- xte 'mousemove 380 665'; sleep 1s; xte 'mouseclick 1'; sleep 50s # starts replay and waits for the loading
- xte 'key 2'; sleep 1s # sets player2-camera
- fi
- # --- this loop runs as long as SC2 runs
- i=0
- j=0
- while [ $(pidof SC2.exe) ]; do
- # --- (experimental) this "if" would collect probed benchmark data. i decided to focus on fps only, so this "if" is commented-out.
- #if [ "$1" == "-b" ]; then
- #for ((i=0; i<=10; i++)); do
- #echo "BENCHMARK CYCLE: $m"; let "m += 1","i += 1"; sleep 1s
- #aticonfig --od-getclocks >> "$sc_appdata_path"bench-logs/bench-sample_gpuload.$sc_date
- #ps -eLo pid,%cpu,%mem,cputime,lwp | grep `pidof SC2.exe` >> "$sc_appdata_path"bench-logs/bench-sample_cpuload.$sc_date
- #done
- #else
- sleep 10s; let "i += 1"
- #fi
- # --- this "if" renews the sudo and stuff so in the end, you dont need to give your password again to revert e.g. the kernel-parameters.
- if [ $i -eq 30 ]; then
- sudo -v; let "j += 5"; echo -e "$j MINUTES INGAME\n"; i=0
- fi
- if [ "$1" == "-b" ] && [ "$2" == "-t" ] && [ $j -eq 5 ]; then # end condition of the benchmark: after 5 minutes ($j={5...15...50...}), the following part will close the replay and SC2.
- xte 'key F10'; sleep 1s; xte 'key v'; sleep 15s # quits the replay
- xte 'key Escape'; sleep 2s; xte 'mousemove 500 460'; sleep 1s; xte 'mouseclick 1'; sleep 5s # adjust the click-coordinates to "Quit Starcraft"-Button.
- fi
- done
- sleep 1s; xrandr -s 1280x800; sleep 1s
- echo -e "\nTERMINATED\nYOU PLAYED $j MINUTES\n"
- wineserver -k
- chmod +w "$sc_appdata_path"Variables.txt # makes the Variables.txt writable again.
- sensors -A # this just put the temperature of your cpu out.
- # --- reverts the cpu-governor settings to ondemand (my default).
- echo "SETTING CPU GOVERNOR: ONDEMAND"
- sudo cpufreq-set -c 0 -g ondemand -d 800000 -u 2000000
- sudo cpufreq-set -c 1 -g ondemand -d 800000 -u 2000000
- # --- this loop changes the kernel-params back to default
- if [ ${#kp_var[@]} -gt 0 ]; then
- echo "RESTORING KERNEL PARAMETERS"
- for ((i=0; i<=${#kp_var[@]} - 1; i++)); do
- sudo sysctl -w "${kp_var[$i]:0:`expr index "${kp_var[$i]}" "="`}${kp_var_bak[$i]}"
- done
- fi
- # --- loads the deactivated kernel-modules again
- if [ ${#km_var[@]} -gt 0 ]; then
- echo "RESTORING KERNEL MODULES"
- sudo modprobe -a ${km_var[@]}
- fi
- # --- this chapter runs the benchmark analysis and prints the results to a file in $sc_appdata_path/bench-logs/
- if [ "$1" == "-b" ]; then
- i=0; j=0
- # --- this chapter prints the header of/to the bench-result file. consisting of used SC2 configurations, "Direct3D"-Registrykey, used kernel-parameters and spreadsheet columns.
- echo -e "\n-------------------------------------------\n---- bench-result.$sc_date -----\n-------------------------------------------" >> "$sc_appdata_path"bench-logs/bench-result.$sc_date
- echo "Used SC2-Settings:" >> "$sc_appdata_path"bench-logs/bench-result.$sc_date
- ls -r "$sc_appdata_path"Variables.txt.bak.* | head -n1 | sed "s_/home\/`whoami`\/StarCraft II\/__" >> "$sc_appdata_path"bench-logs/bench-result.$sc_date
- echo -e "\nDirect3D Registrykey:" >> "$sc_appdata_path"bench-logs/bench-result.$sc_date
- while read bv_line; do
- if [ "$(echo $bv_line | grep Direct3D)" ]; then
- i=1
- elif [ $i -eq 1 ] && [ "$(echo $bv_line | grep Software)" ]; then
- i=0
- elif [ $i -eq 1 ]; then
- echo $bv_line >> "$sc_appdata_path"bench-logs/bench-result.$sc_date
- fi
- done < "$sc_wine_pref"user.reg
- if [ ${#kp_var[@]} -gt 0 ]; then
- echo -e "\nCustom kernel settings:" >> "$sc_appdata_path"bench-logs/bench-result.$sc_date
- for ((j=0; j<=${#kp_var[@]} - 1; j++)); do
- echo "${kp_var[$j]}" >> "$sc_appdata_path"bench-logs/bench-result.$sc_date
- done
- fi
- if [ ${#km_var[@]} -gt 0 ]; then
- echo -e "\nRemoved kernel modules:\n${km_var[@]}" >> "$sc_appdata_path"bench-logs/bench-result.$sc_date
- fi
- echo -e "\nPROCESSING BENCHMAK SAMPLES"
- # ---this loop reads "bench-sample" line by line and modifies these lines.
- while read bv_line; do
- echo -n "."
- if `echo $bv_line | grep "swapchain_gl_present" 1>/dev/null 2>&1`; then
- bv_clean_data[${#bv_clean_data[@]}]=$(echo ${bv_line:`expr index "$bv_line" "@"` + 7} | sed -e 's/[A-Za-z]*//g')
- fi
- done < "$sc_appdata_path"bench-logs/bench-sample_fps.$sc_date
- echo "done"
- for ((i=0; i<=${#bv_clean_data[@]} - 1; i++)); do # this loop calculates the average fps
- bv_results=$(echo "$bv_results + ${bv_clean_data[$i]}" | bc)
- done
- echo -e "\nAverage FPS:" >> "$sc_appdata_path"bench-logs/bench-result.$sc_date
- echo "scale=10;$bv_results/${#bv_clean_data[@]}" | bc >> "$sc_appdata_path"bench-logs/bench-result.$sc_date
- fi
- unset i j k l sc_date bv_line bv_clean_data bv_results kp_var kp_var_bak km_var sc_wine_pref sc_exec_path sc_appdata_path
- sudo -K
- echo -e "\nFINISH"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement