-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.py
120 lines (102 loc) · 4.01 KB
/
stats.py
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/python
# -*- coding: utf-8 -*-# ***************************************************************************
# * Copyright (c) 2015-2024 by Pierre-Henri WUILLEMIN *
# * {prenom.nom}_at_lip6.fr *
# * *
# * "act" is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU General Public License as published by *
# * the Free Software Foundation; either version 2 of the License, or *
# * (at your option) any later version. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU General Public License for more details. *
# * *
# * You should have received a copy of the GNU General Public License *
# * along with this program; if not, write to the *
# * Free Software Foundation, Inc., *
# * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
# **************************************************************************
import sys
from math import sqrt
from subprocess import PIPE, Popen, STDOUT
from time import localtime
from typing import Any
from .builder import getCmake, getMake, getPost
from .configuration import cfg
from .utils import notif, safe_cd
def simple_stats(n, s, s2) -> tuple[float, float, float]:
v = (s2 / n - pow(s / n, 2))
if n == 1:
sig = sqrt(v)
halfA = 0
else:
sig = sqrt(v / (n - 1))
halfA = 1.96 * sig
return (s / n), sig, halfA
def profileAgrum(current: dict[str, Any]):
dic = {k: current[k] for k in current.keys()}
dic['stats'] = False
dic['fixed_seed'] = True
dic['no-fun'] = True
target = "+".join(current['targets'])
safe_cd(current, "build")
safe_cd(current, "agrum")
safe_cd(current, current["mode"])
notif("[cmake]")
cm = getCmake(dic, target)
proc = Popen(cm, shell=True, stdout=PIPE, stderr=STDOUT)
out = proc.stdout.readlines()
if current['verbose']:
for line in out:
print(line, end="")
notif("[make]")
ma = getMake(dic, target)
proc = Popen(ma, shell=True, stdout=PIPE, stderr=STDOUT)
out = proc.stdout.readlines()
if current['verbose']:
for line in out:
print(line, end="")
po, _ = getPost(dic, target)
notif(f"[{cfg.nbr_tests_for_stats} runs] (please be patient) ...")
sdt = 0
sdt2 = 0
dmin = float('inf')
dmax = float('-inf')
mean = halfA = 0
notif("")
barre = "-------------|------------------|-------------------|"
notif(barre)
notif(" time #it | XP (stdev) | confid. interval |")
notif(barre)
for i in range(cfg.nbr_tests_for_stats):
dt = 0
while dt == 0:
proc = Popen(po, shell=True, stdout=PIPE, stderr=STDOUT)
out = proc.stdout.readlines()
for line in out:
if b"Profiling" in line:
t = line.split(b" ")
v = t[4] if len(t[3]) == 0 else t[3]
dt = float(v) / 1000.0
if dt == 0:
notif("[error : duration=0]")
if dt > dmax:
dmax = dt
if dt < dmin:
dmin = dt
sdt += dt
sdt2 += dt * dt
mean, stdev, halfA = simple_stats(i + 1, sdt, sdt2)
t = localtime()
notif(
f"{t.tm_hour:02d}:{t.tm_min:02d}:{t.tm_sec:02d} #[{i + 1:02d}] | {dt:7.3f}s ({stdev:3.3f}) | [{mean:8.3f} ± {halfA:3.3f}]s |")
notif(barre)
notif(" time #it | XP (stdev) | confid. interval |")
notif(barre)
notif(
f"=> Conclusion on {cfg.nbr_tests_for_stats} iteration(s) : {dmin:8.3f} <-- [{mean:8.3f} ± {halfA:3.3f}] --> {dmax:8.3f}")
safe_cd(current, "..")
safe_cd(current, "..")
sys.exit(0)