-
Notifications
You must be signed in to change notification settings - Fork 2
/
statistics.go
64 lines (56 loc) · 1.33 KB
/
statistics.go
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
package loadTest
import (
"encoding/json"
"log"
"os"
"sync"
"time"
)
type EndpointStatistics struct {
sync.RWMutex
StatusCodes map[int]int
Times []time.Duration
}
func newEndpointStatistics() *EndpointStatistics {
return &EndpointStatistics{
StatusCodes: make(map[int]int),
}
}
func (s *EndpointStatistics) addDataPoint(status int, duration *time.Duration) {
s.Lock()
if duration != nil {
s.Times = append(s.Times, *duration / time.Millisecond)
}
s.StatusCodes[status]++
s.Unlock()
}
type Statistics struct {
CreditNote *EndpointStatistics
UblInvoice *EndpointStatistics
D16bInvoice *EndpointStatistics
GetInvoices *EndpointStatistics
UblRulesViolation *EndpointStatistics
UblXsdViolation *EndpointStatistics
UblLarge *EndpointStatistics
}
func NewStatistics() Statistics {
return Statistics{
newEndpointStatistics(),
newEndpointStatistics(),
newEndpointStatistics(),
newEndpointStatistics(),
newEndpointStatistics(),
newEndpointStatistics(),
newEndpointStatistics(),
}
}
func (s *Statistics) Print(file string) {
serializedResult, err := json.MarshalIndent(s, "", " ")
if err != nil {
log.Println("result.marshal.failed", s)
}
err = os.WriteFile(file, serializedResult, 0644)
if err != nil {
log.Println("result.writeFile.failed", serializedResult)
}
}