Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sessionctx, executor, infoschema: Add fine grained network traffic stats in slow log #59041

Merged
merged 9 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions pkg/executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1690,9 +1690,7 @@ func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool, hasMoreResults bool) {
PlanFromCache: sessVars.FoundInPlanCache,
PlanFromBinding: sessVars.FoundInBinding,
RewriteInfo: sessVars.RewritePhaseInfo,
KVTotal: time.Duration(atomic.LoadInt64(&tikvExecDetail.WaitKVRespDuration)),
PDTotal: time.Duration(atomic.LoadInt64(&tikvExecDetail.WaitPDRespDuration)),
BackoffTotal: time.Duration(atomic.LoadInt64(&tikvExecDetail.BackoffDuration)),
KVExecDetail: &tikvExecDetail,
WriteSQLRespTotal: stmtDetail.WriteSQLRespDuration,
ResultRows: resultRows,
ExecRetryCount: a.retryCount,
Expand Down Expand Up @@ -2031,7 +2029,7 @@ func (a *ExecStmt) SummaryStmt(succ bool) {
stmtExecInfo.ExecRetryCount = a.retryCount
stmtExecInfo.StmtExecDetails = stmtDetail
stmtExecInfo.ResultRows = resultRows
stmtExecInfo.TiKVExecDetails = tikvExecDetail
stmtExecInfo.TiKVExecDetails = &tikvExecDetail
stmtExecInfo.Prepared = a.isPreparedStmt
stmtExecInfo.KeyspaceName = keyspaceName
stmtExecInfo.KeyspaceID = keyspaceID
Expand Down
5 changes: 4 additions & 1 deletion pkg/executor/slow_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,10 @@ func getColumnValueFactoryByName(colName string, columnIdx int) (slowQueryColumn
row[columnIdx] = types.NewStringDatum(value)
return true, nil
}, nil
case variable.SlowLogMemMax, variable.SlowLogDiskMax, variable.SlowLogResultRows:
case variable.SlowLogMemMax, variable.SlowLogDiskMax, variable.SlowLogResultRows, variable.SlowLogUnpackedBytesSentKVTotal,
variable.SlowLogUnpackedBytesReceivedKVTotal, variable.SlowLogUnpackedBytesSentKVCrossZone, variable.SlowLogUnpackedBytesReceivedKVCrossZone,
variable.SlowLogUnpackedBytesSentMPPTotal, variable.SlowLogUnpackedBytesReceivedMPPTotal, variable.SlowLogUnpackedBytesSentMPPCrossZone,
variable.SlowLogUnpackedBytesReceivedMPPCrossZone:
return func(row []types.Datum, value string, _ *time.Location, _ *slowLogChecker) (valid bool, err error) {
v, err := strconv.ParseInt(value, 10, 64)
if err != nil {
Expand Down
12 changes: 10 additions & 2 deletions pkg/executor/slow_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ func TestParseSlowLogFile(t *testing.T) {
# Disk_max: 65536
# Plan_from_cache: true
# Plan_from_binding: true
# Unpacked_bytes_sent_kv_total: 30000
# Unpacked_bytes_received_kv_total: 3000
# Unpacked_bytes_sent_kv_cross_zone: 10000
# Unpacked_bytes_received_kv_cross_zone: 1000
# Unpacked_bytes_sent_mpp_total: 500000
# Unpacked_bytes_received_mpp_total: 500005
# Unpacked_bytes_sent_mpp_cross_zone: 300000
# Unpacked_bytes_received_mpp_cross_zone: 300005
# Succ: false
# IsExplicitTxn: true
# Resource_group: default
Expand Down Expand Up @@ -173,7 +181,7 @@ select * from t;`
expectRecordString := `2019-04-28 15:24:04.309074,` +
`405888132465033227,root,localhost,0,alias123,57,0.12,0.216905,` +
`0,0,0,0,0,0,0,0,0,0,0,0,,0,0,0,0,0,0,0.38,0.021,0,0,0,1,637,0,10,10,10,10,100,,,1,42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772,t1:1,t2:2,` +
`0.1,0.2,0.03,127.0.0.1:20160,0.05,0.6,0.8,0.0.0.0:20160,70724,65536,0,0,0,0,0,,` +
`0.1,0.2,0.03,127.0.0.1:20160,0.05,0.6,0.8,0.0.0.0:20160,70724,65536,0,0,0,30000,3000,10000,1000,500000,500005,300000,300005,0,0,,` +
`Cop_backoff_regionMiss_total_times: 200 Cop_backoff_regionMiss_total_time: 0.2 Cop_backoff_regionMiss_max_time: 0.2 Cop_backoff_regionMiss_max_addr: 127.0.0.1 Cop_backoff_regionMiss_avg_time: 0.2 Cop_backoff_regionMiss_p90_time: 0.2 Cop_backoff_rpcPD_total_times: 200 Cop_backoff_rpcPD_total_time: 0.2 Cop_backoff_rpcPD_max_time: 0.2 Cop_backoff_rpcPD_max_addr: 127.0.0.1 Cop_backoff_rpcPD_avg_time: 0.2 Cop_backoff_rpcPD_p90_time: 0.2 Cop_backoff_rpcTiKV_total_times: 200 Cop_backoff_rpcTiKV_total_time: 0.2 Cop_backoff_rpcTiKV_max_time: 0.2 Cop_backoff_rpcTiKV_max_addr: 127.0.0.1 Cop_backoff_rpcTiKV_avg_time: 0.2 Cop_backoff_rpcTiKV_p90_time: 0.2,` +
`0,0,1,0,1,1,0,default,2.158,2.123,0.05,0.01,0.021,,60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4,` +
`,update t set i = 1;,select * from t;`
Expand All @@ -196,7 +204,7 @@ select * from t;`
expectRecordString = `2019-04-28 15:24:04.309074,` +
`405888132465033227,root,localhost,0,alias123,57,0.12,0.216905,` +
`0,0,0,0,0,0,0,0,0,0,0,0,,0,0,0,0,0,0,0.38,0.021,0,0,0,1,637,0,10,10,10,10,100,,,1,42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772,t1:1,t2:2,` +
`0.1,0.2,0.03,127.0.0.1:20160,0.05,0.6,0.8,0.0.0.0:20160,70724,65536,0,0,0,0,0,,` +
`0.1,0.2,0.03,127.0.0.1:20160,0.05,0.6,0.8,0.0.0.0:20160,70724,65536,0,0,0,30000,3000,10000,1000,500000,500005,300000,300005,0,0,,` +
`Cop_backoff_regionMiss_total_times: 200 Cop_backoff_regionMiss_total_time: 0.2 Cop_backoff_regionMiss_max_time: 0.2 Cop_backoff_regionMiss_max_addr: 127.0.0.1 Cop_backoff_regionMiss_avg_time: 0.2 Cop_backoff_regionMiss_p90_time: 0.2 Cop_backoff_rpcPD_total_times: 200 Cop_backoff_rpcPD_total_time: 0.2 Cop_backoff_rpcPD_max_time: 0.2 Cop_backoff_rpcPD_max_addr: 127.0.0.1 Cop_backoff_rpcPD_avg_time: 0.2 Cop_backoff_rpcPD_p90_time: 0.2 Cop_backoff_rpcTiKV_total_times: 200 Cop_backoff_rpcTiKV_total_time: 0.2 Cop_backoff_rpcTiKV_max_time: 0.2 Cop_backoff_rpcTiKV_max_addr: 127.0.0.1 Cop_backoff_rpcTiKV_avg_time: 0.2 Cop_backoff_rpcTiKV_p90_time: 0.2,` +
`0,0,1,0,1,1,0,default,2.158,2.123,0.05,0.01,0.021,,60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4,` +
`,update t set i = 1;,select * from t;`
Expand Down
8 changes: 8 additions & 0 deletions pkg/infoschema/internal/testkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ select * from t_slim;
# KV_total: 86.635049185
# PD_total: 0.015486658
# Backoff_total: 100.054
# Unpacked_bytes_sent_kv_total: 30000
# Unpacked_bytes_received_kv_total: 3000
# Unpacked_bytes_sent_kv_cross_zone: 10000
# Unpacked_bytes_received_kv_cross_zone: 1000
# Unpacked_bytes_sent_mpp_total: 500000
# Unpacked_bytes_received_mpp_total: 500005
# Unpacked_bytes_sent_mpp_cross_zone: 300000
# Unpacked_bytes_received_mpp_cross_zone: 300005
# Write_sql_response_total: 0
# Succ: true
# Resource_group: rg1
Expand Down
8 changes: 8 additions & 0 deletions pkg/infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,14 @@ var slowQueryCols = []columnInfo{
{name: variable.SlowLogKVTotal, tp: mysql.TypeDouble, size: 22},
{name: variable.SlowLogPDTotal, tp: mysql.TypeDouble, size: 22},
{name: variable.SlowLogBackoffTotal, tp: mysql.TypeDouble, size: 22},
{name: variable.SlowLogUnpackedBytesSentKVTotal, tp: mysql.TypeLonglong, size: 22},
{name: variable.SlowLogUnpackedBytesReceivedKVTotal, tp: mysql.TypeLonglong, size: 22},
{name: variable.SlowLogUnpackedBytesSentKVCrossZone, tp: mysql.TypeLonglong, size: 22},
{name: variable.SlowLogUnpackedBytesReceivedKVCrossZone, tp: mysql.TypeLonglong, size: 22},
{name: variable.SlowLogUnpackedBytesSentMPPTotal, tp: mysql.TypeLonglong, size: 22},
{name: variable.SlowLogUnpackedBytesReceivedMPPTotal, tp: mysql.TypeLonglong, size: 22},
{name: variable.SlowLogUnpackedBytesSentMPPCrossZone, tp: mysql.TypeLonglong, size: 22},
{name: variable.SlowLogUnpackedBytesReceivedMPPCrossZone, tp: mysql.TypeLonglong, size: 22},
{name: variable.SlowLogWriteSQLRespTotal, tp: mysql.TypeDouble, size: 22},
{name: variable.SlowLogResultRows, tp: mysql.TypeLonglong, size: 22},
{name: variable.SlowLogWarnings, tp: mysql.TypeLongBlob, size: types.UnspecifiedLength},
Expand Down
16 changes: 16 additions & 0 deletions pkg/infoschema/test/clustertablestest/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,14 @@ func TestSlowQuery(t *testing.T) {
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"10",
"",
"",
Expand Down Expand Up @@ -517,6 +525,14 @@ func TestSlowQuery(t *testing.T) {
"86.635049185",
"0.015486658",
"100.054",
"30000",
"3000",
"10000",
"1000",
"500000",
"500005",
"300000",
"300005",
"0",
"0",
"",
Expand Down
35 changes: 29 additions & 6 deletions pkg/sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import (
"github.com/pingcap/tipb/go-tipb"
tikvstore "github.com/tikv/client-go/v2/kv"
"github.com/tikv/client-go/v2/tikv"
"github.com/tikv/client-go/v2/util"
"github.com/twmb/murmur3"
atomic2 "go.uber.org/atomic"
)
Expand Down Expand Up @@ -3274,6 +3275,22 @@ const (
SlowLogPDTotal = "PD_total"
// SlowLogBackoffTotal is the total time doing backoff.
SlowLogBackoffTotal = "Backoff_total"
// SlowLogUnpackedBytesSentKVTotal is the total bytes sent by tikv.
SlowLogUnpackedBytesSentKVTotal = "Unpacked_bytes_sent_kv_total"
// SlowLogUnpackedBytesReceivedKVTotal is the total bytes received by tikv.
SlowLogUnpackedBytesReceivedKVTotal = "Unpacked_bytes_received_kv_total"
// SlowLogUnpackedBytesSentKVCrossZone is the cross zone bytes sent by tikv.
SlowLogUnpackedBytesSentKVCrossZone = "Unpacked_bytes_sent_kv_cross_zone"
// SlowLogUnpackedBytesReceivedKVCrossZone is the cross zone bytes received by tikv.
SlowLogUnpackedBytesReceivedKVCrossZone = "Unpacked_bytes_received_kv_cross_zone"
// SlowLogUnpackedBytesSentMPPTotal is the total bytes sent by tiflash.
SlowLogUnpackedBytesSentMPPTotal = "Unpacked_bytes_sent_mpp_total"
// SlowLogUnpackedBytesReceivedMPPTotal is the total bytes received by tiflash.
SlowLogUnpackedBytesReceivedMPPTotal = "Unpacked_bytes_received_mpp_total"
// SlowLogUnpackedBytesSentMPPCrossZone is the cross zone bytes sent by tiflash.
SlowLogUnpackedBytesSentMPPCrossZone = "Unpacked_bytes_sent_mpp_cross_zone"
// SlowLogUnpackedBytesReceivedMPPCrossZone is the cross zone bytes received by tiflash.
SlowLogUnpackedBytesReceivedMPPCrossZone = "Unpacked_bytes_received_mpp_cross_zone"
// SlowLogWriteSQLRespTotal is the total time used to write response to client.
SlowLogWriteSQLRespTotal = "Write_sql_response_total"
// SlowLogExecRetryCount is the execution retry count.
Expand Down Expand Up @@ -3348,9 +3365,7 @@ type SlowQueryLogItems struct {
PlanDigest string
BinaryPlan string
RewriteInfo RewritePhaseInfo
KVTotal time.Duration
PDTotal time.Duration
BackoffTotal time.Duration
KVExecDetail *util.ExecDetails
WriteSQLRespTotal time.Duration
ExecRetryCount uint
ExecRetryTime time.Duration
Expand Down Expand Up @@ -3532,9 +3547,17 @@ func (s *SessionVars) SlowLogFormat(logItems *SlowQueryLogItems) string {
writeSlowLogItem(&buf, SlowLogPlanFromCache, strconv.FormatBool(logItems.PlanFromCache))
writeSlowLogItem(&buf, SlowLogPlanFromBinding, strconv.FormatBool(logItems.PlanFromBinding))
writeSlowLogItem(&buf, SlowLogHasMoreResults, strconv.FormatBool(logItems.HasMoreResults))
writeSlowLogItem(&buf, SlowLogKVTotal, strconv.FormatFloat(logItems.KVTotal.Seconds(), 'f', -1, 64))
writeSlowLogItem(&buf, SlowLogPDTotal, strconv.FormatFloat(logItems.PDTotal.Seconds(), 'f', -1, 64))
writeSlowLogItem(&buf, SlowLogBackoffTotal, strconv.FormatFloat(logItems.BackoffTotal.Seconds(), 'f', -1, 64))
writeSlowLogItem(&buf, SlowLogKVTotal, strconv.FormatFloat(time.Duration(logItems.KVExecDetail.WaitKVRespDuration).Seconds(), 'f', -1, 64))
writeSlowLogItem(&buf, SlowLogPDTotal, strconv.FormatFloat(time.Duration(logItems.KVExecDetail.WaitPDRespDuration).Seconds(), 'f', -1, 64))
writeSlowLogItem(&buf, SlowLogBackoffTotal, strconv.FormatFloat(time.Duration(logItems.KVExecDetail.BackoffDuration).Seconds(), 'f', -1, 64))
writeSlowLogItem(&buf, SlowLogUnpackedBytesSentKVTotal, strconv.FormatInt(logItems.KVExecDetail.UnpackedBytesSentKVTotal, 10))
writeSlowLogItem(&buf, SlowLogUnpackedBytesReceivedKVTotal, strconv.FormatInt(logItems.KVExecDetail.UnpackedBytesReceivedKVTotal, 10))
writeSlowLogItem(&buf, SlowLogUnpackedBytesSentKVCrossZone, strconv.FormatInt(logItems.KVExecDetail.UnpackedBytesSentKVCrossZone, 10))
writeSlowLogItem(&buf, SlowLogUnpackedBytesReceivedKVCrossZone, strconv.FormatInt(logItems.KVExecDetail.UnpackedBytesReceivedKVCrossZone, 10))
writeSlowLogItem(&buf, SlowLogUnpackedBytesSentMPPTotal, strconv.FormatInt(logItems.KVExecDetail.UnpackedBytesSentMPPTotal, 10))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we omit the log if the field is 0?

Copy link
Contributor Author

@yibin87 yibin87 Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's your option, Roger? @songrijie

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd better not to omit it, if there is no strong reason.

writeSlowLogItem(&buf, SlowLogUnpackedBytesReceivedMPPTotal, strconv.FormatInt(logItems.KVExecDetail.UnpackedBytesReceivedMPPTotal, 10))
writeSlowLogItem(&buf, SlowLogUnpackedBytesSentMPPCrossZone, strconv.FormatInt(logItems.KVExecDetail.UnpackedBytesSentMPPCrossZone, 10))
writeSlowLogItem(&buf, SlowLogUnpackedBytesReceivedMPPCrossZone, strconv.FormatInt(logItems.KVExecDetail.UnpackedBytesReceivedMPPCrossZone, 10))
writeSlowLogItem(&buf, SlowLogWriteSQLRespTotal, strconv.FormatFloat(logItems.WriteSQLRespTotal.Seconds(), 'f', -1, 64))
writeSlowLogItem(&buf, SlowLogResultRows, strconv.FormatInt(logItems.ResultRows, 10))
if len(logItems.Warnings) > 0 {
Expand Down
17 changes: 14 additions & 3 deletions pkg/sessionctx/variable/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ func TestSlowLogFormat(t *testing.T) {
# KV_total: 10
# PD_total: 11
# Backoff_total: 12
# Unpacked_bytes_sent_kv_total: 0
# Unpacked_bytes_received_kv_total: 0
# Unpacked_bytes_sent_kv_cross_zone: 0
# Unpacked_bytes_received_kv_cross_zone: 0
# Unpacked_bytes_sent_mpp_total: 0
# Unpacked_bytes_received_mpp_total: 0
# Unpacked_bytes_sent_mpp_cross_zone: 0
# Unpacked_bytes_received_mpp_cross_zone: 0
# Write_sql_response_total: 1
# Result_rows: 12345
# Succ: true
Expand All @@ -264,6 +272,11 @@ func TestSlowLogFormat(t *testing.T) {
# Time_queued_by_rc: 0.134`
sql := "select * from t;"
_, digest := parser.NormalizeDigest(sql)
tikvExecDetail := util.ExecDetails{
WaitKVRespDuration: (10 * time.Second).Nanoseconds(),
WaitPDRespDuration: (11 * time.Second).Nanoseconds(),
BackoffDuration: (12 * time.Second).Nanoseconds(),
}
logItems := &variable.SlowQueryLogItems{
TxnTS: txnTS,
KeyspaceName: "keyspace_a",
Expand All @@ -284,9 +297,7 @@ func TestSlowLogFormat(t *testing.T) {
PlanFromCache: true,
PlanFromBinding: true,
HasMoreResults: true,
KVTotal: 10 * time.Second,
PDTotal: 11 * time.Second,
BackoffTotal: 12 * time.Second,
KVExecDetail: &tikvExecDetail,
WriteSQLRespTotal: 1 * time.Second,
ResultRows: 12345,
Succ: true,
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/stmtsummary/statement_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ type StmtExecInfo struct {
ExecRetryTime time.Duration
execdetails.StmtExecDetails
ResultRows int64
TiKVExecDetails util.ExecDetails
TiKVExecDetails *util.ExecDetails
Prepared bool
KeyspaceName string
KeyspaceID uint32
Expand Down Expand Up @@ -981,7 +981,7 @@ func (ssStats *stmtSummaryStats) add(sei *StmtExecInfo) {
ssStats.sumTikvCPU += sei.CPUUsages.TikvCPUTime

// network traffic
ssStats.StmtNetworkTrafficSummary.Add(&sei.TiKVExecDetails)
ssStats.StmtNetworkTrafficSummary.Add(sei.TiKVExecDetails)

// request-units
ssStats.StmtRUSummary.Add(sei.RUDetail)
Expand Down
10 changes: 5 additions & 5 deletions pkg/util/stmtsummary/statement_summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func TestAddStatement(t *testing.T) {
StartTime: time.Date(2019, 1, 1, 10, 10, 20, 10, time.UTC),
Succeed: true,
RUDetail: util.NewRUDetailsWith(123.0, 45.6, 2*time.Second),
TiKVExecDetails: util.ExecDetails{
TiKVExecDetails: &util.ExecDetails{
TrafficDetails: util.TrafficDetails{
UnpackedBytesSentKVTotal: 100,
UnpackedBytesReceivedKVTotal: 200,
Expand Down Expand Up @@ -327,7 +327,7 @@ func TestAddStatement(t *testing.T) {
expectedSummaryElement.MaxWRU = stmtExecInfo2.RUDetail.WRU()
expectedSummaryElement.SumRUWaitDuration += stmtExecInfo2.RUDetail.RUWaitDuration()
expectedSummaryElement.MaxRUWaitDuration = stmtExecInfo2.RUDetail.RUWaitDuration()
expectedSummaryElement.StmtNetworkTrafficSummary.Add(&stmtExecInfo2.TiKVExecDetails)
expectedSummaryElement.StmtNetworkTrafficSummary.Add(stmtExecInfo2.TiKVExecDetails)

ssMap.AddStatement(stmtExecInfo2)
summary, ok = ssMap.summaryMap.Get(key)
Expand Down Expand Up @@ -408,7 +408,7 @@ func TestAddStatement(t *testing.T) {
Succeed: true,
RUDetail: util.NewRUDetailsWith(0.12, 0.34, 5*time.Microsecond),
ResourceGroupName: "rg1",
TiKVExecDetails: util.ExecDetails{
TiKVExecDetails: &util.ExecDetails{
TrafficDetails: util.TrafficDetails{
UnpackedBytesSentKVTotal: 1,
UnpackedBytesReceivedKVTotal: 300,
Expand Down Expand Up @@ -459,7 +459,7 @@ func TestAddStatement(t *testing.T) {
expectedSummaryElement.SumRRU += stmtExecInfo3.RUDetail.RRU()
expectedSummaryElement.SumWRU += stmtExecInfo3.RUDetail.WRU()
expectedSummaryElement.SumRUWaitDuration += stmtExecInfo3.RUDetail.RUWaitDuration()
expectedSummaryElement.StmtNetworkTrafficSummary.Add(&stmtExecInfo3.TiKVExecDetails)
expectedSummaryElement.StmtNetworkTrafficSummary.Add(stmtExecInfo3.TiKVExecDetails)

ssMap.AddStatement(stmtExecInfo3)
summary, ok = ssMap.summaryMap.Get(key)
Expand Down Expand Up @@ -722,7 +722,7 @@ func generateAnyExecInfo() *StmtExecInfo {
ResourceGroupName: "rg1",
RUDetail: util.NewRUDetailsWith(1.1, 2.5, 2*time.Millisecond),
CPUUsages: ppcpuusage.CPUUsages{TidbCPUTime: time.Duration(20), TikvCPUTime: time.Duration(100)},
TiKVExecDetails: util.ExecDetails{
TiKVExecDetails: &util.ExecDetails{
TrafficDetails: util.TrafficDetails{
UnpackedBytesSentKVTotal: 10,
UnpackedBytesReceivedKVTotal: 1000,
Expand Down
11 changes: 6 additions & 5 deletions pkg/util/stmtsummary/v2/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,15 +416,15 @@ func (r *StmtRecord) Add(info *stmtsummary.StmtExecInfo) {
} else {
r.MinResultRows = 0
}
r.SumKVTotal += time.Duration(atomic.LoadInt64(&info.TiKVExecDetails.WaitKVRespDuration))
r.SumPDTotal += time.Duration(atomic.LoadInt64(&info.TiKVExecDetails.WaitPDRespDuration))
r.SumBackoffTotal += time.Duration(atomic.LoadInt64(&info.TiKVExecDetails.BackoffDuration))
r.SumKVTotal += time.Duration(info.TiKVExecDetails.WaitKVRespDuration)
r.SumPDTotal += time.Duration(info.TiKVExecDetails.WaitPDRespDuration)
r.SumBackoffTotal += time.Duration(info.TiKVExecDetails.BackoffDuration)
r.SumWriteSQLRespTotal += info.StmtExecDetails.WriteSQLRespDuration
r.SumTidbCPU += info.CPUUsages.TidbCPUTime
r.SumTikvCPU += info.CPUUsages.TikvCPUTime

// Newroks
r.StmtNetworkTrafficSummary.Add(&info.TiKVExecDetails)
// Networks
r.StmtNetworkTrafficSummary.Add(info.TiKVExecDetails)
// RU
r.StmtRUSummary.Add(info.RUDetail)
}
Expand Down Expand Up @@ -691,6 +691,7 @@ func GenerateStmtExecInfo4Test(digest string) *stmtsummary.StmtExecInfo {
KeyspaceID: 1,
ResourceGroupName: "rg1",
RUDetail: util.NewRUDetailsWith(1.2, 3.4, 2*time.Millisecond),
TiKVExecDetails: &util.ExecDetails{},
CPUUsages: ppcpuusage.CPUUsages{TidbCPUTime: time.Duration(20), TikvCPUTime: time.Duration(10000)},
LazyInfo: &mockLazyInfo{},
}
Expand Down