-
Notifications
You must be signed in to change notification settings - Fork 0
/
gos.gxml
executable file
·401 lines (338 loc) · 9.55 KB
/
gos.gxml
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
<?xml version="1.0" encoding="UTF-8"?>
<gos>
<!-- xml docs : http://golangserver.com/docs/markup.html
<func name="" var="" return="string">
</func> -->
<deploy>webapp</deploy>
<port>9000</port>
<package>if-package-is-library</package>
<not_found>/your-404-page</not_found>
<error>/your-500-page</error>
<import src="github.com/cheikhshift/momentum/gos.gxml"/>
<import src="os"/>
<import src="strings"/>
<import src="runtime"/>
<import src="github.com/cheikhshift/gos/core"/>
<import src="path/filepath"/>
<import src="strconv"/>
<output>application.go</output>
<domain></domain><!-- Cookie domain -->
<var type="*CleoSet">Mset</var>
<main>
//psss go code here : func main()
Windows := strings.Contains(runtime.GOOS, "windows")
if Windows {
os.Chdir( os.ExpandEnv("$USERPROFILE") )
} else {
os.Chdir( os.ExpandEnv("$HOME") )
}
if _, err := os.Stat(cleoWorkspace); os.IsNotExist(err) {
err = os.MkdirAll(cleoWorkspace, 0700)
if err != nil {
panic(err)
}
Mset = &CleoSet{}
SaveConfig()
} else {
err = Load( Path("configs", "default", "000") , &Mset)
if err != nil {
panic(err)
}
}
//TestFrame(Mset.Tests[0])
if Prod {
if !Windows {
if isMac := strings.Contains(runtime.GOOS, "arwin"); isMac {
core.RunCmd("open http://localhost:9000/index")
} else {
core.RunCmd("xdg-open http://localhost:9000/index")
}
} else {
core.RunCmd("cmd /C start http://localhost:9000/index")
}
}
</main>
<key>a very very very very secret key</key>
<header>
<struct name="App">
Name,Path,ID string
FetchOntest bool
Envs []EnvVar
</struct>
<struct name="Setting">
SMTPEmail, SMTPHost,SMTPPass,Emails string
EmailOnAlert bool
SMTPPort,Threads,Connections int
</struct>
<struct name="EnvVar">
Key,Value string
</struct>
<struct name="Test">
ID,TargetID string
Name,Data,Path,Method,H,CustomAddress string
NReqs,PortNumber int
Finished,Working,NoBuild,CPU bool
Duration,MaxCPU float64
HeapMinute []HeapFrame
Start,End time.Time
</struct>
<struct name="HeapFrame">
Iu, Rl,Ho int
Time time.Time
</struct>
<struct name="CleoSet">
Apps []App
Settings Setting
Tests []Test
Alerts []Alert
</struct>
<struct name="Alert">
Danger bool
Message string
Time time.Time
</struct>
<struct name="TopDist">
Name string
Percent float64
</struct>
<struct name="CPUFrame">
Time time.Time
CPUUsage int
</struct>
</header>
<methods>
<func name="AddApp" var="app App" return="(done bool)">
app.ID = core.NewLen(10)
Mset.Apps = append(Mset.Apps, app)
SaveConfig()
done = true
return
</func>
<func name="AddTest" var="test Test" return="(done bool)">
test.ID = core.NewLen(10)
Mset.Tests = append(Mset.Tests, test)
SaveConfig()
done = true
return
</func>
<func name="Cleo" var="" return="(cleo *CleoSet)">
cleo = Mset
return
</func>
<func name="DeleteAlerts" var="" return="(done bool)">
Mset.Alerts = []Alert{}
SaveConfig()
return
</func>
<func name="GetList" var="test Test, lookup string" return="(list string)">
if strings.Contains(lookup, "*") {
lookup = EscapeRegexp(lookup)
}
for cnt, _ := range test.HeapMinute {
cmd := fmt.Sprintf("go tool pprof --list=%s %s", lookup, filepath.Join(cleoWorkspace, Path("tests", test.ID, fmt.Sprintf("h%v", cnt ) )) )
logfull,_ := core.RunCmdSmart(cmd )
retset := strings.Split(logfull,"\n")
if len(retset) > 2 {
list = logfull
break
}
}
return
</func>
<func name="GetListCPU" var="test Test, lookup string" return="(list string)">
if strings.Contains(lookup, "*") {
lookup = EscapeRegexp(lookup)
} else if strings.Contains(lookup, "/") {
lookup = fmt.Sprintf("\"%s\"", lookup)
}
for cnt, _ := range test.HeapMinute {
cmd := fmt.Sprintf("go tool pprof --list=%s %s", lookup, filepath.Join(cleoWorkspace, Path("tests", test.ID, fmt.Sprintf("p%v", cnt ) )) )
logfull,_ := core.RunCmdSmart(cmd )
retset := strings.Split(logfull,"\n")
if len(retset) > 2 {
list = logfull
break
}
}
return
</func>
<func name="GetCPUtimes" var="test Test" return="(top []CPUFrame)">
for cnt, frame := range test.HeapMinute {
var timeused int
logfull,_ := core.RunCmdSmart(fmt.Sprintf("go tool pprof -top %s", filepath.Join(cleoWorkspace, Path("tests", test.ID, fmt.Sprintf("p%v", cnt ) )) ) )
retset := strings.Split(logfull,"\n")
totalTime := strings.Split(retset[2], "=")
timeString := "0"
if strings.Contains(totalTime[1],"s") {
timeStringArray := strings.Split(totalTime[1],"s")
timeString = strings.TrimSpace(timeStringArray[0])
}
f, _ := strconv.ParseFloat(timeString, 64)
f *= 1000
timeused = int(f)
cpuSample := CPUFrame{CPUUsage : timeused, Time : frame.Time }
top = append(top,cpuSample)
}
return
</func>
<func name="GetTop" var="test Test" return="(top []TopDist)">
valm := make(map[string]float64)
for cnt, _ := range test.HeapMinute {
logfull,_ := core.RunCmdSmart(fmt.Sprintf("go tool pprof -top %s", filepath.Join(cleoWorkspace, Path("tests", test.ID, fmt.Sprintf("h%v", cnt ) )) ) )
retset := strings.Split(logfull,"\n")
retset = retset[4:]
for _, str := range retset {
strfm := strings.Replace(strings.TrimSpace(str), " "," ",-1 )
strfm = strings.Replace(strfm, " "," ", -1)
subset := strings.Split(strfm," ")
if len(subset) > 5 {
subsettwo := strings.Split(subset[len(subset) - 1], " ")
if strings.Contains(strfm," (inline)") {
subsettwo = append([]string{subset[len(subset) - 3]},subsettwo...)
} else if len(subsettwo) == 1 {
subsettwo = append([]string{subset[len(subset) - 2]},subsettwo...)
}
//fmt.Println(subsettwo)
_,exts := valm[subsettwo[0]]
if !exts {
valm[subsettwo[0]] = 0
}
f, _ := strconv.ParseFloat(strings.Replace( subset[1],"%","", -1), 64)
valm[subsettwo[0]] += f
}
}
}
tperc := 0.0
for key,val := range valm {
perc := ( val/float64(len(test.HeapMinute) ) )
top = append(top, TopDist{Name: key, Percent : perc })
tperc += perc
}
tperc = 100.0 - tperc
top = append(top, TopDist{Name:"Other samples", Percent : tperc})
valm = nil
return
</func>
<func name="GetCPUTop" var="test Test" return="(top []TopDist,total float64)">
valm := make(map[string]float64)
for cnt, _ := range test.HeapMinute {
logfull,_ := core.RunCmdSmart(fmt.Sprintf("go tool pprof -top %s", filepath.Join(cleoWorkspace, Path("tests", test.ID, fmt.Sprintf("p%v", cnt ) )) ) )
retset := strings.Split(logfull,"\n")
if !strings.Contains(logfull, "Dropped") {
retset = retset[5:]
} else {
retset = retset[6:]
}
for _, str := range retset {
strfm := strings.Replace(strings.TrimSpace(str), " "," ",-1 )
strfm = strings.Replace(strfm, " "," ", -1)
var strval string
subset := strings.Split(strfm," ")
for indx,_ := range subset {
if strings.Contains(subset[indx],"ms") {
strval = subset[indx]
}
}
if len(subset) > 5 {
//fmt.Println(subsettwo)
_,exts := valm[subset[len(subset) - 2]]
if !exts {
valm[subset[len(subset) - 2]] = 0
}
f, _ := strconv.ParseFloat(strings.Replace( strval,"ms","", -1), 64)
valm[subset[len(subset) - 2]] += f
total += f
}
}
}
tperc := 0.0
for key,val := range valm {
perc := ( val/total )
top = append(top, TopDist{Name: key, Percent : perc })
tperc += perc
}
tperc = 100.0 - tperc
top = append(top, TopDist{Name:"Other samples", Percent : tperc})
top = top[:CPUTOPSamples]
valm = nil
return
</func>
<func name="GetCard" var="test Test" return="(res string)">
bc, err := ioutil.ReadFile(filepath.Join(cleoWorkspace, fmt.Sprintf("%s.test", test.ID) ) )
if err != nil {
res = err.Error()
return
}
res = string(bc)
return
</func>
<func name="Start" var="test Test" return="(done bool)">
test.Working = true
test.Start = time.Now()
UpdateTest(test)
SaveConfig()
runtime.GOMAXPROCS(runtime.NumCPU() + Mset.Settings.Threads)
go TestFrame(test)
done = true
return
</func>
<func name="Cancel" var="test Test" return="(done bool)">
test.Working = false
test.End = time.Now()
UpdateTest(test)
SaveConfig()
done = true
return
</func>
<func name="Nuke" var="" return="(done bool)">
err := os.RemoveAll(cleoWorkspace)
if err != nil {
panic(err)
}
err = os.MkdirAll(cleoWorkspace, 0700)
if err != nil {
panic(err)
}
done = true
Mset = &CleoSet{}
SaveConfig()
return
</func>
<func name="UpdateApp" var="app App" return="(done bool)">
UpdateEntry(app)
SaveConfig()
done = true
return
</func>
<func name="UpdateTest" var="test Test" return="(done bool)">
UpdateTest(test)
SaveConfig()
done = true
return
</func>
<func name="UpdateSettings" var="settings Setting" return="(done bool)">
Mset.Settings = settings
SaveConfig()
done = true
return
</func>
<func name="DeleteApp" var="app App" return="(done bool)">
newset := RmEntry(app)
Mset.Apps = newset
SaveConfig()
done = true
return
</func>
<func name="DeleteTest" var="test Test" return="(done bool)">
newset := RmTest(test)
Mset.Tests = newset
SaveConfig()
done = true
return
</func>
</methods>
<templates>
</templates>
<endpoints>
</endpoints>
</gos>