Skip to content

Commit

Permalink
fix #236
Browse files Browse the repository at this point in the history
  • Loading branch information
rafa0128 committed Nov 20, 2023
1 parent 258be2d commit b91601d
Show file tree
Hide file tree
Showing 3 changed files with 529 additions and 5 deletions.
32 changes: 29 additions & 3 deletions solox/public/apm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from solox.public.adb import adb
from solox.public.common import Devices, File, Method, Platform, Scrcpy
from solox.public.fps import FPSMonitor, TimeUtils
from solox.public.fps_api import FPSMonitor_API, TimeUtils_API


d = Devices()
f = File()
Expand Down Expand Up @@ -340,7 +342,26 @@ def getAndroidFps(self, noLog=False):
else:
logger.exception(e)
return fps, jank


def getAndroidFpsApi(self, noLog=False):
"""get Android Fps, unit:HZ"""
try:
monitors = FPSMonitor_API(device_id=self.deviceId, package_name=self.pkgName, frequency=1,
surfaceview=self.surfaceview, start_time=TimeUtils_API.getCurrentTimeUnderline())
monitors.start()
fps, jank = monitors.stop()
if noLog is False:
apm_time = datetime.datetime.now().strftime('%H:%M:%S.%f')
f.add_log(os.path.join(f.report_dir,'fps.log'), apm_time, fps)
f.add_log(os.path.join(f.report_dir,'jank.log'), apm_time, jank)
except Exception as e:
fps, jank = 0
if len(d.getPid(self.deviceId, self.pkgName)) == 0:
logger.error('[FPS] {} : No process found'.format(self.pkgName))
else:
logger.exception(e)
return fps, jank

def getiOSFps(self, noLog=False):
"""get iOS Fps"""
apm = iosAPM(self.pkgName, self.deviceId)
Expand All @@ -354,6 +375,11 @@ def getFPS(self, noLog=False):
"""get fps、jank"""
fps, jank = self.getAndroidFps(noLog) if self.platform == Platform.Android else self.getiOSFps(noLog)
return fps, jank

def getFPS_API(self, noLog=False):
"""get fps、jank"""
fps, jank = self.getAndroidFpsApi(noLog) if self.platform == Platform.Android else self.getiOSFps(noLog)
return fps, jank

class GPU(object):
def __init__(self, pkgName, deviceId):
Expand Down Expand Up @@ -474,7 +500,7 @@ def collectFps(self):
_fps = FPS(self.pkgName, self.deviceId, self.platform, self.surfaceview)
result = {}
while True:
fps, jank = _fps.getFPS(noLog=self.noLog)
fps, jank = _fps.getFPS_API(noLog=self.noLog)
result = {'fps': fps, 'jank': jank}
logger.info(f'fps: {result}')
if time.time() > self.end_time:
Expand All @@ -486,7 +512,7 @@ def collectGpu(self):
result = {}
while True:
if self.platform == Platform.Android:
raise Exception('not support android')
break
gpu = _gpu.getGPU(noLog=self.noLog)
result = {'gpu': gpu}
logger.info(f'gpu: {result}')
Expand Down
Loading

0 comments on commit b91601d

Please sign in to comment.