execdetails: refine cop task execution stats display in plan (#23461)

This commit is contained in:
crazycs
2021-04-01 22:05:24 +08:00
committed by GitHub
parent cd5b91fa03
commit 01b05745d8
4 changed files with 15 additions and 8 deletions

View File

@ -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}")
}

View File

@ -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()

View File

@ -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()

View File

@ -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) {