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

Parse "all_heaps" option argument correctly for protoBuf format #501

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
4 changes: 2 additions & 2 deletions benchmarking/platforms/android/adb.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ def restart_adbd(self, root=False, silent=False):
getLogger().critical(err_text, exc_info=True)
return False

def deleteFile(self, file):
return self.shell(["rm", "-rf", file])
def deleteFile(self, file, **kwargs):
return self.shell(["rm", "-rf", file], **kwargs)

def shell(self, cmd, **kwargs):
dft = None
Expand Down
5 changes: 0 additions & 5 deletions benchmarking/platforms/android/android_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,6 @@ def _runBenchmarkWithSimpleperf(

def _runBenchmarkWithPerfetto(self, cmd, log_to_screen_only: bool, **platform_args):
# attempt Perfetto profiling
if not self.util.isRootedDevice(silent=True):
raise BenchmarkUnsupportedDeviceException(
f"Attempted to perform perfetto profiling on unrooted device {self.device_label}."
)

with Perfetto(
platform=self,
types=platform_args["profiling_args"]["types"],
Expand Down
4 changes: 3 additions & 1 deletion benchmarking/platforms/platform_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ def moveFilesFromPlatform(self, files, target_dir=None):
basename = os.path.basename(files)
target_file = os.path.join(target_dir, basename)
self.util.pull(files, target_file)
self.util.deleteFile(files)
self.util.deleteFile(
files, silent=True, retry=1
) # this may fail on certain unrooted devices
return target_file
elif isinstance(files, list):
output_files = []
Expand Down
52 changes: 25 additions & 27 deletions benchmarking/profilers/perfetto/perfetto.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Perfetto(ProfilerBase):

CONFIG_FILE = "perfetto.conf"
DEVICE_DIRECTORY = "/data/local/tmp/perf"
DEVICE_TRACE_DIRECTORY = "/data/misc/perfetto-traces"
TRACING_PROPERTY = "persist.traced.enable"
DEFAULT_TIMEOUT = 5
BUFFER_SIZE_KB_DEFAULT = 256 * 1024 # 256 megabytes
Expand Down Expand Up @@ -93,13 +94,13 @@ def __init__(
self.restoreState = False
self.perfetto_pid = None
self.all_heaps_config = (
f"\t\t\tall_heaps: {self.options.get('all_heaps', 'false')}"
if self.android_version >= 12
" all_heaps: true\n"
if self.android_version >= 12 and self.options.get("all_heaps", False)
else ""
)
self.basename = generate_perf_filename(model_name, self.platform.platform_hash)
self.trace_file_name = f"{self.basename}.perfetto-trace"
self.trace_file_device = f"{self.DEVICE_DIRECTORY}/{self.trace_file_name}"
self.trace_file_device = f"{self.DEVICE_TRACE_DIRECTORY}/{self.trace_file_name}"
self.config_file = f"{self.basename}.{self.CONFIG_FILE}"
self.config_file_device = f"{self.DEVICE_DIRECTORY}/{self.config_file}"
self.config_file_host = None
Expand All @@ -121,11 +122,14 @@ def __init__(
.lower()
)
self.perfetto_cmd = [
"cat",
self.config_file_device,
"|",
"perfetto",
"-d",
"--txt",
"-c",
self.config_file_device,
"-",
"-o",
self.trace_file_device,
]
Expand All @@ -146,10 +150,6 @@ def _start(self):
raise BenchmarkUnsupportedDeviceException(
f"Attempt to run perfetto on {self.platform.type} {self.platform.rel_version} device {self.platform.device_label} ignored."
)
if not self.is_rooted_device:
raise BenchmarkUnsupportedDeviceException(
f"Attempt to run perfetto on unrooted device {self.platform.device_label} ignored."
)

try:
getLogger().info(
Expand All @@ -160,13 +160,6 @@ def _start(self):
# Generate and upload custom config file
getLogger().info(f"Perfetto profile type(s) = {', '.join(self.types)}.")
self._setup_perfetto_config()
"""
# Ensure no old instances of perfetto are running on the device
self.adb.shell(
["killall", "perfetto"],
timeout=DEFAULT_TIMEOUT,
)
"""

# call Perfetto
output = self._perfetto()
Expand Down Expand Up @@ -303,17 +296,18 @@ def _signalPerfetto(self) -> bool:
getLogger().info(f"Running '{' '.join(cmd)}' returned {result}.")

def _setStateForPerfetto(self):
if not self.user_was_root:
self.adb.root()
if self.is_rooted_device:
if not self.user_was_root:
self.adb.root()

# Set SELinux to permissive mode if not already
if self.original_SELinux_policy == "enforcing":
self.adb.shell(
["setenforce", "0"],
timeout=self.DEFAULT_TIMEOUT,
retry=1,
)
self.restoreState = True
# Set SELinux to permissive mode if not already
if self.is_rooted_device and self.original_SELinux_policy == "enforcing":
self.adb.shell(
["setenforce", "0"],
timeout=self.DEFAULT_TIMEOUT,
retry=1,
)
self.restoreState = True

# Enable Perfetto if not yet enabled.
getprop_tracing_enabled = self.adb.getprop(
Expand Down Expand Up @@ -446,10 +440,14 @@ def _setup_perfetto_config(
def _perfetto(self):
"""Run perfetto on platform with benchmark process id."""
getLogger().info(f"Calling perfetto: {self.perfetto_cmd}")
output = self.platform.util.shell(self.perfetto_cmd)
output = self.platform.util.shell(
self.perfetto_cmd, retry=1
) # Don't retry due to risk of leaving 2 copies running
getLogger().info(f"Perfetto returned: {output}.")

# longer delay if all_heaps is specified
startup_time: float = 2.0 if self.all_heaps_config != "" else 0.2
time.sleep(startup_time) # give it time to spin up
time.sleep(startup_time) # give perfetto time to spin up
return output

def _copyPerfDataToHost(self):
Expand Down