-
Notifications
You must be signed in to change notification settings - Fork 0
/
struct.go
146 lines (127 loc) · 3.73 KB
/
struct.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
package main
// A Data represents the timing information parsed from LS-DYNA message file.
type Data struct {
Name string
CpuSec, CpuPercent, ClockSec, ClockPercent float64
}
// GetValue returns value used for aggregation.
func (data *Data) GetValue(dataType string) float64 {
switch dataType {
case CpuSec:
return data.CpuSec
case CpuPercent:
return data.CpuPercent
case ClockSec:
return data.ClockSec
case ClockPercent:
return data.ClockPercent
}
return 0.0
}
// A Child represents the child information (e.g. Solids, Shells).
type Child struct {
Data
}
// Parent represents the parent information (e.g. Keyword Processing).
type Parent struct {
Data
Children []*Child
}
// AddChild adds child data to parent's children.
func (parent *Parent) AddChild(name string, cpuSec, cpuPercent, clockSec, clockPercent float64) *Child {
child := Child{}
child.Name = name
child.CpuSec = cpuSec
child.CpuPercent = cpuPercent
child.ClockSec = clockSec
child.ClockPercent = clockPercent
parent.Children = append(parent.Children, &child)
return &child
}
// GetNumChildren returns the number of Children in this parent data.
func (parent *Parent) GetNumChildren() int {
return len(parent.Children)
}
// ForEachChildren returns the number of Children in this parent data.
func (parent *Parent) ForEachChildren(cb func(*Child, int)) {
for i, child := range parent.Children {
cb(child, i)
}
}
// Record represents the data set parsed from a LS-DYNA message file.
type Record struct {
File string
Version string
Revision int64
Date, Time string
LicensedTo, IssuedBy string
Platform, Os, Compiler, Hostname, Precision string
SvnVersion int64
InputFile string
NumCpus int64
NormalTermination bool
ElapsedTime float64
Parents []*Parent
}
// GetNumParents returns the number of parents in this record.
func (record *Record) GetNumParents() int {
return len(record.Parents)
}
// GetNumChildren returns the number of Children in this record.
func (record *Record) GetNumChildren() int {
numChildren := 0
record.ForEachParent(func(parent *Parent, i int) {
numChildren += parent.GetNumChildren()
})
return numChildren
}
// GetNumData returns the number of data (num parents + num Children) in this record.
func (record *Record) GetNumData() int {
numData := 0
record.ForEachParent(func(parent *Parent, i int) {
numData++
numData += parent.GetNumChildren()
})
return numData
}
// ForEachParent executes callback function for each parent.
func (record *Record) ForEachParent(cb func(*Parent, int)) {
for i, parent := range record.Parents {
cb(parent, i)
}
}
// ForEachData executes callback function for each data.
func (record *Record) ForEachData(cb func(interface{}, int)) {
count := 0
record.ForEachParent(func(parent *Parent, _ int) {
cb(parent, count)
count++
parent.ForEachChildren(func(child *Child, _ int) {
cb(child, count)
count++
})
})
}
// ForEachChild executes callback function for each child.
func (record *Record) ForEachChild(cb func(interface{}, int)) {
count := 0
record.ForEachParent(func(parent *Parent, _ int) {
cb(parent, count)
count++
parent.ForEachChildren(func(child *Child, _ int) {
cb(child, count)
count++
})
})
}
// AddParent adds parent data to record.
func (record *Record) AddParent(name string, cpuSec, cpuPercent, clockSec, clockPercent float64) *Parent {
parent := Parent{}
parent.Name = name
parent.CpuSec = cpuSec
parent.CpuPercent = cpuPercent
parent.ClockSec = clockSec
parent.ClockPercent = clockPercent
record.Parents = append(record.Parents, &parent)
return &parent
}