blob: 7ec80dcc56b8033b28c495792e6ba52c899f3825 [file] [log] [blame]
Chris Dalton2d802dd2017-09-14 14:18:45 -06001#!/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
8import optparse
9import re
10import subprocess
11import time
12
13
14def 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
28def 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
44if __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