/
main.go
166 lines (130 loc) · 4.37 KB
/
main.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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package main
import (
"log"
"time"
"runtime"
"flag"
"github.com/dumacp/opencivica/openlog"
"github.com/dumacp/utils"
"github.com/yanatan16/itertools"
"os"
"runtime/pprof"
)
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
var memprofile = flag.String("memprofile", "", "write memory profile to `file`")
func main() {
//log.Printf("versions: %q\n", openlog.AppVersions(0))
flag.Parse()
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
for {
/**/
log.Printf("goroutines start: %d\n", runtime.NumGoroutine())
quit1 := make(chan int)
itLogs1 := openlog.ReadAppLogs(0, quit1)
//iterLogs := itertools.Tee(itLogs, 2)
log.Printf("goroutines step1: %d\n", runtime.NumGoroutine())
iterLibs1 := openlog.ParseAppLog(openlog.FuncAppVersionLog, itLogs1)
log.Printf("goroutines step2: %d\n", runtime.NumGoroutine())
log.Printf("App version: %q\n", (<-iterLibs1).(openlog.AppLogData).Data)
quit1 <- 11
//close(iterLibs1)
log.Printf("goroutines step3: %d\n", runtime.NumGoroutine())
/**/
log.Printf("goroutines start: %d\n", runtime.NumGoroutine())
quit2 := make(chan int)
itLogs2 := openlog.ReadAppLogs(0, quit2)
//iterLogs := itertools.Tee(itLogs, 2)
log.Printf("goroutines step1: %d\n", runtime.NumGoroutine())
iterLibs2 := openlog.ParseAppLog(openlog.FuncSubrutaLog, itLogs2)
log.Printf("goroutines step2: %d\n", runtime.NumGoroutine())
log.Printf("App version: %q\n", (<-iterLibs2).(openlog.AppLogData).Data)
quit2 <- 11
//close(iterLibs1)
log.Printf("goroutines step3: %d\n", runtime.NumGoroutine())
/**
quit2 := make(chan int)
itLogs2 := openlog.ReadAppLogs(0, quit2)
iterLibs2 := openlog.ParseAppLog(openlog.FuncTabVersionLog, itLogs2)
log.Printf("goroutines step4: %d\n", runtime.NumGoroutine())
mapVers := make(map[string]string)
for v:= range iterLibs2 {
libv := v.(openlog.AppLogData).Data.(map[string]string)
for key, value := range libv {
if _, ok := mapVers[key]; !ok {
mapVers[key] = value
}
}
}
utils.CloseChannel(quit2, 12)
log.Printf("Lib versions: %q\n", mapVers)
/**/
/**
quit3 := make(chan int)
it := openlog.ReadAppLogs(0, quit3)
//tee1 := itertools.Tee(it, 2)
//libVersions := openlog.TabVersions(it)
appVersions := openlog.AppVersions(it)
//log.Printf("Lib versions: %q\n", libVersions)
log.Printf("app versions: %q\n", appVersions)
utils.CloseChannel(quit3, 13)
utils.FinishChannel(it)
//utils.FinishChannel(tee1[1])
/**/
quit4 := make(chan int)
iterTranss := openlog.ReadTransactions(0,quit4)
iterUsosLog := openlog.ParseUsosLog(iterTranss)
//log.Printf("error count: %v\n", openlog.CountUsosAfter(iterUsosLog,0))
fFilter0 := func(i interface{}) bool {
return i.(openlog.UsoTransporte).UsoId > 1530625744149
//return i.(openlog.UsoTransporte).UsoId > 1523989505114
//return i.(openlog.UsoTransporte).UsoId > 0
}
itLast := itertools.TakeWhile(fFilter0, iterUsosLog)
it := itertools.Tee(itLast, 2)
fFilter1 := func(i interface{}) bool {
switch v := i.(type) {
case openlog.UsoTransporte:
return v.Exitoso
}
return false
}
fFilter2 := func(i interface{}) bool {
return !i.(openlog.UsoTransporte).Exitoso
}
itUsos := itertools.Filter(fFilter1, it[0])
itErrors := itertools.Filter(fFilter2, it[1])
fReducer := func(memo interface{}, element interface{}) interface{} {
return memo.(int) + 1
}
countUsos := itertools.Reduce(itUsos, fReducer, 0)
countErrors := itertools.Reduce(itErrors, fReducer, 0)
log.Printf("error count: %v\n", countErrors)
log.Printf("usos count: %v\n", countUsos)
utils.CloseChannel(14, quit4)
utils.FinishChannel(itErrors, itUsos, it[0], it[1], itLast, iterUsosLog, iterTranss)
time.Sleep(time.Second * 6)
num := runtime.NumGoroutine()
log.Printf("\n\n############# goroutines end: %d\n\n", num)
if num > 1 {
break
}
}
if *memprofile != "" {
f, err := os.Create(*memprofile)
if err != nil {
log.Fatal("could not create memory profile: ", err)
}
runtime.GC() // get up-to-date statistics
if err := pprof.WriteHeapProfile(f); err != nil {
log.Fatal("could not write memory profile: ", err)
}
f.Close()
}
}