1#!/usr/bin/env python3 2# coding=utf-8 3# Copyright (c) 2023 Huawei Device Co., Ltd. 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16import os 17import sys 18import logging 19import pandas 20from matplotlib import pyplot as plt 21 22 23def plot_current_olny(argv): 24 current_data = argv[1] 25 fig = plt.figure() 26 27 current = pandas.read_csv(current_data, delim_whitespace=True) 28 plt.plot(current['duration'], current['sched_time'], 29 color='r', marker='o', linestyle='-', label='current') 30 31 avg = sum(current['sched_time']) / len(current['sched_time']) 32 33 plt.xlabel('task_duration(us)') 34 plt.ylabel('sched_time(us)') 35 plt.title(''.join( 36 ['ffrt sched_time test [avg:', str(round(avg, 2)), ' us]']), fontsize=20) 37 plt.savefig("serial_sched_time.jpg") 38 39 40def plot_current_vs_base(argv): 41 current_data = argv[1] 42 if len(argv) <= 2: 43 logging.warning('no base data') 44 return 45 else: 46 base_data = argv[2] 47 fig = plt.figure() 48 49 base = pandas.read_csv(base_data, delim_whitespace=True) 50 base_avg = sum(base['sched_time']) / len(base['sched_time']) 51 plt.plot(base['duration'], base['sched_time'], color='b', 52 marker='s', linestyle='-.', label=''.join(['base avg:', str(round(base_avg, 2))])) 53 54 current = pandas.read_csv(current_data, delim_whitespace=True) 55 current_avg = sum(current['sched_time']) / len(current['sched_time']) 56 plt.plot(current['duration'], current['sched_time'], 57 color='r', marker='o', linestyle='-', label=''.join(['current avg:', str(round(current_avg, 2))])) 58 59 ratio = (current_avg - base_avg) / base_avg 60 61 plt.legend(loc='best') 62 plt.xlabel('task_duration(us)') 63 plt.ylabel('sched_time(us)') 64 plt.title(''.join(['ffrt serial sched time vs base [Ratio:', str( 65 round(ratio * 100, 2)), '%]']), fontsize=15) 66 plt.savefig("serial_sched_time_vs_base.jpg") 67 68 69if __name__ == '__main__': 70 plot_current_vs_base(sys.argv) 71 plot_current_olny(sys.argv) 72