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 logging
19484543d1Sopenharmony_ciimport pandas
20484543d1Sopenharmony_cifrom matplotlib import pyplot as plt
21484543d1Sopenharmony_ci
22484543d1Sopenharmony_ci# Gets the minimum value greater than 1
23484543d1Sopenharmony_ci
24484543d1Sopenharmony_ci
25484543d1Sopenharmony_cidef get_speedup_1_duration(data):
26484543d1Sopenharmony_ci    p = 0
27484543d1Sopenharmony_ci    for i in range(len(data)):
28484543d1Sopenharmony_ci        if(data['speedup'][i] > 1 and data['speedup'][i] < data['speedup'][p]):
29484543d1Sopenharmony_ci            p = i
30484543d1Sopenharmony_ci    return data['duration'][p]
31484543d1Sopenharmony_ci
32484543d1Sopenharmony_ci
33484543d1Sopenharmony_cidef plot_current_only(argv):
34484543d1Sopenharmony_ci    current_data = argv[1]
35484543d1Sopenharmony_ci    fig = plt.figure()
36484543d1Sopenharmony_ci
37484543d1Sopenharmony_ci    current = pandas.read_csv(current_data, delim_whitespace=True)
38484543d1Sopenharmony_ci    min_duration = get_speedup_1_duration(current)
39484543d1Sopenharmony_ci
40484543d1Sopenharmony_ci    plt.plot(current['duration'], current['speedup'],
41484543d1Sopenharmony_ci             color='r', marker='o', linestyle='-', label=''.join(['speedup=1@duration=',  str(min_duration)]))
42484543d1Sopenharmony_ci
43484543d1Sopenharmony_ci    plt.legend(loc='best')
44484543d1Sopenharmony_ci    plt.xlabel('task_duration(us)')
45484543d1Sopenharmony_ci    plt.ylabel('speedup')
46484543d1Sopenharmony_ci    plt.title('ffrt speedup test', fontsize=20)
47484543d1Sopenharmony_ci    plt.savefig("speedup.jpg")
48484543d1Sopenharmony_ci
49484543d1Sopenharmony_ci
50484543d1Sopenharmony_cidef plot_current_vs_base(argv):
51484543d1Sopenharmony_ci    current_data = argv[1]
52484543d1Sopenharmony_ci    if len(argv) <= 2:
53484543d1Sopenharmony_ci        logging.warning('no base data')
54484543d1Sopenharmony_ci        return
55484543d1Sopenharmony_ci    else:
56484543d1Sopenharmony_ci        base_data = argv[2]
57484543d1Sopenharmony_ci
58484543d1Sopenharmony_ci    fig = plt.figure()
59484543d1Sopenharmony_ci
60484543d1Sopenharmony_ci    base = pandas.read_csv(base_data, delim_whitespace=True)
61484543d1Sopenharmony_ci    base_min_duration = get_speedup_1_duration(base)
62484543d1Sopenharmony_ci
63484543d1Sopenharmony_ci    plt.plot(base['duration'], base['speedup'], color='b',
64484543d1Sopenharmony_ci             marker='s', linestyle='-.', label=''.join(['base speedup=1@duration=',  str(base_min_duration)]))
65484543d1Sopenharmony_ci
66484543d1Sopenharmony_ci    current = pandas.read_csv(current_data, delim_whitespace=True)
67484543d1Sopenharmony_ci    current_min_duration = get_speedup_1_duration(current)
68484543d1Sopenharmony_ci
69484543d1Sopenharmony_ci    plt.plot(current['duration'], current['speedup'],
70484543d1Sopenharmony_ci             color='r', marker='o', linestyle='-', label=''.join(['curren speedup=1@duration=',  str(current_min_duration)]))
71484543d1Sopenharmony_ci
72484543d1Sopenharmony_ci    plt.legend(loc='best')
73484543d1Sopenharmony_ci    plt.xlabel('task_duration(us)')
74484543d1Sopenharmony_ci    plt.ylabel('speedup')
75484543d1Sopenharmony_ci    plt.title('ffrt speedup test', fontsize=20)
76484543d1Sopenharmony_ci    plt.savefig("speedup_vs_base.jpg")
77484543d1Sopenharmony_ci
78484543d1Sopenharmony_ci
79484543d1Sopenharmony_ciif __name__ == '__main__':
80484543d1Sopenharmony_ci    plot_current_vs_base(sys.argv)
81484543d1Sopenharmony_ci    plot_current_only(sys.argv)
82