From 01b05745d8ea16efaeb71b4bb68e7b65355e1598 Mon Sep 17 00:00:00 2001 From: crazycs Date: Thu, 1 Apr 2021 22:05:24 +0800 Subject: [PATCH] execdetails: refine cop task execution stats display in plan (#23461) --- distsql/select_result_test.go | 2 +- executor/explainfor_test.go | 2 +- util/execdetails/execdetails.go | 11 +++++++---- util/execdetails/execdetails_test.go | 8 ++++++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/distsql/select_result_test.go b/distsql/select_result_test.go index 38a57ebe94..2046f53c51 100644 --- a/distsql/select_result_test.go +++ b/distsql/select_result_test.go @@ -48,5 +48,5 @@ func (s *testSuite) TestUpdateCopRuntimeStats(c *C) { c.Assert(ctx.GetSessionVars().StmtCtx.RuntimeStatsColl, NotNil) c.Assert(len(sr.selectResp.GetExecutionSummaries()), Equals, len(sr.copPlanIDs)) sr.updateCopRuntimeStats(context.Background(), &copr.CopRuntimeStats{ExecDetails: execdetails.ExecDetails{CalleeAddress: "callee"}}, 0) - c.Assert(ctx.GetSessionVars().StmtCtx.RuntimeStatsColl.GetOrCreateCopStats(1234, "tikv").String(), Equals, "tikv_task:{time:1ns, loops:1}, scan_detail: {total_process_keys: 0, total_keys: 0, rocksdb: {delete_skipped_count: 0, key_skipped_count: 0, block: {cache_hit_count: 0, read_count: 0, read_byte: 0 Bytes}}}") + c.Assert(ctx.GetSessionVars().StmtCtx.RuntimeStatsColl.GetOrCreateCopStats(1234, "tikv").String(), Equals, "tikv_task:{time:1ns, loops:1}") } diff --git a/executor/explainfor_test.go b/executor/explainfor_test.go index 9aa42dda62..a113200a92 100644 --- a/executor/explainfor_test.go +++ b/executor/explainfor_test.go @@ -113,7 +113,7 @@ func (s *testSerialSuite) TestExplainFor(c *C) { } c.Assert(buf.String(), Matches, ""+ "TableReader_5 10000.00 0 root time:.*, loops:1, cop_task: {num:.*, max:.*, proc_keys: 0, rpc_num: 1, rpc_time:.*} data:TableFullScan_4 N/A N/A\n"+ - "└─TableFullScan_4 10000.00 0 cop.* table:t1 tikv_task:{time:.*, loops:0}, scan_detail:.* keep order:false, stats:pseudo N/A N/A") + "└─TableFullScan_4 10000.00 0 cop.* table:t1 tikv_task:{time:.*, loops:0} keep order:false, stats:pseudo N/A N/A") } tkRoot.MustQuery("select * from t1;") check() diff --git a/util/execdetails/execdetails.go b/util/execdetails/execdetails.go index 322b639f3c..010b301963 100644 --- a/util/execdetails/execdetails.go +++ b/util/execdetails/execdetails.go @@ -243,9 +243,11 @@ func (sd *ScanDetail) Merge(scanDetail *ScanDetail) { atomic.AddUint64(&sd.RocksdbBlockReadByte, scanDetail.RocksdbBlockReadByte) } +var zeroScanDetail = ScanDetail{} + // String implements the fmt.Stringer interface. func (sd *ScanDetail) String() string { - if sd == nil { + if sd == nil || *sd == zeroScanDetail { return "" } buf := bytes.NewBuffer(make([]byte, 0, 16)) @@ -612,10 +614,11 @@ func (crs *CopRuntimeStats) String() string { buf.WriteString("}") } } - if !isTiFlashCop { - if detail := crs.scanDetail; detail != nil { + if !isTiFlashCop && crs.scanDetail != nil { + detail := crs.scanDetail.String() + if detail != "" { buf.WriteString(", ") - buf.WriteString(detail.String()) + buf.WriteString(detail) } } return buf.String() diff --git a/util/execdetails/execdetails_test.go b/util/execdetails/execdetails_test.go index 4702ba3439..702cdf4d07 100644 --- a/util/execdetails/execdetails_test.go +++ b/util/execdetails/execdetails_test.go @@ -130,8 +130,7 @@ func TestCopRuntimeStats(t *testing.T) { t.Fatalf("cop stats string is not expect, got: %v", copStats[0].String()) } - if stats.GetOrCreateCopStats(aggID, "tikv").String() != "tikv_task:{proc max:4ns, min:3ns, p80:4ns, p95:4ns, iters:7, tasks:2}, "+ - "scan_detail: {total_process_keys: 0, total_keys: 0, rocksdb: {delete_skipped_count: 0, key_skipped_count: 0, block: {cache_hit_count: 0, read_count: 0, read_byte: 0 Bytes}}}" { + if stats.GetOrCreateCopStats(aggID, "tikv").String() != "tikv_task:{proc max:4ns, min:3ns, p80:4ns, p95:4ns, iters:7, tasks:2}" { t.Fatalf("agg cop stats string is not as expected, got: %v", stats.GetOrCreateCopStats(aggID, "tikv").String()) } rootStats := stats.GetRootStats(tableReaderID) @@ -150,6 +149,11 @@ func TestCopRuntimeStats(t *testing.T) { "scan_detail: {total_process_keys: 0, total_keys: 15, rocksdb: {delete_skipped_count: 5, key_skipped_count: 0, block: {cache_hit_count: 10, read_count: 0, read_byte: 100 Bytes}}}" { t.Fatalf(cop.String()) } + + zeroScanDetail := ScanDetail{} + if zeroScanDetail.String() != "" { + t.Fatalf(zeroScanDetail.String()) + } } func TestCopRuntimeStatsForTiFlash(t *testing.T) {