Skip to content

Commit 0f6621d

Browse files
qw4990jackysp
authored andcommitted
session: Adjust cop-tasks' information in slow log to let it can be parsed by pt-query correctly (#10230) (#10300)
1 parent b51f531 commit 0f6621d

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

sessionctx/variable/session.go

+20-10
Original file line numberDiff line numberDiff line change
@@ -786,10 +786,18 @@ const (
786786
SlowLogStatsInfoStr = "Stats"
787787
// SlowLogNumCopTasksStr is the number of cop-tasks.
788788
SlowLogNumCopTasksStr = "Num_cop_tasks"
789-
// SlowLogCopProcessStr includes some useful information about cop-tasks' process time.
790-
SlowLogCopProcessStr = "Cop_process"
791-
// SlowLogCopWaitStr includes some useful information about cop-tasks' wait time.
792-
SlowLogCopWaitStr = "Cop_wait"
789+
// SlowLogCopProcAvg is the average process time of all cop-tasks.
790+
SlowLogCopProcAvg = "Cop_proc_avg"
791+
// SlowLogCopProcP90 is the p90 process time of all cop-tasks.
792+
SlowLogCopProcP90 = "Cop_proc_p90"
793+
// SlowLogCopProcMax is the max process time of all cop-tasks.
794+
SlowLogCopProcMax = "Cop_proc_max"
795+
// SlowLogCopWaitAvg is the average wait time of all cop-tasks.
796+
SlowLogCopWaitAvg = "Cop_wait_avg"
797+
// SlowLogCopWaitP90 is the p90 wait time of all cop-tasks.
798+
SlowLogCopWaitP90 = "Cop_wait_p90"
799+
// SlowLogCopWaitMax is the max wait time of all cop-tasks.
800+
SlowLogCopWaitMax = "Cop_wait_max"
793801
// SlowLogMemMax is the max number bytes of memory used in this statement.
794802
SlowLogMemMax = "Mem_max"
795803
)
@@ -859,12 +867,14 @@ func (s *SessionVars) SlowLogFormat(txnTS uint64, costTime time.Duration, execDe
859867
}
860868
if copTasks != nil {
861869
buf.WriteString(SlowLogPrefixStr + SlowLogNumCopTasksStr + SlowLogSpaceMarkStr + strconv.FormatInt(int64(copTasks.NumCopTasks), 10) + "\n")
862-
buf.WriteString(SlowLogPrefixStr + SlowLogCopProcessStr + SlowLogSpaceMarkStr +
863-
fmt.Sprintf("Avg_time: %v P90_time: %v Max_time: %v", copTasks.AvgProcessTime,
864-
copTasks.P90ProcessTime, copTasks.MaxProcessTime) + "\n")
865-
buf.WriteString(SlowLogPrefixStr + SlowLogCopWaitStr + SlowLogSpaceMarkStr +
866-
fmt.Sprintf("Avg_time: %v P90_time: %v Max_time: %v", copTasks.AvgWaitTime,
867-
copTasks.P90WaitTime, copTasks.MaxWaitTime) + "\n")
870+
buf.WriteString(SlowLogPrefixStr + fmt.Sprintf("%v%v%v %v%v%v %v%v%v",
871+
SlowLogCopProcAvg, SlowLogSpaceMarkStr, copTasks.AvgProcessTime.Seconds(),
872+
SlowLogCopProcP90, SlowLogSpaceMarkStr, copTasks.P90ProcessTime.Seconds(),
873+
SlowLogCopProcMax, SlowLogSpaceMarkStr, copTasks.MaxProcessTime.Seconds()) + "\n")
874+
buf.WriteString(SlowLogPrefixStr + fmt.Sprintf("%v%v%v %v%v%v %v%v%v",
875+
SlowLogCopWaitAvg, SlowLogSpaceMarkStr, copTasks.AvgWaitTime.Seconds(),
876+
SlowLogCopWaitP90, SlowLogSpaceMarkStr, copTasks.P90WaitTime.Seconds(),
877+
SlowLogCopWaitMax, SlowLogSpaceMarkStr, copTasks.MaxWaitTime.Seconds()) + "\n")
868878
}
869879
if memMax > 0 {
870880
buf.WriteString(SlowLogPrefixStr + SlowLogMemMax + SlowLogSpaceMarkStr + strconv.FormatInt(memMax, 10) + "\n")

sessionctx/variable/session_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ func (*testSessionSuite) TestSlowLogFormat(c *C) {
100100
# Digest: 42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772
101101
# Stats: t1:pseudo
102102
# Num_cop_tasks: 10
103-
# Cop_process: Avg_time: 1s P90_time: 2s Max_time: 3s
104-
# Cop_wait: Avg_time: 10ms P90_time: 20ms Max_time: 30ms
103+
# Cop_proc_avg: 1 Cop_proc_p90: 2 Cop_proc_max: 3
104+
# Cop_wait_avg: 0.01 Cop_wait_p90: 0.02 Cop_wait_max: 0.03
105105
# Mem_max: 2333
106106
select * from t;`
107107
sql := "select * from t"

0 commit comments

Comments
 (0)