-
Notifications
You must be signed in to change notification settings - Fork 0
/
frame_times.go
80 lines (64 loc) · 1.68 KB
/
frame_times.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
package libphonelabgo
import (
"fmt"
phonelab "github.com/shaseley/phonelab-go"
)
type FrameRefreshEvent struct {
SysTimeNs int64
TraceTimeAdj float64
}
func (event *FrameRefreshEvent) MonotonicTimestamp() float64 {
if GlobalConf.UseSysTime {
return float64(event.SysTimeNs) / nsPerSecF
} else {
return event.TraceTimeAdj
}
}
type FrameRefreshEmitter struct {
Source phonelab.Processor
}
func (emitter *FrameRefreshEmitter) Process() <-chan interface{} {
outChan := make(chan interface{})
go func() {
inChan := emitter.Source.Process()
// Clock skew between different monotonic clocks.
// Add this to diff timestamps to get trace timestamp.
curOffsetNs := int64(0)
prevToken := int64(-1)
for iLog := range inChan {
if ll, ok := iLog.(*phonelab.Logline); ok {
switch t := ll.Payload.(type) {
case *SFFrameTimesLog:
{
// Check token for things that don't look quite right
if prevToken >= 0 && prevToken+1 != t.Token {
fmt.Printf("Warning: Missing tokens. Prev = %v, New = %v\n", prevToken, t.Token)
}
prevToken = t.Token
// Unpack
for _, sysTs := range t.Times {
outChan <- &FrameRefreshEvent{
SysTimeNs: sysTs,
TraceTimeAdj: float64(sysTs+curOffsetNs) / nsPerSecF,
}
}
}
case *TimeSyncMsg:
{
// Update current time offset
curOffsetNs = t.OffsetNs
}
}
}
}
close(outChan)
}()
return outChan
}
type FrameRefreshEmitterGen struct{}
func (g *FrameRefreshEmitterGen) GenerateProcessor(source *phonelab.PipelineSourceInstance,
kwargs map[string]interface{}) phonelab.Processor {
return &FrameRefreshEmitter{
Source: source.Processor,
}
}