1#!/usr/bin/python 2# 3# SPDX-License-Identifier: Apache-2.0 4# 5# Copyright (C) 2015, ARM Limited and contributors. 6# 7# Licensed under the Apache License, Version 2.0 (the "License"); you may 8# not use this file except in compliance with the License. 9# You may obtain a copy of the License at 10# 11# http://www.apache.org/licenses/LICENSE-2.0 12# 13# Unless required by applicable law or agreed to in writing, software 14# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16# See the License for the specific language governing permissions and 17# limitations under the License. 18# 19 20import sys 21# sys.path.insert(1, "./libs") 22 23from perf_analysis import PerfAnalysis 24from trace import Trace 25 26import os 27import re 28import argparse 29import json 30 31# Configure logging 32import logging 33reload(logging) 34logging.basicConfig( 35 format='%(asctime)-9s %(levelname)-8s: %(message)s', 36 level=logging.DEBUG, 37 # level=logging.INFO, 38 datefmt='%I:%M:%S') 39 40# Regexp to match the format of a result folder 41TEST_DIR_RE = re.compile( 42 r'([^:]*):([^:]*):([^:]*)' 43 ) 44 45parser = argparse.ArgumentParser( 46 description='EAS Performance and Trace Plotter') 47parser.add_argument('--results', type=str, 48 default='./results_latest', 49 help='Folder containing experimental results') 50parser.add_argument('--outdir', type=str, 51 default=None, 52 help='A single output folder we want to produce plots for') 53parser.add_argument('--tmin', type=float, 54 default=None, 55 help='Minimum timestamp for all plots') 56parser.add_argument('--tmax', type=float, 57 default=None, 58 help='Maximum timestamp for all plots') 59parser.add_argument('--plots', type=str, 60 default='all', 61 help='List of plots to produce (all,') 62 63args = None 64 65def main(): 66 global args 67 args = parser.parse_args() 68 69 # Setup plots to produce 70 if args.plots == 'all': 71 args.plots = 'tasks clusters cpus stune ediff edspace' 72 73 # For each rtapp and each run 74 if args.outdir is not None: 75 76 # Load platform descriptior 77 platform = None 78 plt_file = os.path.join(args.outdir, 'platform.json') 79 if os.path.isfile(plt_file): 80 with open(plt_file, 'r') as ifile: 81 platform = json.load(ifile) 82 logging.info('Platform description:') 83 logging.info(' %s', platform) 84 85 # Plot the specified results folder 86 return plotdir(args.outdir, platform) 87 88 for test_idx in sorted(os.listdir(args.results)): 89 90 match = TEST_DIR_RE.search(test_idx) 91 if match == None: 92 continue 93 wtype = match.group(1) 94 conf_idx = match.group(2) 95 wload_idx = match.group(3) 96 97 98 # Generate performance plots only for RTApp workloads 99 if wtype != 'rtapp': 100 continue 101 102 logging.debug('Processing [%s:%s:%s]...', 103 wtype, conf_idx, wload_idx) 104 105 # For each run of an rt-app workload 106 test_dir = os.path.join(args.results, test_idx) 107 108 # Load platform descriptior 109 platform = None 110 plt_file = os.path.join(test_dir, 'platform.json') 111 if os.path.isfile(plt_file): 112 with open(plt_file, 'r') as ifile: 113 platform = json.load(ifile) 114 logging.info('Platform description:') 115 logging.info(' %s', platform) 116 117 for run_idx in sorted(os.listdir(test_dir)): 118 119 run_dir = os.path.join(test_dir, run_idx) 120 try: 121 run_id = int(run_idx) 122 except ValueError: 123 continue 124 125 logging.info('Generate plots for [%s]...', run_dir) 126 plotdir(run_dir, platform) 127 128def plotdir(run_dir, platform): 129 global args 130 tasks = None 131 pa = None 132 133 # Load RTApp performance data 134 try: 135 pa = PerfAnalysis(run_dir) 136 137 # Get the list of RTApp tasks 138 tasks = pa.tasks() 139 logging.info('Tasks: %s', tasks) 140 except ValueError: 141 pa = None 142 logging.info('No performance data found') 143 144 # Load Trace Analysis modules 145 trace = Trace(platform, run_dir) 146 147 # Define time ranges for all the temporal plots 148 trace.setXTimeRange(args.tmin, args.tmax) 149 150 # Tasks plots 151 if 'tasks' in args.plots: 152 trace.analysis.tasks.plotTasks(tasks) 153 if pa: 154 for task in tasks: 155 pa.plotPerf(task) 156 157 # Cluster and CPUs plots 158 if 'clusters' in args.plots: 159 trace.analysis.frequency.plotClusterFrequencies() 160 if 'cpus' in args.plots: 161 trace.analysis.cpus.plotCPU() 162 163 # SchedTune plots 164 if 'stune' in args.plots: 165 trace.analysis.eas.plotSchedTuneConf() 166 if 'ediff' in args.plots: 167 trace.analysis.eas.plotEDiffTime(); 168 if 'edspace' in args.plots: 169 trace.analysis.eas.plotEDiffSpace(); 170 171if __name__ == "__main__": 172 main() 173