-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils_tf.go
86 lines (76 loc) · 2.3 KB
/
utils_tf.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
package evaluation
import (
json "encoding/json"
"strings"
model "github.com/uber/jaeger/model/json"
)
type TensorFlowTagOutput struct {
TensorDescription TensorDescription `json:"tensor_description"`
}
type Dim struct {
Size int `json:"size"`
}
type Shape struct {
Dim []Dim `json:"dim"`
}
type AllocationDescription struct {
RequestedBytes int `json:"requested_bytes"`
AllocatedBytes int `json:"allocated_bytes"`
AllocatorName string `json:"allocator_name"`
AllocationID int `json:"allocation_id"`
Ptr int64 `json:"ptr"`
}
type TensorDescription struct {
Dtype int `json:"dtype"`
Shape Shape `json:"shape"`
AllocationDescription AllocationDescription `json:"allocation_description"`
}
func getAllocationDescription(span model.Span) AllocationDescription {
ret := AllocationDescription{}
output, err := getTagValueAsString(span, "output")
if err != nil {
log.WithError(err).Info("fail to get output value in the tags")
return ret
}
if output == "" {
return ret
}
output = strings.Replace(output, "\\", "", -1)
var result []TensorFlowTagOutput
json.Unmarshal([]byte(output), &result)
if len(result) == 0 {
return ret
}
ret = result[0].TensorDescription.AllocationDescription
return ret
}
type TensorFlowAllocatorMemoryUsed struct {
AllocatorName string `json:"allocator_name"`
TotalBytes int `json:"total_bytes"`
PeakBytes int `json:"peak_bytes"`
LiveBytes int `json:"live_bytes"`
AllocationRecords []AllocationRecords `json:"allocation_records"`
AllocatorBytesInUse int `json:"allocator_bytes_in_use"`
}
type AllocationRecords struct {
AllocMicros int64 `json:"alloc_micros"`
AllocBytes int `json:"alloc_bytes"`
}
func getTensorFlowAllocatorMemoryUsed(span model.Span) (TensorFlowAllocatorMemoryUsed, bool) {
ret := TensorFlowAllocatorMemoryUsed{}
output, err := getTagValueAsString(span, "memory")
if err != nil {
return ret, false
}
if output == "" {
return ret, false
}
output = strings.Replace(output, "\\", "", -1)
var result []TensorFlowAllocatorMemoryUsed
json.Unmarshal([]byte(output), &result)
if len(result) == 0 {
return ret, false
}
ret = result[0]
return ret, true
}