Skip to content

Commit

Permalink
run without root permission
Browse files Browse the repository at this point in the history
  • Loading branch information
harp-intel committed Apr 16, 2024
1 parent 1926c25 commit 81c661a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
4 changes: 3 additions & 1 deletion perf-collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,9 @@ def validate_file(fname):
sys.exit()

if os.geteuid() != 0:
crash("Must run PerfSpect as root, please re-run")
logging.warning(
"PerfSpect requires elevated permissions to run. User is not root. Proceeding anyway..."
)

# disable nmi watchdog before collecting perf
nmi_watchdog = perf_helpers.disable_nmi_watchdog()
Expand Down
28 changes: 17 additions & 11 deletions src/perf_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ def disable_nmi_watchdog():
proc_output = subprocess.check_output(["cat", "/proc/sys/kernel/nmi_watchdog"])
nmi_watchdog_status = int(proc_output.decode().strip())
if nmi_watchdog_status == 1:
proc_output = subprocess.check_output(["sysctl", "kernel.nmi_watchdog=0"])
proc_output = subprocess.check_output(
["sysctl", "kernel.nmi_watchdog=0"], stderr=subprocess.STDOUT
)
new_watchdog_status = int(
proc_output.decode().strip().replace("kernel.nmi_watchdog = ", "")
)
Expand All @@ -158,7 +160,7 @@ def disable_nmi_watchdog():
logging.info("nmi_watchdog already disabled. No change needed.")
return nmi_watchdog_status
except (ValueError, FileNotFoundError, subprocess.CalledProcessError) as e:
crash(f"Failed to disable nmi_watchdog: {e}")
logging.warning(f"Failed to disable nmi_watchdog: {e}")


# enable nmi watchdog
Expand All @@ -183,15 +185,19 @@ def set_perf_event_mux_interval(reset, interval_ms, mux_interval):
if os.path.isdir(dirpath):
muxfile = os.path.join(dirpath, "perf_event_mux_interval_ms")
if os.path.isfile(muxfile):
with open(muxfile, "w") as f_mux:
val = 0
if reset:
val = int(mux_interval[f])
else:
if int(mux_interval[f]):
val = int(interval_ms)
if val:
f_mux.write(str(val))
try:
with open(muxfile, "w") as f_mux:
val = 0
if reset:
val = int(mux_interval[f])
else:
if int(mux_interval[f]):
val = int(interval_ms)
if val:
f_mux.write(str(val))
except OSError as e:
logging.warning(f"Failed to write mux interval: {e}")
break


# get linux kernel version
Expand Down

0 comments on commit 81c661a

Please sign in to comment.