mirror of https://github.com/tikv/client-go.git
cop: fix time detail merge (#1258)
* time detail merge Signed-off-by: cfzjywxk <cfzjywxk@gmail.com> * fix test Signed-off-by: cfzjywxk <cfzjywxk@gmail.com> --------- Signed-off-by: cfzjywxk <cfzjywxk@gmail.com>
This commit is contained in:
parent
146a6329d8
commit
c2927c0ec6
|
|
@ -321,25 +321,15 @@ func (s *testSnapshotSuite) TestSnapshotRuntimeStats() {
|
||||||
}
|
}
|
||||||
snapshot.MergeExecDetail(detail)
|
snapshot.MergeExecDetail(detail)
|
||||||
expect = "Get:{num_rpc:4, total_time:2s},txnLockFast_backoff:{num:2, total_time:10ms}, " +
|
expect = "Get:{num_rpc:4, total_time:2s},txnLockFast_backoff:{num:2, total_time:10ms}, " +
|
||||||
"total_process_time: 100ms, total_wait_time: 100ms, " +
|
"time_detail: {total_process_time: 100ms, total_wait_time: 100ms}, " +
|
||||||
"scan_detail: {total_process_keys: 10, " +
|
"scan_detail: {total_process_keys: 10, total_process_keys_size: 10, total_keys: 15, get_snapshot_time: 500ns, " +
|
||||||
"total_process_keys_size: 10, " +
|
"rocksdb: {delete_skipped_count: 5, key_skipped_count: 1, block: {cache_hit_count: 10, read_count: 20, read_byte: 15 Bytes}}}"
|
||||||
"total_keys: 15, " +
|
|
||||||
"get_snapshot_time: 500ns, " +
|
|
||||||
"rocksdb: {delete_skipped_count: 5, " +
|
|
||||||
"key_skipped_count: 1, " +
|
|
||||||
"block: {cache_hit_count: 10, read_count: 20, read_byte: 15 Bytes}}}"
|
|
||||||
s.Equal(expect, snapshot.FormatStats())
|
s.Equal(expect, snapshot.FormatStats())
|
||||||
snapshot.MergeExecDetail(detail)
|
snapshot.MergeExecDetail(detail)
|
||||||
expect = "Get:{num_rpc:4, total_time:2s},txnLockFast_backoff:{num:2, total_time:10ms}, " +
|
expect = "Get:{num_rpc:4, total_time:2s},txnLockFast_backoff:{num:2, total_time:10ms}, " +
|
||||||
"total_process_time: 200ms, total_wait_time: 200ms, " +
|
"time_detail: {total_process_time: 200ms, total_wait_time: 200ms}, " +
|
||||||
"scan_detail: {total_process_keys: 20, " +
|
"scan_detail: {total_process_keys: 20, total_process_keys_size: 20, total_keys: 30, get_snapshot_time: 1µs, " +
|
||||||
"total_process_keys_size: 20, " +
|
"rocksdb: {delete_skipped_count: 10, key_skipped_count: 2, block: {cache_hit_count: 20, read_count: 40, read_byte: 30 Bytes}}}"
|
||||||
"total_keys: 30, " +
|
|
||||||
"get_snapshot_time: 1µs, " +
|
|
||||||
"rocksdb: {delete_skipped_count: 10, " +
|
|
||||||
"key_skipped_count: 2, " +
|
|
||||||
"block: {cache_hit_count: 20, read_count: 40, read_byte: 30 Bytes}}}"
|
|
||||||
s.Equal(expect, snapshot.FormatStats())
|
s.Equal(expect, snapshot.FormatStats())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -635,6 +635,7 @@ func (td *TimeDetail) String() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
buf := bytes.NewBuffer(make([]byte, 0, 16))
|
buf := bytes.NewBuffer(make([]byte, 0, 16))
|
||||||
|
buf.WriteString("time_detail: {")
|
||||||
if td.ProcessTime > 0 {
|
if td.ProcessTime > 0 {
|
||||||
buf.WriteString("total_process_time: ")
|
buf.WriteString("total_process_time: ")
|
||||||
buf.WriteString(FormatDuration(td.ProcessTime))
|
buf.WriteString(FormatDuration(td.ProcessTime))
|
||||||
|
|
@ -667,17 +668,19 @@ func (td *TimeDetail) String() string {
|
||||||
buf.WriteString("tikv_wall_time: ")
|
buf.WriteString("tikv_wall_time: ")
|
||||||
buf.WriteString(FormatDuration(td.TotalRPCWallTime))
|
buf.WriteString(FormatDuration(td.TotalRPCWallTime))
|
||||||
}
|
}
|
||||||
|
buf.WriteString("}")
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge merges the time detail into itself.
|
// Merge merges the time detail into itself.
|
||||||
|
// Note this function could be called concurrently.
|
||||||
func (td *TimeDetail) Merge(detail *TimeDetail) {
|
func (td *TimeDetail) Merge(detail *TimeDetail) {
|
||||||
if detail != nil {
|
if detail != nil {
|
||||||
td.ProcessTime += detail.ProcessTime
|
atomic.AddInt64((*int64)(&td.ProcessTime), int64(detail.ProcessTime))
|
||||||
td.SuspendTime += detail.SuspendTime
|
atomic.AddInt64((*int64)(&td.SuspendTime), int64(detail.SuspendTime))
|
||||||
td.WaitTime += detail.WaitTime
|
atomic.AddInt64((*int64)(&td.WaitTime), int64(detail.WaitTime))
|
||||||
td.KvReadWallTime += detail.KvReadWallTime
|
atomic.AddInt64((*int64)(&td.KvReadWallTime), int64(detail.KvReadWallTime))
|
||||||
td.TotalRPCWallTime += detail.TotalRPCWallTime
|
atomic.AddInt64((*int64)(&td.TotalRPCWallTime), int64(detail.TotalRPCWallTime))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue