Skip to content

Commit

Permalink
Make encoding explicit in denoise.py
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Marr <[email protected]>
  • Loading branch information
smarr committed Nov 9, 2024
1 parent aa90dd4 commit ed94f61
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions rebench/denoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ def _set_scaling_governor(governor, num_cores):
filename = (
"/sys/devices/system/cpu/cpu" + str(cpu_i) + "/cpufreq/scaling_governor"
)
with open(
filename, "w"
) as gov_file: # pylint: disable=unspecified-encoding
with open(filename, "w", encoding="utf-8") as gov_file:
gov_file.write(governor + "\n")
except IOError:
return "failed"
Expand All @@ -208,8 +206,9 @@ def _set_no_turbo(with_no_turbo):
value = "0"

try:
# pylint: disable-next=unspecified-encoding
with open("/sys/devices/system/cpu/intel_pstate/no_turbo", "w") as nt_file:
with open(
"/sys/devices/system/cpu/intel_pstate/no_turbo", "w", encoding="utf-8"
) as nt_file:
nt_file.write(value + "\n")
except IOError:
return "failed"
Expand All @@ -218,22 +217,25 @@ def _set_no_turbo(with_no_turbo):

def _configure_perf_sampling(for_profiling):
try:
# pylint: disable-next=unspecified-encoding
with open("/proc/sys/kernel/perf_cpu_time_max_percent", "w") as perc_file:
with open(
"/proc/sys/kernel/perf_cpu_time_max_percent", "w", encoding="utf-8"
) as perc_file:
if for_profiling:
perc_file.write("0\n")
else:
perc_file.write("1\n")

# pylint: disable-next=unspecified-encoding
with open("/proc/sys/kernel/perf_event_max_sample_rate", "w") as sample_file:
with open(
"/proc/sys/kernel/perf_event_max_sample_rate", "w", encoding="utf-8"
) as sample_file:
# for profiling we just disabled it above, and then don't need to set it
if not for_profiling:
sample_file.write("1\n")

if for_profiling:
# pylint: disable-next=unspecified-encoding
with open("/proc/sys/kernel/perf_event_paranoid", "w") as perf_file:
with open(
"/proc/sys/kernel/perf_event_paranoid", "w", encoding="utf-8"
) as perf_file:
perf_file.write("-1\n")
except IOError:
return "failed"
Expand All @@ -246,16 +248,19 @@ def _configure_perf_sampling(for_profiling):

def _restore_perf_sampling():
try:
# pylint: disable-next=unspecified-encoding
with open("/proc/sys/kernel/perf_cpu_time_max_percent", "w") as perc_file:
with open(
"/proc/sys/kernel/perf_cpu_time_max_percent", "w", encoding="utf-8"
) as perc_file:
perc_file.write("25\n")

# pylint: disable-next=unspecified-encoding
with open("/proc/sys/kernel/perf_event_max_sample_rate", "w") as sample_file:
with open(
"/proc/sys/kernel/perf_event_max_sample_rate", "w", encoding="utf-8"
) as sample_file:
sample_file.write("50000\n")

# pylint: disable-next=unspecified-encoding
with open("/proc/sys/kernel/perf_event_paranoid", "w") as perf_file:
with open(
"/proc/sys/kernel/perf_event_paranoid", "w", encoding="utf-8"
) as perf_file:
perf_file.write("3\n")
except IOError:
return "failed"
Expand Down

0 comments on commit ed94f61

Please sign in to comment.