From 632643b5a21957c017f01a47207a7818fb581b8f Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 6 May 2017 19:48:13 -0700 Subject: [PATCH 1/3] android: Add gfxinfo module to parse gfxinfo output Sample usage: g = GfxInfo("results/framestats.txt") print dir(g) print g.janky_frames print g.number_missed_vsync Signed-off-by: Joel Fernandes --- libs/utils/android/gfxinfo.py | 85 +++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 libs/utils/android/gfxinfo.py diff --git a/libs/utils/android/gfxinfo.py b/libs/utils/android/gfxinfo.py new file mode 100755 index 000000000..ec27ec8dc --- /dev/null +++ b/libs/utils/android/gfxinfo.py @@ -0,0 +1,85 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# Copyright (C) 2017, ARM Limited and contributors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Parser for dumpsys gfxinfo output + +import ast + +def get_value(token): + try: + v = ast.literal_eval(token) + except: + return token + return v + +class GfxInfo(object): + """ + Class for parsing and accessing GfxInfo output + """ + __properties = {} + + def __init__(self, path): + """ + Initialize gfxinfo parser object + + :param path: Path to file containing output of gfxinfo + """ + self.path = path + self.parse_gfxinfo() + + def parse_gfxinfo(self): + """ + Parser for gfxinfo output, creates a name/value pair + """ + with open(self.path) as f: + content = f.readlines() + + # gfxinfo has several statistics of the format + # : + for line in content: + line = line.rstrip() + # Ignore any lines that aren't of this format + if not ':' in line or line.endswith(':'): + continue + + tokens = line.split(':') + # convert into a key by replacing spaces with '_' + tokens = [t.strip() for t in tokens] + tokens[0] = tokens[0].replace(' ', '_').lower() + + self.__properties[tokens[0]] = get_value(tokens[1]) + + def __dir__(self): + """ + List all available attributes including ones parsed from + gfxinfo output + """ + return self.__properties.keys() + + def __getattr__(self, name): + """ + Get the gfxinfo property using the period operator + Ex: obj.number_missed_vsync + """ + return self.__properties[name] + + def __getitem__(self, name): + """ + Get the gfxinfo property using the [] opertator + Useful for attributes like "50th_percentile" that can't + be fetched with the period operator + """ + return self.__properties[name] -- GitLab From d110d2ee6b67e7914f0dc69a464806d6de0c8741 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 6 May 2017 20:07:33 -0700 Subject: [PATCH 2/3] android/gfxinfo: Improve parsing for janky frames Special case parsing of janky_frames. As an example, janky_frames is formatted as "42 (24.85%)". This patch splits this into 2 parts and builds 2 separate properties. Signed-off-by: Joel Fernandes --- libs/utils/android/gfxinfo.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libs/utils/android/gfxinfo.py b/libs/utils/android/gfxinfo.py index ec27ec8dc..10192776e 100755 --- a/libs/utils/android/gfxinfo.py +++ b/libs/utils/android/gfxinfo.py @@ -16,7 +16,7 @@ # # Parser for dumpsys gfxinfo output -import ast +import ast, re def get_value(token): try: @@ -60,6 +60,15 @@ class GfxInfo(object): tokens = [t.strip() for t in tokens] tokens[0] = tokens[0].replace(' ', '_').lower() + # Parse janky_frames. Ex: "Janky frames: 44 (26.99%)" + if tokens[0] == 'janky_frames': + (frames, pc) = tokens[1].split(' ') + self.__properties["janky_frames"] = get_value(frames) + pc = re.sub('[\(\)\%]', '', pc) + self.__properties["janky_frames_pc"] = get_value(pc) + continue + + # Regular parsing self.__properties[tokens[0]] = get_value(tokens[1]) def __dir__(self): -- GitLab From 64512fc27c3ae9178820fcea795da063ed3482a1 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Tue, 9 May 2017 07:14:35 -0700 Subject: [PATCH 3/3] android/gfxinfo: Improve parsing for percentiles This improves parsing of: 50th percentile: 5ms 90th percentile: 38ms ..by adding _ms to end of the key, and dropping the ms so it becomes: obj['50th_percentile_ms'] = 5 obj['90th_percentile_ms'] = 38 Signed-off-by: Joel Fernandes --- libs/utils/android/gfxinfo.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/utils/android/gfxinfo.py b/libs/utils/android/gfxinfo.py index 10192776e..7b59fcbca 100755 --- a/libs/utils/android/gfxinfo.py +++ b/libs/utils/android/gfxinfo.py @@ -67,7 +67,10 @@ class GfxInfo(object): pc = re.sub('[\(\)\%]', '', pc) self.__properties["janky_frames_pc"] = get_value(pc) continue - + # Parse 'nth_percentile: ms' into nth_percentile_ms= + if tokens[1].endswith('ms'): + tokens[0] = tokens[0] + '_ms' + tokens[1] = tokens[1][:-2] # Regular parsing self.__properties[tokens[0]] = get_value(tokens[1]) -- GitLab