Skip to content

Commit

Permalink
perfschema: add root child id column for profile tables (pingcap#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
lonng authored and qiuyesuifeng committed Oct 26, 2019
1 parent 6f4fe8c commit f96e243
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
6 changes: 6 additions & 0 deletions infoschema/perfschema/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ const tableCpuProfile = "CREATE TABLE IF NOT EXISTS " + tableNameCpuProfile + "
"FUNCTION VARCHAR(512) NOT NULL," +
"PERCENT_ABS VARCHAR(8) NOT NULL," +
"PERCENT_REL VARCHAR(8) NOT NULL," +
"ROOT_CHILD INT(8) NOT NULL," +
"DEPTH INT(8) NOT NULL," +
"FILE VARCHAR(512) NOT NULL);"

Expand All @@ -412,6 +413,7 @@ const tableMemoryProfile = "CREATE TABLE IF NOT EXISTS " + tableNameMemoryProfil
"FUNCTION VARCHAR(512) NOT NULL," +
"PERCENT_ABS VARCHAR(8) NOT NULL," +
"PERCENT_REL VARCHAR(8) NOT NULL," +
"ROOT_CHILD INT(8) NOT NULL," +
"DEPTH INT(8) NOT NULL," +
"FILE VARCHAR(512) NOT NULL);"

Expand All @@ -420,6 +422,7 @@ const tableMutexProfile = "CREATE TABLE IF NOT EXISTS " + tableNameMutexProfile
"FUNCTION VARCHAR(512) NOT NULL," +
"PERCENT_ABS VARCHAR(8) NOT NULL," +
"PERCENT_REL VARCHAR(8) NOT NULL," +
"ROOT_CHILD INT(8) NOT NULL," +
"DEPTH INT(8) NOT NULL," +
"FILE VARCHAR(512) NOT NULL);"

Expand All @@ -428,6 +431,7 @@ const tableAllocsProfile = "CREATE TABLE IF NOT EXISTS " + tableNameAllocsProfil
"FUNCTION VARCHAR(512) NOT NULL," +
"PERCENT_ABS VARCHAR(8) NOT NULL," +
"PERCENT_REL VARCHAR(8) NOT NULL," +
"ROOT_CHILD INT(8) NOT NULL," +
"DEPTH INT(8) NOT NULL," +
"FILE VARCHAR(512) NOT NULL);"

Expand All @@ -436,6 +440,7 @@ const tableBlockProfile = "CREATE TABLE IF NOT EXISTS " + tableNameBlockProfile
"FUNCTION VARCHAR(512) NOT NULL," +
"PERCENT_ABS VARCHAR(8) NOT NULL," +
"PERCENT_REL VARCHAR(8) NOT NULL," +
"ROOT_CHILD INT(8) NOT NULL," +
"DEPTH INT(8) NOT NULL," +
"FILE VARCHAR(512) NOT NULL);"

Expand All @@ -452,5 +457,6 @@ const tableTiKVCpuProfile = "CREATE TABLE IF NOT EXISTS " + tableNameTiKVCpuProf
"FUNCTION VARCHAR(512) NOT NULL," +
"PERCENT_ABS VARCHAR(8) NOT NULL," +
"PERCENT_REL VARCHAR(8) NOT NULL," +
"ROOT_CHILD INT(8) NOT NULL," +
"DEPTH INT(8) NOT NULL," +
"FILE VARCHAR(512) NOT NULL);"
36 changes: 22 additions & 14 deletions infoschema/perfschema/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,24 @@ type profileGraphCollector struct {
Rows [][]types.Datum
}

func (c *profileGraphCollector) collect(node *Node, depth int64, indent string, parentCur int64, isLastChild bool) {
row := []types.Datum{
types.NewStringDatum(prettyIdentifier(node.Name, indent, isLastChild)),
types.NewStringDatum(node.Percent),
types.NewStringDatum(strings.TrimSpace(measurement.Percentage(node.Cum, parentCur))),
types.NewIntDatum(depth),
types.NewStringDatum(node.Location),
}
func (c *profileGraphCollector) collect(node *Node, depth int64, indent string, rootChild int, parentCur int64, isLastChild bool) {
row := types.MakeDatums(
prettyIdentifier(node.Name, indent, isLastChild),
node.Percent,
strings.TrimSpace(measurement.Percentage(node.Cum, parentCur)),
rootChild,
depth,
node.Location,
)
c.Rows = append(c.Rows, row)

indent4Child := getIndent4Child(indent, isLastChild)
for i, child := range node.Children {
c.collect(child, depth+1, indent4Child, node.Cum, i == len(node.Children)-1)
rc := rootChild
if depth == 0 {
rc = i + 1
}
c.collect(child, depth+1, indent4Child, rc, node.Cum, i == len(node.Children)-1)
}
}

Expand Down Expand Up @@ -188,7 +193,7 @@ func profileToDatums(p *profile.Profile) ([][]types.Datum, error) {
}

c := profileGraphCollector{}
c.collect(rootNode, 0, "", config.Total, len(rootNode.Children) == 0)
c.collect(rootNode, 0, "", 0, config.Total, len(rootNode.Children) == 0)
return c.Rows, nil
}

Expand All @@ -210,7 +215,10 @@ func tikvCpuProfileGraph(ctx sessionctx.Context) ([][]types.Datum, error) {
return nil, err
}

type result struct{rows [][]types.Datum; err error}
type result struct {
rows [][]types.Datum
err error
}

var finalRows [][]types.Datum
wg := sync.WaitGroup{}
Expand All @@ -225,12 +233,12 @@ func tikvCpuProfileGraph(ctx sessionctx.Context) ([][]types.Datum, error) {
}

wg.Add(1)
go func () {
go func() {
defer wg.Done()
resp, err := http.Get(fmt.Sprintf("http://%s/pprof/cpu?seconds=20", statusAddr))
resp, err := http.Get(fmt.Sprintf("http://%s/pprof/cpu?seconds=20", statusAddr))
if err != nil {
ch <- result{err: err}
return
return
}
defer resp.Body.Close()
rows, err := profileReaderToDatums(resp.Body)
Expand Down

0 comments on commit f96e243

Please sign in to comment.