github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/colexec/execpb/stats.go (about) 1 // Copyright 2019 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package execpb 12 13 import ( 14 "fmt" 15 "time" 16 17 "github.com/cockroachdb/cockroach/pkg/col/coldata" 18 "github.com/cockroachdb/cockroach/pkg/sql/execinfrapb" 19 "github.com/cockroachdb/cockroach/pkg/util/humanizeutil" 20 "github.com/cockroachdb/cockroach/pkg/util/tracing" 21 ) 22 23 var _ tracing.SpanStats = &VectorizedStats{} 24 var _ execinfrapb.DistSQLSpanStats = &VectorizedStats{} 25 26 const ( 27 batchesOutputTagSuffix = "output.batches" 28 tuplesOutputTagSuffix = "output.tuples" 29 selectivityTagSuffix = "selectivity" 30 stallTimeTagSuffix = "time.stall" 31 executionTimeTagSuffix = "time.execution" 32 maxVecMemoryBytesTagSuffix = "mem.vectorized.max" 33 maxVecDiskBytesTagSuffix = "disk.vectorized.max" 34 ) 35 36 // Stats is part of SpanStats interface. 37 func (vs *VectorizedStats) Stats() map[string]string { 38 var timeSuffix string 39 if vs.Stall { 40 timeSuffix = stallTimeTagSuffix 41 } else { 42 timeSuffix = executionTimeTagSuffix 43 } 44 selectivity := float64(0) 45 if vs.NumBatches > 0 { 46 selectivity = float64(vs.NumTuples) / float64(int64(coldata.BatchSize())*vs.NumBatches) 47 } 48 return map[string]string{ 49 batchesOutputTagSuffix: fmt.Sprintf("%d", vs.NumBatches), 50 tuplesOutputTagSuffix: fmt.Sprintf("%d", vs.NumTuples), 51 selectivityTagSuffix: fmt.Sprintf("%.2f", selectivity), 52 timeSuffix: fmt.Sprintf("%v", vs.Time.Round(time.Microsecond)), 53 maxVecMemoryBytesTagSuffix: fmt.Sprintf("%d", vs.MaxAllocatedMem), 54 maxVecDiskBytesTagSuffix: fmt.Sprintf("%d", vs.MaxAllocatedDisk), 55 } 56 } 57 58 const ( 59 batchesOutputQueryPlanSuffix = "batches output" 60 tuplesOutputQueryPlanSuffix = "tuples output" 61 selectivityQueryPlanSuffix = "selectivity" 62 stallTimeQueryPlanSuffix = "stall time" 63 executionTimeQueryPlanSuffix = "execution time" 64 maxVecMemoryBytesQueryPlanSuffix = "max vectorized memory allocated" 65 maxVecDiskBytesQueryPlanSuffix = "max vectorized disk allocated" 66 ) 67 68 // StatsForQueryPlan is part of DistSQLSpanStats interface. 69 func (vs *VectorizedStats) StatsForQueryPlan() []string { 70 var timeSuffix string 71 if vs.Stall { 72 timeSuffix = stallTimeQueryPlanSuffix 73 } else { 74 timeSuffix = executionTimeQueryPlanSuffix 75 } 76 selectivity := float64(0) 77 if vs.NumBatches > 0 { 78 selectivity = float64(vs.NumTuples) / float64(int64(coldata.BatchSize())*vs.NumBatches) 79 } 80 stats := []string{ 81 fmt.Sprintf("%s: %d", batchesOutputQueryPlanSuffix, vs.NumBatches), 82 fmt.Sprintf("%s: %d", tuplesOutputQueryPlanSuffix, vs.NumTuples), 83 fmt.Sprintf("%s: %.2f", selectivityQueryPlanSuffix, selectivity), 84 fmt.Sprintf("%s: %v", timeSuffix, vs.Time.Round(time.Microsecond)), 85 } 86 87 if vs.MaxAllocatedMem != 0 { 88 stats = append(stats, 89 fmt.Sprintf("%s: %s", maxVecMemoryBytesQueryPlanSuffix, humanizeutil.IBytes(vs.MaxAllocatedMem))) 90 } 91 92 if vs.MaxAllocatedDisk != 0 { 93 stats = append(stats, 94 fmt.Sprintf("%s: %s", maxVecDiskBytesQueryPlanSuffix, humanizeutil.IBytes(vs.MaxAllocatedDisk))) 95 } 96 return stats 97 }