-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathstats.go
123 lines (115 loc) · 4.24 KB
/
stats.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
// Copyright 2019 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package execpb
import (
"fmt"
"time"
"github.com/cockroachdb/cockroach/pkg/sql/execinfrapb"
"github.com/cockroachdb/cockroach/pkg/util/humanizeutil"
"github.com/cockroachdb/cockroach/pkg/util/tracing"
)
var _ tracing.SpanStats = &VectorizedStats{}
var _ execinfrapb.DistSQLSpanStats = &VectorizedStats{}
const (
batchesOutputTagSuffix = "output.batches"
tuplesOutputTagSuffix = "output.tuples"
ioTimeTagSuffix = "time.io"
executionTimeTagSuffix = "time.execution"
deserializationTimeTagSuffix = "time.deserialization"
maxVecMemoryBytesTagSuffix = "mem.vectorized.max"
maxVecDiskBytesTagSuffix = "disk.vectorized.max"
bytesReadTagSuffix = "bytes.read"
rowsReadTagSuffix = "rows.read"
networkLatencyTagSuffix = "network.latency"
)
// Stats is part of SpanStats interface.
func (vs *VectorizedStats) Stats() map[string]string {
var timeSuffix string
if vs.IO {
if vs.OnStream {
timeSuffix = deserializationTimeTagSuffix
} else {
timeSuffix = ioTimeTagSuffix
}
} else {
timeSuffix = executionTimeTagSuffix
}
stats := map[string]string{
batchesOutputTagSuffix: fmt.Sprintf("%d", vs.NumBatches),
timeSuffix: fmt.Sprintf("%v", vs.Time.Round(time.Microsecond)),
maxVecMemoryBytesTagSuffix: fmt.Sprintf("%d", vs.MaxAllocatedMem),
maxVecDiskBytesTagSuffix: fmt.Sprintf("%d", vs.MaxAllocatedDisk),
}
if vs.OnStream {
stats[networkLatencyTagSuffix] = fmt.Sprintf("%v", time.Duration(vs.NetworkLatency).Round(time.Microsecond))
stats[timeSuffix] = fmt.Sprintf("%v", (vs.Time - time.Duration(vs.NetworkLatency)).Round(time.Microsecond))
} else {
stats[tuplesOutputTagSuffix] = fmt.Sprintf("%d", vs.NumTuples)
}
if vs.BytesRead != 0 {
stats[bytesReadTagSuffix] = humanizeutil.IBytes(vs.BytesRead)
}
if vs.RowsRead != 0 {
stats[rowsReadTagSuffix] = fmt.Sprintf("%d", vs.RowsRead)
}
return stats
}
const (
batchesOutputQueryPlanSuffix = "batches output"
tuplesOutputQueryPlanSuffix = "tuples output"
ioTimeQueryPlanSuffix = "IO time"
executionTimeQueryPlanSuffix = "execution time"
deserializationTimeQueryPlanSuffix = "deserialization time"
maxVecMemoryBytesQueryPlanSuffix = "max vectorized memory allocated"
maxVecDiskBytesQueryPlanSuffix = "max vectorized disk allocated"
bytesReadQueryPlanSuffix = "bytes read"
rowsReadQueryPlanSuffix = "rows read"
networkLatencyQueryPlanSuffix = "network latency"
)
// StatsForQueryPlan is part of DistSQLSpanStats interface.
func (vs *VectorizedStats) StatsForQueryPlan() []string {
var timeSuffix string
if vs.IO {
if vs.OnStream {
timeSuffix = deserializationTimeQueryPlanSuffix
} else {
timeSuffix = ioTimeQueryPlanSuffix
}
} else {
timeSuffix = executionTimeQueryPlanSuffix
}
stats := []string{
fmt.Sprintf("%s: %d", batchesOutputQueryPlanSuffix, vs.NumBatches),
}
if vs.OnStream {
stats = append(stats,
fmt.Sprintf("%s: %v", timeSuffix, (vs.Time-time.Duration(vs.NetworkLatency)).Round(time.Microsecond)),
fmt.Sprintf("%s: %v", networkLatencyQueryPlanSuffix, time.Duration(vs.NetworkLatency).Round(time.Microsecond)))
} else {
stats = append(stats, fmt.Sprintf("%s: %d", tuplesOutputQueryPlanSuffix, vs.NumTuples),
fmt.Sprintf("%s: %v", timeSuffix, vs.Time.Round(time.Microsecond)))
}
if vs.MaxAllocatedMem != 0 {
stats = append(stats,
fmt.Sprintf("%s: %s", maxVecMemoryBytesQueryPlanSuffix, humanizeutil.IBytes(vs.MaxAllocatedMem)))
}
if vs.MaxAllocatedDisk != 0 {
stats = append(stats,
fmt.Sprintf("%s: %s", maxVecDiskBytesQueryPlanSuffix, humanizeutil.IBytes(vs.MaxAllocatedDisk)))
}
if vs.BytesRead != 0 {
stats = append(stats,
fmt.Sprintf("%s: %s", bytesReadQueryPlanSuffix, humanizeutil.IBytes(vs.BytesRead)))
}
if vs.RowsRead != 0 {
stats = append(stats, fmt.Sprintf("%s: %d", rowsReadQueryPlanSuffix, vs.RowsRead))
}
return stats
}