@@ -16,14 +16,14 @@ package collector
16
16
17
17
import (
18
18
"context"
19
+ "encoding/hex"
19
20
"runtime/pprof"
20
21
"sync"
21
22
"time"
22
23
23
24
"github.com/google/pprof/profile"
24
25
"github.com/pingcap/tidb/pkg/util"
25
26
"github.com/pingcap/tidb/pkg/util/cpuprofile"
26
- "github.com/pingcap/tidb/pkg/util/hack"
27
27
"github.com/pingcap/tidb/pkg/util/logutil"
28
28
topsqlstate "github.com/pingcap/tidb/pkg/util/topsql/state"
29
29
"go.uber.org/zap"
@@ -193,12 +193,25 @@ func (sp *SQLCPUCollector) parseCPUProfileBySQLLabels(p *profile.Profile) []SQLC
193
193
194
194
func (* SQLCPUCollector ) createSQLStats (sqlMap map [string ]* sqlStats ) []SQLCPUTimeRecord {
195
195
stats := make ([]SQLCPUTimeRecord , 0 , len (sqlMap ))
196
- for sqlDigest , stmt := range sqlMap {
196
+ for hexSQLDigest , stmt := range sqlMap {
197
197
stmt .tune ()
198
- for planDigest , val := range stmt .plans {
198
+
199
+ sqlDigest , err := hex .DecodeString (hexSQLDigest )
200
+ if err != nil {
201
+ logutil .BgLogger ().Error ("decode sql digest failed" , zap .String ("sqlDigest" , hexSQLDigest ), zap .Error (err ))
202
+ continue
203
+ }
204
+
205
+ for hexPlanDigest , val := range stmt .plans {
206
+ planDigest , err := hex .DecodeString (hexPlanDigest )
207
+ if err != nil {
208
+ logutil .BgLogger ().Error ("decode plan digest failed" , zap .String ("planDigest" , hexPlanDigest ), zap .Error (err ))
209
+ continue
210
+ }
211
+
199
212
stats = append (stats , SQLCPUTimeRecord {
200
- SQLDigest : [] byte ( sqlDigest ) ,
201
- PlanDigest : [] byte ( planDigest ) ,
213
+ SQLDigest : sqlDigest ,
214
+ PlanDigest : planDigest ,
202
215
CPUTimeMs : uint32 (time .Duration (val ).Milliseconds ()),
203
216
})
204
217
}
@@ -255,12 +268,12 @@ func (s *sqlStats) tune() {
255
268
}
256
269
257
270
// CtxWithSQLDigest wrap the ctx with sql digest.
258
- func CtxWithSQLDigest (ctx context.Context , sqlDigest [] byte ) context.Context {
259
- return pprof .WithLabels (ctx , pprof .Labels (labelSQLDigest , string ( hack . String ( sqlDigest )) ))
271
+ func CtxWithSQLDigest (ctx context.Context , sqlDigest string ) context.Context {
272
+ return pprof .WithLabels (ctx , pprof .Labels (labelSQLDigest , sqlDigest ))
260
273
}
261
274
262
275
// CtxWithSQLAndPlanDigest wrap the ctx with sql digest and plan digest.
263
- func CtxWithSQLAndPlanDigest (ctx context.Context , sqlDigest , planDigest [] byte ) context.Context {
264
- return pprof .WithLabels (ctx , pprof .Labels (labelSQLDigest , string ( hack . String ( sqlDigest )) ,
265
- labelPlanDigest , string ( hack . String ( planDigest )) ))
276
+ func CtxWithSQLAndPlanDigest (ctx context.Context , sqlDigest , planDigest string ) context.Context {
277
+ return pprof .WithLabels (ctx , pprof .Labels (labelSQLDigest , sqlDigest ,
278
+ labelPlanDigest , planDigest ))
266
279
}
0 commit comments