Chris Dalton | 2d802dd | 2017-09-14 14:18:45 -0600 | [diff] [blame] | 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 | import optparse |
| 9 | import re |
| 10 | import subprocess |
| 11 | import time |
| 12 | |
| 13 | |
| 14 | def query_surfaceflinger_frame_count(): |
| 15 | parcel = subprocess.Popen("adb shell service call SurfaceFlinger 1013", |
| 16 | stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
| 17 | shell=True).communicate()[0] |
| 18 | if not parcel: |
| 19 | raise Exception("FAILED: adb shell service call SurfaceFlinger 1013") |
| 20 | |
| 21 | framecount = re.search("Result: Parcel\(([a-f0-9]+) ", parcel) |
| 22 | if not framecount: |
| 23 | raise Exception("Unexpected result from SurfaceFlinger: " + parcel) |
| 24 | |
| 25 | return int(framecount.group(1), 16) |
| 26 | |
| 27 | |
| 28 | def main(interval): |
| 29 | startframe = query_surfaceflinger_frame_count() |
| 30 | starttime = time.time() |
| 31 | |
| 32 | while True: |
| 33 | time.sleep(interval) |
| 34 | |
| 35 | endframe = query_surfaceflinger_frame_count() |
| 36 | endtime = time.time() |
| 37 | fps = (endframe - startframe) / (endtime - starttime) |
| 38 | print "%.2f" % fps |
| 39 | |
| 40 | startframe = endframe |
| 41 | starttime = endtime |
| 42 | |
| 43 | |
| 44 | if __name__ == '__main__': |
| 45 | parser = optparse.OptionParser() |
| 46 | parser.add_option("-i", "--interval", type="int", default="2", |
| 47 | help="Number of seconds to count frames.") |
| 48 | options, args = parser.parse_args() |
| 49 | main(options.interval) |
| 50 | |