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# Gets the minimum value greater than 1
23
24
25def get_speedup_1_duration(data):
26    p = 0
27    for i in range(len(data)):
28        if(data['speedup'][i] > 1 and data['speedup'][i] < data['speedup'][p]):
29            p = i
30    return data['duration'][p]
31
32
33def plot_current_only(argv):
34    current_data = argv[1]
35    fig = plt.figure()
36
37    current = pandas.read_csv(current_data, delim_whitespace=True)
38    min_duration = get_speedup_1_duration(current)
39
40    plt.plot(current['duration'], current['speedup'],
41             color='r', marker='o', linestyle='-', label=''.join(['speedup=1@duration=',  str(min_duration)]))
42
43    plt.legend(loc='best')
44    plt.xlabel('task_duration(us)')
45    plt.ylabel('speedup')
46    plt.title('ffrt speedup test', fontsize=20)
47    plt.savefig("speedup.jpg")
48
49
50def plot_current_vs_base(argv):
51    current_data = argv[1]
52    if len(argv) <= 2:
53        logging.warning('no base data')
54        return
55    else:
56        base_data = argv[2]
57
58    fig = plt.figure()
59
60    base = pandas.read_csv(base_data, delim_whitespace=True)
61    base_min_duration = get_speedup_1_duration(base)
62
63    plt.plot(base['duration'], base['speedup'], color='b',
64             marker='s', linestyle='-.', label=''.join(['base speedup=1@duration=',  str(base_min_duration)]))
65
66    current = pandas.read_csv(current_data, delim_whitespace=True)
67    current_min_duration = get_speedup_1_duration(current)
68
69    plt.plot(current['duration'], current['speedup'],
70             color='r', marker='o', linestyle='-', label=''.join(['curren speedup=1@duration=',  str(current_min_duration)]))
71
72    plt.legend(loc='best')
73    plt.xlabel('task_duration(us)')
74    plt.ylabel('speedup')
75    plt.title('ffrt speedup test', fontsize=20)
76    plt.savefig("speedup_vs_base.jpg")
77
78
79if __name__ == '__main__':
80    plot_current_vs_base(sys.argv)
81    plot_current_only(sys.argv)
82