File: performance_graph.py

package info (click to toggle)
freespace2 24.0.2%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: trixie
  • size: 43,188 kB
  • sloc: cpp: 583,107; ansic: 21,729; python: 1,174; sh: 464; makefile: 248; xml: 181
file content (87 lines) | stat: -rw-r--r-- 2,173 bytes parent folder | download | duplicates (2)
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
81
82
83
84
85
86
87
#!/usr/bin/env python3

import numpy as np
import pylab as plot
import sys
import argparse

parser = argparse.ArgumentParser(description="Generate a performance graph")
parser.add_argument("--base_data", required=True,
                    help="The path to the base data")
parser.add_argument("--base_title", required=True,
                    help="The title of the base data plot")

parser.add_argument("--changed_data", required=True,
                    help="The path to the changed data")
parser.add_argument("--changed_title", required=True,
                    help="The title of the changed data plot")

parser.add_argument("--fps", action="store_true",
                    help="Draw plot as FPS, default is frametime")
parser.add_argument("--save_img", help="Saves the generated graph to the specified file path.")
args = parser.parse_args()

averageTime = 0.3

NANOSECONDS_PER_SECOND = 1000000000.


def average(time, frametime):
    startIndex = 0
    currentTime = time[startIndex]

    outTime = []
    outFPS = []

    for i in range(startIndex + 1, len(time)):
        if time[i] - currentTime >= averageTime:
            val = np.mean(frametime[startIndex:i])

            outTime.append(time[startIndex])
            outFPS.append(val)

            startIndex = i
            currentTime = time[i]

    return outTime, outFPS


def adjustData(data):
    times = data[2:, 0] / NANOSECONDS_PER_SECOND
    frametimes = data[2:, 1] / NANOSECONDS_PER_SECOND

    times = times - times[0]

    if args.fps:
        frametimes = 1 / frametimes

    return average(times, frametimes)


normalData = np.genfromtxt(args.base_data, delimiter=';')
changedData = np.genfromtxt(args.changed_data, delimiter=';')

nT, nF = adjustData(normalData)
cT, cF = adjustData(changedData)

avgNormalData = np.mean(nF)
avgChangedData = np.mean(cF)

ratio = avgNormalData / avgChangedData
print(ratio)

plot.plot(nT, nF, label=args.base_title)
plot.plot(cT, cF, label=args.changed_title)

plot.xlabel("Mission time")
if args.fps:
    plot.ylabel("FPS")
else:
    plot.ylabel("Frametime")

plot.legend(loc=1)

if args.save_img:
    plot.savefig(args.save_img)
else:
    plot.show()