From bad2f01dde52d31e0be3ac541d4e5481a353c244 Mon Sep 17 00:00:00 2001 From: Lonng Date: Tue, 22 Oct 2019 10:49:26 +0800 Subject: [PATCH] add performance_schema.events_tikv_cpu_profile virtual table Signed-off-by: Lonng --- infoschema/perfschema/const.go | 8 ++++++++ infoschema/perfschema/profile.go | 11 +++++++++++ infoschema/perfschema/tables.go | 3 +++ 3 files changed, 22 insertions(+) diff --git a/infoschema/perfschema/const.go b/infoschema/perfschema/const.go index 0fedc4ea38115..4c4a3335cf1d4 100644 --- a/infoschema/perfschema/const.go +++ b/infoschema/perfschema/const.go @@ -46,6 +46,7 @@ var perfSchemaTables = []string{ tableAllocsProfile, tableBlockProfile, tableGoroutine, + tableTiKVCpuProfile, } // tableGlobalStatus contains the column name definitions for table global_status, same as MySQL. @@ -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);" \ No newline at end of file diff --git a/infoschema/perfschema/profile.go b/infoschema/perfschema/profile.go index b5e8aa2cf0b4e..5f840366059c5 100644 --- a/infoschema/perfschema/profile.go +++ b/infoschema/perfschema/profile.go @@ -17,6 +17,7 @@ import ( "bytes" "fmt" "io" + "net/http" "runtime/pprof" "strconv" "strings" @@ -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 { diff --git a/infoschema/perfschema/tables.go b/infoschema/perfschema/tables.go index bda9bf9ced3b9..5dc0503873f7b 100644 --- a/infoschema/perfschema/tables.go +++ b/infoschema/perfschema/tables.go @@ -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. @@ -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