1484543d1Sopenharmony_ci#!/usr/bin/env python3 2484543d1Sopenharmony_ci# coding=utf-8 3484543d1Sopenharmony_ci# Copyright (c) 2023 Huawei Device Co., Ltd. 4484543d1Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 5484543d1Sopenharmony_ci# you may not use this file except in compliance with the License. 6484543d1Sopenharmony_ci# You may obtain a copy of the License at 7484543d1Sopenharmony_ci# 8484543d1Sopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 9484543d1Sopenharmony_ci# 10484543d1Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software 11484543d1Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 12484543d1Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13484543d1Sopenharmony_ci# See the License for the specific language governing permissions and 14484543d1Sopenharmony_ci# limitations under the License. 15484543d1Sopenharmony_ci 16484543d1Sopenharmony_ciimport os 17484543d1Sopenharmony_ciimport sys 18484543d1Sopenharmony_ciimport pandas 19484543d1Sopenharmony_cifrom matplotlib import pyplot 20484543d1Sopenharmony_ci 21484543d1Sopenharmony_cistall = [ 22484543d1Sopenharmony_ci 0, 5, 10, 15, 20, 25, 30, 35, 40, 50, 23484543d1Sopenharmony_ci 60, 70, 80, 90, 100, 120, 140, 160, 180, 200 24484543d1Sopenharmony_ci] 25484543d1Sopenharmony_ci 26484543d1Sopenharmony_ci 27484543d1Sopenharmony_cidef draw_fig(ax, base, data, title): 28484543d1Sopenharmony_ci label = title[:-4] 29484543d1Sopenharmony_ci thread = title[-3:] 30484543d1Sopenharmony_ci 31484543d1Sopenharmony_ci # get optimization ratio 32484543d1Sopenharmony_ci avg = sum(data) / len(data) 33484543d1Sopenharmony_ci avg_base = base['_'.join([label, 'base', thread])].mean() 34484543d1Sopenharmony_ci ratio = str(round((avg_base - avg) / avg_base, 3)) 35484543d1Sopenharmony_ci 36484543d1Sopenharmony_ci data_base = [float(base['_'.join([label, 'base', thread])][i]) 37484543d1Sopenharmony_ci for i in range(len(stall))] 38484543d1Sopenharmony_ci ax.plot(stall, data_base, 's-', label='_'.join([label, 'base'])) 39484543d1Sopenharmony_ci ax.plot(stall, data, 'o-', label=label) 40484543d1Sopenharmony_ci ax.legend(loc='best') 41484543d1Sopenharmony_ci ax.set_title(''.join([title, '[R:', ratio, ']'])) 42484543d1Sopenharmony_ci 43484543d1Sopenharmony_ci 44484543d1Sopenharmony_cidef main(argv): 45484543d1Sopenharmony_ci path = argv[1] 46484543d1Sopenharmony_ci out = argv[2] 47484543d1Sopenharmony_ci 48484543d1Sopenharmony_ci # read csv 49484543d1Sopenharmony_ci base = pandas.read_csv(os.path.join(path, 'base.csv')) 50484543d1Sopenharmony_ci t1 = pandas.read_csv(os.path.join(path, 'perf_thread1.csv')) 51484543d1Sopenharmony_ci t8 = pandas.read_csv(os.path.join(path, 'perf_thread8.csv')) 52484543d1Sopenharmony_ci 53484543d1Sopenharmony_ci # get actual data 54484543d1Sopenharmony_ci t1_fork_join = [(t1[' fork_join'][i] / t1['repeat'][i] * 55484543d1Sopenharmony_ci 1 - stall[i] * 10000) / 10000 for i in range(len(stall))] 56484543d1Sopenharmony_ci t1_fork_join_worker_submit = [(t1['fork_join_worker_submit'][i] / t1['repeat'] 57484543d1Sopenharmony_ci [i] * 1 - stall[i] * 10000) / 10000 for i in range(len(stall))] 58484543d1Sopenharmony_ci t1_airaw = [(t1['airaw'][i] / t1['repeat'][i] * 1 - stall[i] 59484543d1Sopenharmony_ci * 2400 * 3) / 2400 / 3 for i in range(len(stall))] 60484543d1Sopenharmony_ci t1_airaw_worker_submit = [(t1['airaw_worker_submit'][i] / t1['repeat'] 61484543d1Sopenharmony_ci [i] * 1 - stall[i] * 2400 * 3) / 2400 / 3 for i in range(len(stall))] 62484543d1Sopenharmony_ci t1_fib_data_wait = [(t1['fib_data_wait'][i] / t1['repeat'][i] 63484543d1Sopenharmony_ci * 1 - stall[i] * 21890) / 21890 for i in range(len(stall))] 64484543d1Sopenharmony_ci t1_fib_child_wait = [(t1['fib_child_wait'][i] / t1['repeat'][i] 65484543d1Sopenharmony_ci * 1 - stall[i] * 21890) / 21890 for i in range(len(stall))] 66484543d1Sopenharmony_ci t1_fib_no_wait = [(t1['fib_no_wait'][i] / t1['repeat'][i] 67484543d1Sopenharmony_ci * 1 - stall[i] * 21890) / 21890 for i in range(len(stall))] 68484543d1Sopenharmony_ci t8_fork_join = [(t8[' fork_join'][i] / t8['repeat'][i] * 69484543d1Sopenharmony_ci 8 - stall[i] * 10000) / 10000 for i in range(len(stall))] 70484543d1Sopenharmony_ci t8_fork_join_worker_submit = [(t8['fork_join_worker_submit'][i] / t8['repeat'] 71484543d1Sopenharmony_ci [i] * 8 - stall[i] * 10000) / 10000 for i in range(len(stall))] 72484543d1Sopenharmony_ci t8_airaw = [(t8['airaw'][i] / t8['repeat'][i] * 3 - stall[i] 73484543d1Sopenharmony_ci * 2400 * 3) / 2400 / 3 for i in range(len(stall))] 74484543d1Sopenharmony_ci t8_airaw_worker_submit = [(t8['airaw_worker_submit'][i] / t8['repeat'] 75484543d1Sopenharmony_ci [i] * 3 - stall[i] * 2400 * 3) / 2400 / 3 for i in range(len(stall))] 76484543d1Sopenharmony_ci t8_fib_data_wait = [(t8['fib_data_wait'][i] / t8['repeat'][i] 77484543d1Sopenharmony_ci * 8 - stall[i] * 21890) / 21890 for i in range(len(stall))] 78484543d1Sopenharmony_ci t8_fib_child_wait = [(t8['fib_child_wait'][i] / t8['repeat'][i] 79484543d1Sopenharmony_ci * 8 - stall[i] * 21890) / 21890 for i in range(len(stall))] 80484543d1Sopenharmony_ci t8_fib_no_wait = [(t8['fib_no_wait'][i] / t8['repeat'][i] 81484543d1Sopenharmony_ci * 8 - stall[i] * 21890) / 21890 for i in range(len(stall))] 82484543d1Sopenharmony_ci 83484543d1Sopenharmony_ci # draw figure 84484543d1Sopenharmony_ci fig, ax = pyplot.subplots(2, 7, figsize=(30, 8)) 85484543d1Sopenharmony_ci 86484543d1Sopenharmony_ci draw_fig(ax[0, 0], base, t1_fork_join, 'fork_join_1th') 87484543d1Sopenharmony_ci draw_fig(ax[0, 1], base, t1_fork_join_worker_submit, 88484543d1Sopenharmony_ci 'fork_join_worker_submit_1th') 89484543d1Sopenharmony_ci draw_fig(ax[0, 2], base, t1_airaw, 'airaw_1th') 90484543d1Sopenharmony_ci draw_fig(ax[0, 3], base, t1_airaw_worker_submit, 'airaw_worker_submit_1th') 91484543d1Sopenharmony_ci draw_fig(ax[0, 4], base, t1_fib_data_wait, 'fib20_data_wait_1th') 92484543d1Sopenharmony_ci draw_fig(ax[0, 5], base, t1_fib_child_wait, 'fib20_child_wait_1th') 93484543d1Sopenharmony_ci draw_fig(ax[0, 6], base, t1_fib_no_wait, 'fib20_no_wait_1th') 94484543d1Sopenharmony_ci draw_fig(ax[1, 0], base, t8_fork_join, 'fork_join_8th') 95484543d1Sopenharmony_ci draw_fig(ax[1, 1], base, t8_fork_join_worker_submit, 96484543d1Sopenharmony_ci 'fork_join_worker_submit_8th') 97484543d1Sopenharmony_ci draw_fig(ax[1, 2], base, t8_airaw, 'airaw_8th') 98484543d1Sopenharmony_ci draw_fig(ax[1, 3], base, t8_airaw_worker_submit, 'airaw_worker_submit_8th') 99484543d1Sopenharmony_ci draw_fig(ax[1, 4], base, t8_fib_data_wait, 'fib20_data_wait_8th') 100484543d1Sopenharmony_ci draw_fig(ax[1, 5], base, t8_fib_child_wait, 'fib20_child_wait_8th') 101484543d1Sopenharmony_ci draw_fig(ax[1, 6], base, t8_fib_no_wait, 'fib20_no_wait_8th') 102484543d1Sopenharmony_ci 103484543d1Sopenharmony_ci fig.savefig(os.path.join(path, out)) 104484543d1Sopenharmony_ci 105484543d1Sopenharmony_ci 106484543d1Sopenharmony_ciif __name__ == '__main__': 107484543d1Sopenharmony_ci main(sys.argv) 108