1ed17e94b
김태훈
전주기 시연용 응용 프로그램 추가
|
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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
|
}
var reTimestamp = regexp.MustCompile(`^\[[[:blank:]]*[[:digit:]]+\.[[:digit:]]+[[:blank:]]*\]`)
var reAddress = regexp.MustCompile(`0x[[:xdigit:]]+`)
func parseMemory(lines chan string, chanOutput chan jsonObject) {
m := make(jsonObject)
m["type"] = "memory"
rLine := regexp.MustCompile("Memory: [[:ascii:]]+ available")
rBytes := regexp.MustCompile("[[:digit:]]+[Kk]")
for line := range lines {
if found := rLine.FindString(line); found != "" {
r := rBytes.FindAllString(line, 2)
m["available"] = r[0]
m["total"] = r[1]
chanOutput <- m
return
}
}
m["available"] = ""
m["total"] = ""
chanOutput <- m
}
func parseMemoryLayout(lines chan string, chanOutput chan jsonObject) {
rHeaderArm := regexp.MustCompile("Virtual kernel memory layout:")
rHeaderX86 := regexp.MustCompile("Zone ranges:")
for line := range lines {
if rHeaderArm.MatchString(line) {
parseMemoryLayoutArm(lines, chanOutput)
return
}
if rHeaderX86.MatchString(line) {
parseMemoryLayoutX86(lines, chanOutput)
return
}
}
m := make(jsonObject)
m["type"] = "memory_layout"
m["layout"] = make([]jsonObject, 0)
chanOutput <- m
}
func parseMemoryLayoutArm(lines chan string, chanOutput chan jsonObject) {
m := make(jsonObject)
m["type"] = "memory_layout"
m["layout"] = make([]jsonObject, 0)
rLine := regexp.MustCompile(`[[:print:]]+:[[:blank:]]*0x[[:xdigit:]]+[[:blank:]]*-[[:blank:]]*0x[[:xdigit:]]+`)
rLabel := regexp.MustCompile(`[[:graph:]]+`)
for line := range lines {
line = removeTimestamp(line)
if rLine.MatchString(line) {
item := make(jsonObject)
item["label"] = rLabel.FindString(line)
r := reAddress.FindAllString(line, 2)
item["from"] = r[0]
item["to"] = r[1]
m["layout"] = append(m["layout"].([]jsonObject), item)
} else {
break
}
}
chanOutput <- m
}
func parseMemoryLayoutX86(lines chan string, chanOutput chan jsonObject) {
m := make(jsonObject)
m["type"] = "memory_layout"
m["layout"] = make([]jsonObject, 0)
rLine := regexp.MustCompile(`[[:print:]]+\[mem[[:blank:]]+0x[[:xdigit:]]+-0x[[:xdigit:]]+\]`)
rLabel := regexp.MustCompile(`[[:graph:]]+`)
for line := range lines {
line = removeTimestamp(line)
if rLine.MatchString(line) {
item := make(jsonObject)
item["label"] = rLabel.FindString(line)
r := reAddress.FindAllString(line, 2)
item["from"] = r[0]
item["to"] = r[1]
m["layout"] = append(m["layout"].([]jsonObject), item)
} else {
break
}
}
chanOutput <- m
}
func parseTimestamps(lines chan string, chanOutput chan jsonObject) {
rVal := regexp.MustCompile(`[[:digit:]]+\.[[:digit:]]+`)
list := make(jsonArray, 0)
for line := range lines {
if reTimestamp.MatchString(line) {
t := reTimestamp.FindString(line)
v := rVal.FindString(t)
f, _ := strconv.ParseFloat(v, 64)
list = append(list, f)
}
}
m := make(jsonObject)
m["type"] = "timestamps"
m["timestamps"] = list
chanOutput <- m
}
func parseStatus(lines chan string, chanOutput chan jsonObject) {
rLine := regexp.MustCompile(`^\[[[:blank:]]*(OK|FAIL)[[:blank:]]*\][[:blank:]]+`)
rOk := regexp.MustCompile(`^\[[[:blank:]]*OK[[:blank:]]*\]`)
list := make([]jsonObject, 0)
for line := range lines {
if rLine.MatchString(line) {
item := make(jsonObject)
if rOk.MatchString(line) {
item["status"] = "ok"
} else {
item["status"] = "fail"
}
prefix := rLine.FindString(line)
label := strings.TrimPrefix(line, prefix)
item["label"] = label
list = append(list, item)
}
}
m := make(jsonObject)
m["type"] = "status"
m["list"] = list
chanOutput <- m
}
func parseHashTables(lines chan string, chanOutput chan jsonObject) {
rLine := regexp.MustCompile(`[[:graph:]]+ hash table entries:`)
list := make([]jsonObject, 0)
for line := range lines {
if rLine.MatchString(line) {
line = removeTimestamp(line)
item := make(jsonObject)
label := regexp.MustCompile(`[[:print:]]+ hash table entries:`).FindString(line)
item["label"] = strings.TrimSuffix(label, " hash table entries:")
entries := regexp.MustCompile(`hash table entries: [[:digit:]]+`).FindString(line)
entries = strings.TrimPrefix(entries, "hash table entries: ")
item["entries"], _ = strconv.ParseInt(entries, 10, 64)
order := regexp.MustCompile(`order:? [[:digit:]-]+`).FindString(line)
orderPrefix := regexp.MustCompile(`order:? `).FindString(order)
order = strings.TrimPrefix(order, orderPrefix)
item["order"], _ = strconv.ParseInt(order, 10, 64)
size := regexp.MustCompile(`[[:digit:]]+ bytes`).FindString(line)
size = strings.TrimSuffix(size, " bytes")
item["size"], _ = strconv.ParseInt(size, 10, 64)
list = append(list, item)
}
}
m := make(jsonObject)
m["type"] = "hash_tables"
m["list"] = list
chanOutput <- m
}
func parseLinux(lines chan string, chanOutput chan jsonObject) {
m := make(jsonObject)
m["type"] = "linux"
m["version"] = ""
m["builder"] = ""
m["toolchain"] = ""
m["label"] = ""
rLine := regexp.MustCompile(`Linux version[[:blank:]]+[[:graph:]]+[[:blank:]]+([[:print:]]+)[[:blank:]]+([[:print:]]+)[[:blank:]]+#[[:print:]]+`)
for line := range lines {
if rLine.MatchString(line) {
line = rLine.FindString(line)
line = strings.TrimPrefix(line, "Linux version ")
m["version"] = regexp.MustCompile(`[[:graph:]]+`).FindString(line)
m["os"] = "linux"
bracketed := regexp.MustCompile(`\([[:print:]]+?\)`).FindAllString(line, 2)
for i, s := range bracketed {
switch i {
case 0:
m["builder"] = removeBrackets(s)
case 1:
m["toolchain"] = removeBrackets(s)
}
}
m["label"] = regexp.MustCompile(`#[[:print:]]+`).FindString(line)
break
}
}
chanOutput <- m
}
func parseCpu(lines chan string, chanOutput chan jsonObject) {
m := make(jsonObject)
m["type"] = "cpu"
m["name"] = ""
m["id"] = ""
m["revision"] = ""
m["arch"] = ""
m["cr"] = ""
m["data_cache"] = ""
m["instruction_cache"] = ""
rLine1 := regexp.MustCompile(`CPU:[[:blank:]]+[[:print:]]+[[:blank:]]+\[[[:xdigit:]]+\][[:blank:]]+revision[[:blank:]]+[[:digit:]][[:blank:]]+\([[:print:]]+\), cr=[[:xdigit:]]+`)
rLine2 := regexp.MustCompile(`CPU:[[:blank:]]+[[:print:]]+[[:blank:]]+data cache,[[:blank:]]+[[:print:]]+[[:blank:]]+instruction cache`)
for line := range lines {
if rLine1.MatchString(line) {
line = rLine1.FindString(line)
line = strings.TrimPrefix(line, "CPU: ")
name := regexp.MustCompile(`[[:print:]]+\[`).FindString(line)
name = strings.TrimSuffix(name, "[")
name = strings.TrimSpace(name)
m["name"] = name
id := regexp.MustCompile(`\[[[:xdigit:]]+\]`).FindString(line)
id = strings.TrimPrefix(id, "[")
id = strings.TrimSuffix(id, "]")
m["id"] = id
revision := regexp.MustCompile(`revision[[:blank:]]+[[:digit:]]+`).FindString(line)
revision = strings.TrimPrefix(revision, "revision")
revision = strings.TrimSpace(revision)
m["revision"] = revision
arch := regexp.MustCompile(`\([[:print:]]+\)`).FindString(line)
arch = strings.TrimPrefix(arch, "(")
arch = strings.TrimSuffix(arch, ")")
arch = strings.TrimSpace(arch)
m["arch"] = arch
cr := regexp.MustCompile(`cr=[[:xdigit:]]+`).FindString(line)
cr = strings.TrimPrefix(cr, "cr=")
m["cr"] = cr
} else if rLine2.MatchString(line) {
line = rLine2.FindString(line)
line = strings.TrimPrefix(line, `CPU: `)
dataCache := regexp.MustCompile(`[[:print:]]+data cache`).FindString(line)
dataCache = strings.TrimSuffix(dataCache, "data cache")
dataCache = strings.TrimSpace(dataCache)
m["data_cache"] = dataCache
instructionCache := regexp.MustCompile(`,[[:print:]]+instruction cache`).FindString(line)
instructionCache = strings.TrimPrefix(instructionCache, ",")
instructionCache = strings.TrimSuffix(instructionCache, "instruction cache")
instructionCache = strings.TrimSpace(instructionCache)
m["instruction_cache"] = instructionCache
}
}
chanOutput <- m
}
func parseModel(lines chan string, chanOutput chan jsonObject) {
m := make(jsonObject)
m["type"] = "model"
m["model"] = ""
rLine := regexp.MustCompile(`(Machine model: [[:print:]]+)|(Machine: [[:print:]]+)`)
rLineEdison := regexp.MustCompile(`Linux version[[:print:]]+edison`)
rLineARTIK := regexp.MustCompile(`CPU EXYNOS3250`)
for line := range lines {
if rLine.MatchString(line) {
line = rLine.FindString(line)
line = strings.TrimPrefix(line, "Machine model: ")
line = strings.TrimPrefix(line, "Machine: ")
m["model"] = strings.TrimSpace(line)
break
} else if rLineEdison.MatchString(line) {
m["model"] = "Intel Edison"
break
} else if rLineARTIK.MatchString(line) {
m["model"] = "SAMSUNG ARTIK5"
break
}
}
chanOutput <- m
}
func parseDeviceFound(lines chan string, chanOutput chan jsonObject) {
list := make([]string, 0)
for line := range lines {
for _, e := range deviceTable {
if e.re.MatchString(line) {
list = append(list, e.name)
}
}
}
m := make(jsonObject)
m["type"] = "device_found"
m["list"] = list
chanOutput <- m
}
func parseKernelCommandLine(lines chan string, chanOutput chan jsonObject) {
m := make(jsonObject)
m["type"] = "kernel_command_line"
m["kernel_command_line"] = ""
rLine := regexp.MustCompile("Kernel command line: [[:print:]]+")
for line := range lines {
if rLine.MatchString(line) {
line = rLine.FindString(line)
cmdline := strings.TrimPrefix(line, "Kernel command line: ")
cmdline = strings.TrimSpace(cmdline)
if strings.HasPrefix(cmdline, `"`) && strings.HasSuffix(cmdline, `"`) {
cmdline = strings.TrimPrefix(cmdline, `"`)
cmdline = strings.TrimSuffix(cmdline, `"`)
}
m["kernel_command_line"] = cmdline
break
}
}
chanOutput <- m
}
func parseCma(lines chan string, chanOutput chan jsonObject) {
m := make(jsonObject)
m["type"] = "cma"
m["size"] = ""
m["address"] = ""
rLine := regexp.MustCompile("cma: Reserved [[:print:]]+ at [[:print:]]+")
for line := range lines {
if rLine.MatchString(line) {
line = rLine.FindString(line)
line = strings.TrimPrefix(line, "cma: Reserved ")
size := regexp.MustCompile(`[[:print:]]+ at`).FindString(line)
size = strings.TrimSuffix(size, "at")
size = strings.TrimSpace(size)
m["size"] = size
address := regexp.MustCompile(`at [[:print:]]+`).FindString(line)
address = strings.TrimPrefix(address, "at")
address = strings.TrimSpace(address)
m["address"] = address
break
}
}
chanOutput <- m
}
func parseSlub(lines chan string, chanOutput chan jsonObject) {
m := make(jsonObject)
m["type"] = "slub"
m["hw_align"] = ""
m["order"] = ""
m["min_objects"] = ""
m["cpus"] = ""
m["nodes"] = ""
rLine := regexp.MustCompile("SLUB: HWalign=[[:digit:]]+, Order=[[:digit:]]+-[[:digit:]]+, MinObjects=[[:digit:]]+, CPUs=[[:digit:]]+, Nodes=[[:digit:]]+")
for line := range lines {
if rLine.MatchString(line) {
line = rLine.FindString(line)
hwAlign := regexp.MustCompile(`HWalign=[[:digit:]]+`).FindString(line)
hwAlign = strings.TrimPrefix(hwAlign, `HWalign=`)
m["hw_align"] = hwAlign
order := regexp.MustCompile(`Order=[[:digit:]]+-[[:digit:]]+`).FindString(line)
order = strings.TrimPrefix(order, `Order=`)
m["order"] = order
minObjects := regexp.MustCompile(`MinObjects=[[:digit:]]+`).FindString(line)
minObjects = strings.TrimPrefix(minObjects, `MinObjects=`)
m["min_objects"] = minObjects
cpus := regexp.MustCompile(`CPUs=[[:digit:]]+`).FindString(line)
cpus = strings.TrimPrefix(cpus, `CPUs=`)
m["cpus"] = cpus
nodes := regexp.MustCompile(`Nodes=[[:digit:]]+`).FindString(line)
nodes = strings.TrimPrefix(nodes, `Nodes=`)
m["nodes"] = nodes
break
}
}
chanOutput <- m
}
func parsePidMax(lines chan string, chanOutput chan jsonObject) {
m := make(jsonObject)
m["type"] = "pid_max"
m["default"] = ""
m["min"] = ""
rLine := regexp.MustCompile("pid_max:[[:blank:]]+default:[[:blank:]]*[[:digit:]]+[[:blank:]]+minimum:[[:blank:]]*[[:digit:]]+")
for line := range lines {
if rLine.MatchString(line) {
line = rLine.FindString(line)
m["default"] = extract(line,
`default:[[:blank:]]*[[:digit:]]+`,
`default:[[:blank:]]*`,
``)
m["min"] = extract(line,
`minimum:[[:blank:]]*[[:digit:]]+`,
`minimum:[[:blank:]]*`,
``)
break
}
}
chanOutput <- m
}
func parseWorkingset(lines chan string, chanOutput chan jsonObject) {
m := make(jsonObject)
m["type"] = "workingset"
m["timestamp bits"] = ""
m["max_order"] = ""
m["bucket_order"] = ""
rLine := regexp.MustCompile("workingset: timestamp_bits=[[:digit:]]+ max_order=[[:digit:]]+ bucket_order=[[:digit:]]+")
for line := range lines {
if rLine.MatchString(line) {
line = rLine.FindString(line)
m["timestamp_bits"] = extract(line,
`timestamp_bits=[[:digit:]]+`,
`timestamp_bits=`,
``)
m["max_order"] = extract(line,
`max_order=[[:digit:]]+`,
`max_order=`,
``)
m["bucket_order"] = extract(line,
`bucket_order=[[:digit:]]+`,
`bucket_order=`,
``)
break
}
}
chanOutput <- m
}
|
2b591388f
김태훈
라즈베리 파이 3 부트로더 정보 추가
|
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
|
func parseBootloaderBootcode(lines chan string, chanOutput chan jsonObject) {
m := make(jsonObject)
m["type"] = "bootloader_bootcode"
m["value"] = ""
rLine := regexp.MustCompile(`^Raspberry Pi Bootcode`)
for line := range lines {
if rLine.MatchString(line) {
m["value"] = line
break
}
}
chanOutput <- m
}
func parseBootloaderRead(lines chan string, chanOutput chan jsonObject) {
const (
FIND_NAME = iota
FIND_SIZE
)
state := FIND_NAME
elements := make(map[string]string)
name := ""
rLine := regexp.MustCompile(`brfs: File read: ([[:print:]]+)`)
for line := range lines {
if rLine.MatchString(line) {
if sub := rLine.FindStringSubmatch(line); len(sub) > 1 {
switch state {
case FIND_NAME:
name = sub[1]
state = FIND_SIZE
case FIND_SIZE:
elements[name] = sub[1]
state = FIND_NAME
}
}
}
}
list := make([]jsonObject, 0)
for name, size := range elements {
list = append(list, jsonObject{"name": name, "size": size})
}
m := make(jsonObject)
m["type"] = "bootloader_read"
m["list"] = list
chanOutput <- m
}
func parseBootloaderCommandLine(lines chan string, chanOutput chan jsonObject) {
m := make(jsonObject)
m["type"] = "bootloader_command_line"
m["value"] = ""
const (
FIND_HEADER = iota
FIND_LINE
DONE
)
state := FIND_HEADER
rLine := regexp.MustCompile(`Read command line from file`)
rValue := regexp.MustCompile(`[[:graph:]]+ ([[:print:]]+)`)
for line := range lines {
switch state {
case FIND_HEADER:
if rLine.MatchString(line) {
state = FIND_LINE
}
case FIND_LINE:
if sub := rValue.FindStringSubmatch(line); len(sub) > 1 {
m["value"] = sub[1]
state = DONE
}
}
if state == DONE {
break
}
}
chanOutput <- m
}
func parseBootloaderLoad(lines chan string, chanOutput chan jsonObject) {
list := make([]jsonObject, 0)
rLine := regexp.MustCompile(`Loading '([[:print:]]+)' to (0x[[:xdigit:]]+) size (0x[[:xdigit:]]+)`)
for line := range lines {
if rLine.MatchString(line) {
if sub := rLine.FindStringSubmatch(line); len(sub) > 3 {
list = append(list, jsonObject{"name": sub[1], "address": sub[2], "size": sub[3]})
}
}
}
m := make(jsonObject)
m["type"] = "bootloader_load"
m["list"] = list
chanOutput <- m
}
|
1ed17e94b
김태훈
전주기 시연용 응용 프로그램 추가
|
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
|
func removeBrackets(s string) string {
for strings.HasPrefix(s, "(") && strings.HasSuffix(s, ")") {
openCount := strings.Count(s, "(")
closeCount := strings.Count(s, ")")
if openCount > closeCount {
s = strings.TrimPrefix(s, "(")
} else if openCount < closeCount {
s = strings.TrimSuffix(s, ")")
} else {
s = strings.TrimPrefix(s, "(")
s = strings.TrimSuffix(s, ")")
}
}
return s
}
func removeTimestamp(s string) string {
if reTimestamp.MatchString(s) {
t := reTimestamp.FindString(s)
s = strings.TrimPrefix(s, t)
}
return strings.TrimSpace(s)
}
func extract(from string, chunk, prefix, suffix string) string {
reChunk, err := regexp.Compile(chunk)
if err != nil {
return ""
}
rePrefix, err := regexp.Compile(prefix)
if err != nil {
return ""
}
reSuffix, err := regexp.Compile(suffix)
if err != nil {
return ""
}
b := reChunk.FindString(from)
p := rePrefix.FindString(b)
b = strings.TrimPrefix(b, p)
s := reSuffix.FindString(b)
b = strings.TrimSuffix(b, s)
return b
}
|