diff --git a/Makefile b/Makefile index 1423d1bfd4017..5e880c2b04cf9 100644 --- a/Makefile +++ b/Makefile @@ -209,6 +209,11 @@ else CGO_ENABLED=1 $(GOBUILD) $(RACE_FLAG) -ldflags '$(LDFLAGS) $(CHECK_FLAG)' -o '$(TARGET)' ./cmd/tidb-server endif +.PHONY: pgo-file +pgo-file: + go tool pprof -proto build/profile/*.proto > default.pgo + @echo "Merge profile files from build/profile folder to produce default.pgo file" + .PHONY: server_debug server_debug: ifeq ($(TARGET), "") diff --git a/Makefile.common b/Makefile.common index 8a59f8a9fe96f..870d2cdc5fa8d 100644 --- a/Makefile.common +++ b/Makefile.common @@ -28,7 +28,9 @@ path_to_add := $(addsuffix /bin,$(subst :,/bin:,$(GOPATH))):$(PWD)/tools/bin export PATH := $(path_to_add):$(PATH) GO := GO111MODULE=on go -BUILD_FLAG := -tags codes +# default.pgo is the tidb cpu profile of TiDB, you can use make pgo-file to merge profile files from build/profile folder to produce default.pgo file. +# default.pgo file needs to be updated frequently to ensure that the PGO optimization is effective. +BUILD_FLAG := -pgo=default.pgo -tags codes GOEXPERIMENT= ifeq ("${ENABLE_FIPS}", "1") BUILD_FLAG = -tags codes,boringcrypto diff --git a/build/profile/bank_profile.proto b/build/profile/bank_profile.proto new file mode 100644 index 0000000000000..a885688f4fea1 Binary files /dev/null and b/build/profile/bank_profile.proto differ diff --git a/build/profile/sysbench_read_only_profile.proto b/build/profile/sysbench_read_only_profile.proto new file mode 100644 index 0000000000000..031d0ac006711 Binary files /dev/null and b/build/profile/sysbench_read_only_profile.proto differ diff --git a/build/profile/tpcc_profile.proto b/build/profile/tpcc_profile.proto new file mode 100644 index 0000000000000..16053f6049c9c Binary files /dev/null and b/build/profile/tpcc_profile.proto differ diff --git a/build/profile/ycsb_workloada_profile.proto b/build/profile/ycsb_workloada_profile.proto new file mode 100644 index 0000000000000..3972a12ecbd6e Binary files /dev/null and b/build/profile/ycsb_workloada_profile.proto differ diff --git a/cmd/pluginpkg/pluginpkg.go b/cmd/pluginpkg/pluginpkg.go index 2f83a75a11ee2..c1f2ec7d9c992 100644 --- a/cmd/pluginpkg/pluginpkg.go +++ b/cmd/pluginpkg/pluginpkg.go @@ -30,8 +30,9 @@ import ( ) var ( - pkgDir string - outDir string + pkgDir string + outDir string + pgoFile string ) const codeTemplate = ` @@ -74,6 +75,7 @@ func PluginManifest() *plugin.Manifest { func init() { flag.StringVar(&pkgDir, "pkg-dir", "", "plugin package folder path") flag.StringVar(&outDir, "out-dir", "", "plugin packaged folder path") + flag.StringVar(&pgoFile, "pgo-file", "default.pgo", "go profile-guided optimization(pgo) file path") flag.Usage = usage } @@ -98,6 +100,11 @@ func main() { log.Printf("unable to resolve absolute representation of output path , %+v\n", err) flag.Usage() } + pgoFile, err := filepath.Abs(pgoFile) + if err != nil { + log.Printf("unable to resolve absolute representation of pgo-file path , %+v\n", err) + flag.Usage() + } var manifest map[string]any _, err = toml.DecodeFile(filepath.Join(pkgDir, "manifest.toml"), &manifest) @@ -142,6 +149,7 @@ func main() { outputFile := filepath.Join(outDir, pluginName+"-"+version+".so") ctx := context.Background() buildCmd := exec.CommandContext(ctx, "go", "build", + "-pgo="+pgoFile, "-tags=codes", "-buildmode=plugin", "-o", outputFile, pkgDir) diff --git a/default.pgo b/default.pgo new file mode 100644 index 0000000000000..5ab24d311ae28 Binary files /dev/null and b/default.pgo differ