1#!/usr/bin/env python 2 3# Copyright 2017 Google Inc. 4# 5# Use of this source code is governed by a BSD-style license that can be 6# found in the LICENSE file. 7 8 9from __future__ import print_function 10import optparse 11import re 12import subprocess 13import time 14 15 16def query_surfaceflinger_frame_count(): 17 parcel = subprocess.Popen("adb shell service call SurfaceFlinger 1013", 18 stdout=subprocess.PIPE, stderr=subprocess.PIPE, 19 shell=True).communicate()[0] 20 if not parcel: 21 raise Exception("FAILED: adb shell service call SurfaceFlinger 1013") 22 23 framecount = re.search("Result: Parcel\(([a-f0-9]+) ", parcel) 24 if not framecount: 25 raise Exception("Unexpected result from SurfaceFlinger: " + parcel) 26 27 return int(framecount.group(1), 16) 28 29 30def main(interval): 31 startframe = query_surfaceflinger_frame_count() 32 starttime = time.time() 33 34 while True: 35 time.sleep(interval) 36 37 endframe = query_surfaceflinger_frame_count() 38 endtime = time.time() 39 fps = (endframe - startframe) / (endtime - starttime) 40 print("%.2f" % fps) 41 42 startframe = endframe 43 starttime = endtime 44 45 46if __name__ == '__main__': 47 parser = optparse.OptionParser() 48 parser.add_option("-i", "--interval", type="int", default="2", 49 help="Number of seconds to count frames.") 50 options, args = parser.parse_args() 51 main(options.interval) 52 53