From 2f6219151967b23e461f98c0c9ed4197f1fed2bf Mon Sep 17 00:00:00 2001 From: ti-srebot <66930949+ti-srebot@users.noreply.github.com> Date: Fri, 16 Oct 2020 16:47:20 +0800 Subject: [PATCH] *: add gc duration in metric profile (#20379) (#20480) Signed-off-by: ti-srebot --- executor/inspection_profile.go | 49 +++++++++++++++++++++++++++------- infoschema/metric_table_def.go | 12 ++++----- 2 files changed, 46 insertions(+), 15 deletions(-) diff --git a/executor/inspection_profile.go b/executor/inspection_profile.go index 1768519a70b70..36d78fdac96f8 100644 --- a/executor/inspection_profile.go +++ b/executor/inspection_profile.go @@ -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 } @@ -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" @@ -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 } @@ -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) { @@ -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", @@ -676,6 +700,10 @@ func (pb *profileBuilder) genTiDBQueryTree() *metricNode { }, }, }, + { + table: "tikv_gc_tasks", + label: []string{"task"}, + }, }, }, }, @@ -700,6 +728,9 @@ func (pb *profileBuilder) genTiDBQueryTree() *metricNode { { table: "tidb_owner_handle_syncer", }, + { + table: "tidb_meta_operation", + }, }, }, }, diff --git a/infoschema/metric_table_def.go b/infoschema/metric_table_def.go index 4e09f23bc40f5..a9df46bbded4e 100644 --- a/infoschema/metric_table_def.go +++ b/infoschema/metric_table_def.go @@ -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": { @@ -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": {