File: duration_perf_analyse.py

package info (click to toggle)
gnocchi 4.7.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,384 kB
  • sloc: python: 21,820; sh: 366; makefile: 54
file content (80 lines) | stat: -rw-r--r-- 2,586 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python
#
# Copyright (c) 2014 eNovance
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#
# Tools to analyse the result of multiple call of duration_perf_test.py:
#
#   $ clients=10
#   $ parallel --progress -j $clients python duration_perf_test.py \
#       --result myresults/client{} ::: $(seq 0 $clients)
#   $ python duration_perf_analyse.py myresults
#    * get_measures:
#                  Time
#    count  1000.000000
#    mean      0.032090
#    std       0.028287
#    ...
#


import argparse
import os

import pandas


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('result',
                        help=('Path of the results of perf_tool.py.'),
                        default='result')

    data = {
        'get_measures': [],
        'write_measures': [],
        'write_metric': [],
    }
    args = parser.parse_args()
    for root, dirs, files in os.walk(args.result):
        for name in files:
            for method in data:
                if name.endswith('_%s.csv' % method):
                    datum = data[method]
                    filepath = os.path.join(root, name)
                    datum.append(pandas.read_csv(filepath))
                    cname = name.replace('_%s.csv' % method, '')
                    datum[-1].rename(columns={'Duration': cname}, inplace=True)

    for method in data:
        merged = pandas.DataFrame(columns=['Index', 'Duration'])
        append = pandas.DataFrame(columns=['Duration'])
        for datum in data[method]:
            datum.dropna(axis=1, inplace=True)
            datum.drop('Count', axis=1, inplace=True)
            merged = merged.merge(datum, on='Index')
            cname = datum.columns.values[1]
            datum.rename(columns={cname: 'Duration'}, inplace=True)
            append = append.append(datum.drop('Index', axis=1))
        merged.to_csv(os.path.join(args.result, '%s_merged.csv' % method),
                      index=False)
        print("* %s:" % method)
        print(append.describe())
        print("")


if __name__ == '__main__':
    main()