1#!/usr/bin/env python 2# SPDX-License-Identifier: Apache-2.0 3# 4# Copyright (C) 2017, ARM Limited, Google, and contributors. 5# 6# Licensed under the Apache License, Version 2.0 (the "License"); you may 7# not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17# 18 19import os 20import json 21import argparse 22from trace import Trace 23 24def run_queue_analysis(trace, threshold): 25 """ 26 Plot the queuing delay distribution and 27 severely delayed tasks. 28 29 :param trace: input Trace object 30 :type trace: :mod:`libs.utils.Trace` 31 32 :param threshold: plot transactions taken longer than threshold 33 :type threshold: int 34 """ 35 df = trace.data_frame.queue_df() 36 trace.analysis.binder_transaction.plot_samples(df, "delta_t", 37 "transaction samples", 38 "wait time (microseconds)") 39 trace.analysis.binder_transaction.plot_tasks(df, threshold, "__comm_x", 40 "delta_t", "tasks", 41 "wait time (microseconds)") 42 return df 43 44def run_buffer_analysis(trace, threshold): 45 """ 46 Plot the buffer size distribution and big transactions. 47 48 :param trace: input Trace object 49 :type trace: :mod:`libs.utils.Trace` 50 51 :param threshold: plot buffers larger than threshold 52 :type threshold: int 53 """ 54 df = trace.data_frame.alloc_df() 55 trace.analysis.binder_transaction.plot_samples(df, "size", 56 "sample trace points", 57 "buffersize (bytes)") 58 trace.analysis.binder_transaction.plot_tasks(df, threshold, 59 "__pid_x", "size", 60 "proc_id", 61 "buffersize (bytes)") 62 return df 63 64def run_alloc_analysis(trace, threshold): 65 """ 66 Plot the runtime of buffer allocator. 67 68 :param trace: input Trace object 69 :type trace: :mod:`libs.utils.Trace` 70 71 :param threshold: plot allocations took less than threshold 72 :type threshold: int 73 """ 74 df = trace.data_frame.alloc_df() 75 trace.analysis.binder_transaction.plot_samples(df, "delta_t", 76 "transaction samples", 77 "alloc time (microseconds)", 78 ymax=threshold) 79 return df 80 81parser = argparse.ArgumentParser( 82 description="Plot transaction data and write dataframe to a csv file.") 83parser.add_argument("--res_dir","-d", type=str, 84 help="Directory that contains trace.html.") 85parser.add_argument("--analysis_type", "-t", type=str, 86 choices=["queue", "buffer", "alloc"], 87 help="Analysis type. Available options: 'queue'" 88 "(target queue wait time), 'buffer' (binder buffer size)" 89 "and 'alloc' (allocation time).") 90parser.add_argument("--threshold", "-th", type=int, 91 help="Threshold above which a task or buffer will be" 92 "captured or below which an allocation will be captured" 93 "(microseconds for queuing delay and allocation time," 94 "bytes for buffer size).") 95 96if __name__ == "__main__": 97 args = parser.parse_args() 98 99 platform_file = os.path.join(args.res_dir, "platform.json") 100 with open(platform_file, 'r') as fh: 101 platform = json.load(fh) 102 trace_file = os.path.join(args.res_dir, "trace.html") 103 events = ["binder_transaction", 104 "binder_transaction_received", 105 "binder_transaction_alloc_buf"] 106 trace = Trace(platform, trace_file, events) 107 108 if args.analysis_type == "queue": 109 df = run_queue_analysis(trace, args.threshold) 110 elif args.analysis_type == "buffer": 111 df = run_buffer_analysis(trace, args.threshold) 112 else: 113 df = run_alloc_analysis(trace, args.threshold) 114 115 df.to_csv(os.path.join(args.res_dir, "analysis_df.csv")) 116