Skip to content

Commit 7308b1a

Browse files
committed
SQL query at /debug/top/time
1 parent ecc5d34 commit 7308b1a

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

internal/api/handler.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ type (
226226

227227
queryTopDuration struct {
228228
queryArgs
229+
query string
229230
duration time.Duration
230231
protocol int
231232
user string
@@ -2945,7 +2946,7 @@ func loadPoints(ctx context.Context, h *requestHandler, pq *queryBuilder, lod da
29452946
return nil
29462947
}})
29472948
duration := time.Since(start)
2948-
h.reportQueryDuration(duration)
2949+
h.reportQueryDuration(query.body, duration)
29492950
if err != nil {
29502951
return 0, err
29512952
}
@@ -3288,7 +3289,7 @@ func (h *requestHandler) reportQueryMemUsage(rowCount, colCount int) {
32883289
}
32893290
}
32903291

3291-
func (h *requestHandler) reportQueryDuration(d time.Duration) {
3292+
func (h *requestHandler) reportQueryDuration(q string, d time.Duration) {
32923293
if d <= 0 {
32933294
return
32943295
}
@@ -3305,24 +3306,24 @@ func (h *requestHandler) reportQueryDuration(d time.Duration) {
33053306
case 0:
33063307
if len(s) == 0 {
33073308
s = make([]queryTopDuration, 0, maxLen+1)
3308-
s = append(s, h.queryDuration(d))
3309+
s = append(s, h.queryDuration(q, d))
33093310
} else {
33103311
s = append(s[:1], s...)
33113312
if len(s) > maxLen {
33123313
s = s[:maxLen]
33133314
}
3314-
s[0] = h.queryDuration(d)
3315+
s[0] = h.queryDuration(q, d)
33153316
}
33163317
top = true
33173318
case len(s):
33183319
if len(s) < maxLen && s[len(s)-1].expr != h.query.Expr {
3319-
s = append(s, h.queryDuration(d))
3320+
s = append(s, h.queryDuration(q, d))
33203321
top = true
33213322
}
33223323
default:
33233324
if s[i-1].expr != h.query.Expr {
33243325
s = append(s[:i+1], s[i+1:]...)
3325-
s[i] = h.queryDuration(d)
3326+
s[i] = h.queryDuration(q, d)
33263327
top = true
33273328
}
33283329
}
@@ -3348,13 +3349,14 @@ func (h *requestHandler) queryMemUsage(rowCount, colCount, memUsage int) queryTo
33483349
}
33493350
}
33503351

3351-
func (h *requestHandler) queryDuration(d time.Duration) queryTopDuration {
3352+
func (h *requestHandler) queryDuration(q string, d time.Duration) queryTopDuration {
33523353
return queryTopDuration{
33533354
queryArgs: queryArgs{
33543355
expr: h.query.Expr,
33553356
start: h.query.Start,
33563357
end: h.query.End,
33573358
},
3359+
query: q,
33583360
duration: d,
33593361
protocol: h.endpointStat.protocol,
33603362
user: h.endpointStat.user,

internal/api/http_router.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ func DumpQueryTopDuration(r *httpRequestHandler) {
239239
protocol = strconv.Itoa(v.protocol)
240240
}
241241
w.Write([]byte(v.expr))
242+
w.Write([]byte("\n"))
243+
w.Write([]byte(v.query))
242244
w.Write([]byte(fmt.Sprintf(
243245
"\n# duration=%v from=%d to=%d range=%d token=%s proto=%s\n\n",
244246
v.duration, v.start, v.end, v.end-v.start, v.user, protocol)))

0 commit comments

Comments
 (0)