Skip to content

Commit 9450c60

Browse files
Varun Purifacebook-github-bot
authored andcommitted
AIBench XCRun wait for benchmark completion on Server-Side
Summary: As titled Reviewed By: cccclai Differential Revision: D53377316 fbshipit-source-id: b2ae6e40656fe84f4b8c33c698035fc992eee480
1 parent b7948e7 commit 9450c60

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

benchmarking/platforms/ios/ios_platform.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,29 @@ def runBenchmark(self, cmd, *args, **kwargs):
195195
with open(logfile, "r") as f:
196196
getLogger().info(f.read())
197197

198+
if self.use_xcrun:
199+
# Since XCRun doesn't provide logs, we generate a file with the logs on the device (for ExecuTorch benchmark) at /tmp/BENCH_LOG. Once the benchmark completes, /tmp/BENCH_DONE will be created.
200+
# The xcrun command to detect fiels takes a while. 15 seconds should be enough for the commandto complete.
201+
timeout = kwargs.get("platform_args", {}).get("timeout", 1200)
202+
while "tmp/BENCH_DONE" not in self.util.listFiles() and timeout >= 0:
203+
time.sleep(15)
204+
timeout -= 15
205+
if "tmp/BENCH_DONE" not in self.util.listFiles():
206+
getLogger().info(
207+
f"Benchmark did not complete within the timeout period ({timeout} seconds)."
208+
)
209+
210+
self.util.pull("/tmp/BENCH_LOG", logfile)
211+
212+
if os.path.isfile(logfile):
213+
logfile_reader = open(logfile, "r")
214+
logfile_contents = logfile_reader.read()
215+
getLogger().info("\n\t[ ======= Benchmark Logs ======= ]")
216+
getLogger().info(logfile_contents)
217+
getLogger().info("\t[ ===== End Benchmark Logs ===== ]\n")
218+
log_screen += logfile_contents
219+
logfile_reader.close()
220+
198221
return log_screen, meta
199222

200223
def rebootDevice(self):

benchmarking/platforms/ios/xcrun.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,35 @@ def pull(self, src, tgt):
8787
"--device",
8888
self.device,
8989
]
90-
self.run(cmd)
90+
return self.run(cmd)
9191

9292
def reboot(self):
9393
cmd = ["reboot", "--device", self.device]
94-
self.run(cmd)
94+
return self.run(cmd)
95+
96+
def listFiles(self):
97+
list_files_cmd = [
98+
"info",
99+
"files",
100+
"--domain-type",
101+
"appDataContainer",
102+
"--domain-identifier",
103+
self.bundle_id,
104+
"--username",
105+
"mobile",
106+
"--device",
107+
self.device,
108+
]
109+
110+
rows = self.run(list_files_cmd)
111+
# All of the files are listed below a line of dashes ----
112+
line_row_idx = 0
113+
for i in range(0, len(rows)):
114+
if rows[i].startswith("----"):
115+
line_row_idx = i
116+
break
117+
118+
return rows[line_row_idx + 1 :]
95119

96120
def deleteFile(self, file, **kwargs):
97121
# files will be deleted when the app is uninstalled
@@ -102,4 +126,4 @@ def batteryLevel(self):
102126
return super().batteryLevel()
103127

104128
def uninstallApp(self, bundle):
105-
self.run(["uninstall", "app", bundle, "--device", self.device])
129+
return self.run(["uninstall", "app", bundle, "--device", self.device])

0 commit comments

Comments
 (0)