Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the script to enable Monsoon power monitor #535

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions benchmarking/frameworks/framework_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def runBenchmark(self, info, benchmark, platform):

program = programs["program"] if "program" in programs else ""
if test["metric"] == "power":
platform_args["power"] = True
platform_args["non_blocking"] = True
method = test.get("method")
platform_args["method"] = method

Expand All @@ -240,6 +240,15 @@ def runBenchmark(self, info, benchmark, platform):
# FIXME "Monsoon" was unimportable
from utils.monsoon_power import collectPowerData

if method == "monsoon_with_usb":
# enter root mode in case we need to disable usb access
if hasattr(platform, "root"):
platform.root()
platform.util.run("wait-for-device")
# disable usb power line if test desires
if "disable_usb" in test:
platform.util.shell(f"echo 1 > {test['disable_usb']}")

# in power metric, the output is ignored
total_num = 0
platform.killProgram(program)
Expand Down Expand Up @@ -290,17 +299,35 @@ def runBenchmark(self, info, benchmark, platform):
test["collection_time"] if "collection_time" in test else 180
)
voltage = float(test["voltage"]) if "voltage" in test else 4.0
threshold = float(test["threshold"] if "threshold" in test else 300)
window_size_in_ms = float(
test["window_size"] if "window_size" in test else 1000
)
# each sample is 200us
window_size = int(window_size_in_ms / 0.2)
output = collectPowerData(
platform.platform_hash,
collection_time,
voltage,
test["iter"],
self.args.monsoon_map,
method=test["method"] if "method" in test else "monsoon",
monsoon_map=self.args.monsoon_map,
threshold=threshold,
window_size=window_size,
)
platform.waitForDevice(20)
# kill the process if exists
platform.killProgram(program)

if method == "monsoon_with_usb":
# re-enable usb power line
if "disable_usb" in test:
platform.util.shell(f"echo 0 > {test['disable_usb']}")
# exit root mode in case we need to disable usb access
if hasattr(platform, "unroot"):
platform.unroot()
platform.util.run("wait-for-device")

# remove the files before copying out the output files
# this will save some time in ios platform, since in ios
# all files are copied back to the host system
Expand Down Expand Up @@ -589,6 +616,11 @@ def _runCommands(
profiling_args.setdefault("types", [default_type])
profiling_args.setdefault("options", {})
platform_args["model_name"] = getModelName(model)
# we only run non_blocking on the last command. Previous commands
# may be set ups for the last command, and should be blocking.
non_blocking = platform_args.get("non_blocking", False)
if non_blocking:
del platform_args["non_blocking"]
for idx, cmd in enumerate(cmds):
# note that we only enable profiling for the last command
# of the main commands.
Expand All @@ -598,6 +630,8 @@ def _runCommands(
else {"enabled": False}
)
platform_args["model_files"] = model_files
if non_blocking and idx == len(cmds) - 1:
platform_args["non_blocking"] = True
one_output = self.runOnPlatform(
total_num, cmd, platform, platform_args, converter
)
Expand Down
14 changes: 7 additions & 7 deletions benchmarking/platforms/android/android_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ def runAppBenchmark(self, cmd, *args, **kwargs):
platform_args = {}
if "platform_args" in kwargs:
platform_args = kwargs["platform_args"]
if "power" in platform_args and platform_args["power"]:
platform_args["non_blocking"] = True
if "non_blocking" in platform_args and platform_args["non_blocking"]:
self.util.shell(["am", "start", "-S", activity])
return []
if platform_args.get("profiling_args", {}).get("enabled", False):
Expand Down Expand Up @@ -236,18 +235,19 @@ def runBinaryBenchmark(self, cmd, *args, **kwargs):
sleep_before_run = str(platform_args["sleep_before_run"])
cmd = ["sleep", sleep_before_run, "&&"] + cmd
del platform_args["sleep_before_run"]
if "power" in platform_args and platform_args["power"]:
if "non_blocking" in platform_args and platform_args["non_blocking"]:
# launch settings page to prevent the phone
# to go into sleep mode
self.util.shell(["am", "start", "-a", "android.settings.SETTINGS"])
self.util.shell(
["am", "start", "-a", "android.settings.SETTINGS"],
ignore_status=True,
)
time.sleep(1)
cmd = (
["nohup"]
+ ["sh", "-c", "'" + " ".join(cmd) + "'"]
+ [">", "/dev/null", "2>&1"]
)
platform_args["non_blocking"] = True
del platform_args["power"]
enable_profiling = platform_args.get("profiling_args", {}).get(
"enabled", False
)
Expand Down Expand Up @@ -354,7 +354,7 @@ def killProgram(self, program):
# if the program doesn't exist, the grep may fail
# do not update status code
success = getRunStatus()
res = self.util.shell(["ps", "|", "grep", basename])
res = self.util.shell(["ps", "|", "grep", basename], ignore_status=True)
setRunStatus(success, overwrite=True)
if len(res) == 0:
return
Expand Down
Loading