Skip to content

Commit

Permalink
Merge pull request pingcap#18 from lonng/hackthon
Browse files Browse the repository at this point in the history
add performance_schema.events_tikv_cpu_profile virtual table
  • Loading branch information
qiuyesuifeng authored Oct 22, 2019
2 parents 23e9194 + bad2f01 commit 56a4231
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions infoschema/perfschema/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var perfSchemaTables = []string{
tableAllocsProfile,
tableBlockProfile,
tableGoroutine,
tableTiKVCpuProfile,
}

// tableGlobalStatus contains the column name definitions for table global_status, same as MySQL.
Expand Down Expand Up @@ -444,3 +445,10 @@ const tableGoroutine = "CREATE TABLE IF NOT EXISTS " + tableNameGoroutines + " (
"ID INT(8) NOT NULL," +
"STATE VARCHAR(16) NOT NULL," +
"LOCATION VARCHAR(512));"

const tableTiKVCpuProfile = "CREATE TABLE IF NOT EXISTS " + tableNameTiKVCpuProfile + " (" +
"FUNCTION VARCHAR(512) NOT NULL," +
"PERCENT_ABS VARCHAR(8) NOT NULL," +
"PERCENT_REL VARCHAR(8) NOT NULL," +
"DEPTH INT(8) NOT NULL," +
"FILE VARCHAR(512) NOT NULL);"
11 changes: 11 additions & 0 deletions infoschema/perfschema/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"bytes"
"fmt"
"io"
"net/http"
"runtime/pprof"
"strconv"
"strings"
Expand Down Expand Up @@ -198,6 +199,16 @@ func cpuProfileGraph() ([][]types.Datum, error) {
return profileReaderToDatums(buffer)
}

// TODO: use cluster info to get all tikv profile
func tikvCpuProfileGraph() ([][]types.Datum, error) {
resp, err := http.Get("http://127.0.0.1:49904/pprof/cpu?seconds=20")
if err != nil {
return nil, err
}
defer resp.Body.Close()
return profileReaderToDatums(resp.Body)
}

func profileGraph(name string) ([][]types.Datum, error) {
p := pprof.Lookup(name)
if p == nil {
Expand Down
3 changes: 3 additions & 0 deletions infoschema/perfschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const (
tableNameAllocsProfile = "events_allocs_profile"
tableNameBlockProfile = "events_block_profile"
tableNameGoroutines = "events_goroutines"
tableNameTiKVCpuProfile = "events_tikv_cpu_profile"
)

// perfSchemaTable stands for the fake table all its data is in the memory.
Expand Down Expand Up @@ -108,6 +109,8 @@ func (vt *perfSchemaTable) getRows(ctx sessionctx.Context, cols []*table.Column)
fullRows, err = profileGraph("block")
case tableNameGoroutines:
fullRows, err = goroutinesList()
case tableNameTiKVCpuProfile:
fullRows, err = tikvCpuProfileGraph()
}
if err != nil {
return
Expand Down

0 comments on commit 56a4231

Please sign in to comment.