Skip to content

Commit

Permalink
*: add gc duration in metric profile (#20379) (#20480)
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
ti-srebot authored Oct 16, 2020
1 parent 8968d39 commit 2f62191
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 15 deletions.
49 changes: 40 additions & 9 deletions executor/inspection_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,16 @@ func NewProfileBuilder(sctx sessionctx.Context, start, end time.Time, tp string)

// Collect uses to collect the related metric information.
func (pb *profileBuilder) Collect() error {
pb.buf.WriteString(fmt.Sprintf(`digraph "%s" {`, "tidb_profile"))
pb.buf.WriteByte('\n')
pb.buf.WriteString(`node [style=filled fillcolor="#f8f8f8"]`)
pb.buf.WriteByte('\n')
err := pb.addMetricTree(pb.genTiDBQueryTree(), "tidb_query")
tidbQuery := pb.genTiDBQueryTree()
err := pb.init(tidbQuery, "tidb_query")
if err != nil {
return err
}
err = pb.traversal(tidbQuery)
if err != nil {
return err
}
err = pb.traversal(pb.genTiDBGCTree())
if err != nil {
return err
}
Expand All @@ -337,8 +342,8 @@ func (pb *profileBuilder) getNameID(name string) uint64 {
return id
}

func (pb *profileBuilder) addMetricTree(root *metricNode, name string) error {
if root == nil {
func (pb *profileBuilder) init(total *metricNode, name string) error {
if total == nil {
return nil
}
tp := "total_time"
Expand All @@ -348,9 +353,13 @@ func (pb *profileBuilder) addMetricTree(root *metricNode, name string) error {
case metricValueCnt:
tp = "total_count"
}
pb.buf.WriteString(fmt.Sprintf(`digraph "%s" {`, "tidb_profile"))
pb.buf.WriteByte('\n')
pb.buf.WriteString(`node [style=filled fillcolor="#f8f8f8"]`)
pb.buf.WriteByte('\n')
pb.buf.WriteString(fmt.Sprintf(`subgraph %[1]s { "%[1]s" [shape=box fontsize=16 label="Type: %[1]s\lTime: %s\lDuration: %s\l"] }`, name+"_"+tp, pb.start.String(), pb.end.Sub(pb.start).String()))
pb.buf.WriteByte('\n')
v, err := pb.GetTotalValue(root)
v, err := pb.GetTotalValue(total)
if err != nil {
return err
}
Expand All @@ -359,7 +368,7 @@ func (pb *profileBuilder) addMetricTree(root *metricNode, name string) error {
} else {
pb.totalValue = 1
}
return pb.traversal(root)
return nil
}

func (pb *profileBuilder) GetTotalValue(root *metricNode) (float64, error) {
Expand Down Expand Up @@ -609,6 +618,21 @@ func (pb *profileBuilder) dotColor(score float64, isBackground bool) string {
return fmt.Sprintf("#%02x%02x%02x", uint8(r*255.0), uint8(g*255.0), uint8(b*255.0))
}

func (pb *profileBuilder) genTiDBGCTree() *metricNode {
tidbGC := &metricNode{
table: "tidb_gc",
isPartOfParent: true,
label: []string{"stage"},
children: []*metricNode{
{
table: "tidb_kv_request",
isPartOfParent: true,
},
},
}
return tidbGC
}

func (pb *profileBuilder) genTiDBQueryTree() *metricNode {
tidbKVRequest := &metricNode{
table: "tidb_kv_request",
Expand Down Expand Up @@ -676,6 +700,10 @@ func (pb *profileBuilder) genTiDBQueryTree() *metricNode {
},
},
},
{
table: "tikv_gc_tasks",
label: []string{"task"},
},
},
},
},
Expand All @@ -700,6 +728,9 @@ func (pb *profileBuilder) genTiDBQueryTree() *metricNode {
{
table: "tidb_owner_handle_syncer",
},
{
table: "tidb_meta_operation",
},
},
},
},
Expand Down
12 changes: 6 additions & 6 deletions infoschema/metric_table_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,8 @@ var MetricTableMap = map[string]MetricTableDef{
},
"tidb_gc_duration": {
Comment: "The quantile of kv storage garbage collection time durations",
PromQL: "histogram_quantile($QUANTILE, sum(rate(tidb_tikvclient_gc_seconds_bucket{$LABEL_CONDITIONS}[$RANGE_DURATION])) by (le,instance))",
Labels: []string{"instance"},
PromQL: "histogram_quantile($QUANTILE, sum(rate(tidb_tikvclient_gc_seconds_bucket{$LABEL_CONDITIONS}[$RANGE_DURATION])) by (le,instance,stage))",
Labels: []string{"instance", "stage"},
Quantile: 0.95,
},
"tidb_gc_config": {
Expand Down Expand Up @@ -2522,13 +2522,13 @@ var MetricTableMap = map[string]MetricTableDef{
Comment: "The total time of kv storage range worker processing one task duration",
},
"tidb_gc_total_count": {
PromQL: "sum(increase(tidb_tikvclient_gc_seconds_count{$LABEL_CONDITIONS}[$RANGE_DURATION])) by (instance)",
Labels: []string{"instance"},
PromQL: "sum(increase(tidb_tikvclient_gc_seconds_count{$LABEL_CONDITIONS}[$RANGE_DURATION])) by (instance,stage)",
Labels: []string{"instance", "stage"},
Comment: "The total count of kv storage garbage collection",
},
"tidb_gc_total_time": {
PromQL: "sum(increase(tidb_tikvclient_gc_seconds_sum{$LABEL_CONDITIONS}[$RANGE_DURATION])) by (instance)",
Labels: []string{"instance"},
PromQL: "sum(increase(tidb_tikvclient_gc_seconds_sum{$LABEL_CONDITIONS}[$RANGE_DURATION])) by (instance,stage)",
Labels: []string{"instance", "stage"},
Comment: "The total time of kv storage garbage collection time durations",
},
"tidb_get_token_total_count": {
Expand Down

0 comments on commit 2f62191

Please sign in to comment.