Skip to content

Commit

Permalink
executor: add metric definition in metric profile (pingcap#19978)
Browse files Browse the repository at this point in the history
Signed-off-by: crazycs520 <[email protected]>
  • Loading branch information
crazycs520 authored Sep 14, 2020
1 parent 2a3a5ab commit b99376b
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions executor/inspection_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strings"
"time"

"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/util/sqlexec"
)
Expand Down Expand Up @@ -57,11 +58,12 @@ type metricNode struct {
}

type metricValue struct {
sum float64
count int
avgP99 float64
avgP90 float64
avgP80 float64
sum float64
count int
avgP99 float64
avgP90 float64
avgP80 float64
comment string
}

type metricValueType int
Expand Down Expand Up @@ -108,7 +110,9 @@ func (m *metricValue) getComment() string {
if m.count == 0 {
return ""
}
buf := bytes.NewBuffer(make([]byte, 0, 32))
buf := bytes.NewBuffer(make([]byte, 0, 64))
buf.WriteString(m.comment)
buf.WriteString("\n\n")
buf.WriteString("total_time: ")
buf.WriteString(time.Duration(int64(m.sum * float64(time.Second))).String())
buf.WriteByte('\n')
Expand Down Expand Up @@ -277,6 +281,15 @@ func (n *metricNode) initializeMetricValue(pb *profileBuilder) error {
}
setQuantileValue(n.value, quantile, totalValue/float64(cnt))
}

// 4. Add metric comment.
def, ok := infoschema.MetricTableMap[n.table+"_total_time"]
if ok {
n.value.comment = def.Comment
for label, value := range n.labelValue {
value.comment = fmt.Sprintf("%s, the label of [%v] is [%v]", def.Comment, strings.Join(n.label, ","), label)
}
}
return nil
}

Expand Down

0 comments on commit b99376b

Please sign in to comment.