-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrace.go
72 lines (59 loc) · 1.81 KB
/
trace.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
package pces
import (
"github.com/iti/evt/vrtime"
"strconv"
"github.com/iti/mrnes"
"gopkg.in/yaml.v3"
)
var trtToStr map[mrnes.TraceRecordType]string = map[mrnes.TraceRecordType]string{mrnes.NetworkType:"network",mrnes.CmpPtnType:"cp"}
var TraceMgr *mrnes.TraceManager
// CPTrace saves information about the visitation of a message to some point in the computation pattern portion of the simulation.
// saved for post-run analysis
type CPTrace struct {
Time float64 // time in float64
Ticks int64 // ticks variable of time
Priority int64 // priority field of time-stamp
ExecID int // integer identifier identifying the chain of traces this is part of
ObjID int // integer id for object being referenced
Op string // "start", "stop", "enter", "exit"
CPM string // serialization of CmpPtnMsg
}
func (cpt *CPTrace) TraceType() mrnes.TraceRecordType {
return mrnes.CmpPtnType
}
func (cpt *CPTrace) Serialize() string {
if !useTrace {
return ""
}
var bytes []byte
var merr error
bytes, merr = yaml.Marshal(*cpt)
if merr != nil {
panic(merr)
}
return string(bytes[:])
}
// AddCPTrace creates a record of the trace using its calling arguments, and stores it
func AddCPTrace(tm *mrnes.TraceManager, flag bool, vrt vrtime.Time, execID int, objID int, op string, cpm *CmpPtnMsg) {
if !flag || !useTrace {
return
}
cpt := new(CPTrace)
cpt.Time = vrt.Seconds()
cpt.Ticks = vrt.Ticks()
cpt.Priority = vrt.Pri()
if cpm != nil {
cpt.ExecID = cpm.ExecID
} else {
cpt.ExecID = 0
}
cpt.ObjID = objID
cpt.Op = op
if cpm != nil {
cpt.CPM = cpm.Serialize()
}
cptStr := cpt.Serialize()
timeInStr := strconv.FormatFloat(cpt.Time, 'f', -1, 64)
trcInst := mrnes.TraceInst{TraceTime: timeInStr, TraceType:"CP", TraceStr: cptStr}
tm.AddTrace(vrt, cpt.ExecID, trcInst)
}