Skip to content

Commit

Permalink
Merge pull request #7505 from dolthub/db/builder-pgo
Browse files Browse the repository at this point in the history
[no-release-notes] /go/performance/utils/dolt_builder: allow profile builds
  • Loading branch information
coffeegoddd authored Feb 15, 2024
2 parents 6464c3e + 20ab5d0 commit abbe4a7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
15 changes: 13 additions & 2 deletions go/performance/utils/dolt_builder/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,39 @@ package main

import (
"context"
"flag"
"fmt"
"log"
"os"

builder "github.com/dolthub/dolt/go/performance/utils/dolt_builder"
)

var profile = flag.String("profile", "", "path to profile used during build")

func main() {
flag.Parse()
commitList := os.Args[1:]
if *profile != "" {
commitList = commitList[2:]
}
if len(commitList) < 1 {
helpStr := "dolt-builder takes Dolt commit shas or tags as arguments\n" +
"and builds corresponding binaries to a path specified\n" +
"by DOLT_BIN\n" +
"If DOLT_BIN is not set, ./doltBin will be used\n" +
"usage: dolt-builder dccba46 4bad226 ...\n" +
"usage: dolt-builder v0.19.0 v0.22.6 ...\n" +
"set DEBUG=1 to run in debug mode\n"
"set DEBUG=1 to run in debug mode\n" +
"use the -profile flag to supply a pprof profile\n" +
"which will be used to create a PGO build\n" +
"usage: dolt-builder -profile /path/to/profile v1.33.0\n" +
"only one version may be specified when supplying a profile\n"
fmt.Print(helpStr)
os.Exit(2)
}

err := builder.Run(context.Background(), commitList)
err := builder.Run(context.Background(), commitList, *profile)
if err != nil {
log.Fatal(err)
}
Expand Down
27 changes: 21 additions & 6 deletions go/performance/utils/dolt_builder/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package dolt_builder

import (
"context"
"errors"
"fmt"
"os"
"os/signal"
Expand All @@ -29,7 +30,11 @@ import (

const envDoltBin = "DOLT_BIN"

func Run(parentCtx context.Context, commitList []string) error {
func Run(parentCtx context.Context, commitList []string, profilePath string) error {
if profilePath != "" && len(commitList) > 1 {
return errors.New("cannot build more that one binary when a profile is supplied")
}

doltBin, err := getDoltBin()
if err != nil {
return err
Expand Down Expand Up @@ -79,7 +84,7 @@ func Run(parentCtx context.Context, commitList []string) error {
for _, commit := range commitList {
commit := commit // https://golang.org/doc/faq#closures_and_goroutines
g.Go(func() error {
return buildBinaries(ctx, tempDir, repoDir, doltBin, commit)
return buildBinaries(ctx, tempDir, repoDir, doltBin, profilePath, commit)
})
}

Expand Down Expand Up @@ -128,7 +133,7 @@ func getDoltBin() (string, error) {
}

// buildBinaries builds a dolt binary at the given commit and stores it in the doltBin
func buildBinaries(ctx context.Context, tempDir, repoDir, doltBinDir, commit string) error {
func buildBinaries(ctx context.Context, tempDir, repoDir, doltBinDir, profilePath, commit string) error {
checkoutDir := filepath.Join(tempDir, commit)
if err := os.MkdirAll(checkoutDir, os.ModePerm); err != nil {
return err
Expand All @@ -144,7 +149,7 @@ func buildBinaries(ctx context.Context, tempDir, repoDir, doltBinDir, commit str
return err
}

command, err := goBuild(ctx, checkoutDir, commitDir)
command, err := goBuild(ctx, checkoutDir, commitDir, profilePath)
if err != nil {
return err
}
Expand All @@ -153,14 +158,24 @@ func buildBinaries(ctx context.Context, tempDir, repoDir, doltBinDir, commit str
}

// goBuild builds the dolt binary and returns the filename
func goBuild(ctx context.Context, source, dest string) (string, error) {
func goBuild(ctx context.Context, source, dest, profilePath string) (string, error) {
goDir := filepath.Join(source, "go")
doltFileName := "dolt"
if runtime.GOOS == "windows" {
doltFileName = "dolt.exe"
}

args := make([]string, 0)
args = append(args, "build")

if profilePath != "" {
args = append(args, fmt.Sprintf("-pgo=%s", profilePath))
}

toBuild := filepath.Join(dest, doltFileName)
build := ExecCommand(ctx, "go", "build", "-o", toBuild, filepath.Join(goDir, "cmd", "dolt"))
args = append(args, "-o", toBuild, filepath.Join(goDir, "cmd", "dolt"))

build := ExecCommand(ctx, "go", args...)
build.Dir = goDir
err := build.Run()
if err != nil {
Expand Down

0 comments on commit abbe4a7

Please sign in to comment.