Skip to content

Commit

Permalink
/go/performance/utils/sysbench_runner/profile.go: seems to work
Browse files Browse the repository at this point in the history
  • Loading branch information
coffeegoddd committed Feb 7, 2024
1 parent 34ad972 commit 3906451
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions go/performance/utils/sysbench_runner/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,27 @@ func ProfileDolt(ctx context.Context, config *Config, serverConfig *ServerConfig
return err
}

tempProfilesDir, err := os.MkdirTemp("", "")
if err != nil {
return err
}
defer os.RemoveAll(tempProfilesDir)

for i := 0; i < config.Runs; i++ {
for _, test := range tests {
profile, err := profileTest(ctx, test, config, serverConfig, serverParams, testRepo, serverConfig.ProfilePath)
_, err = profileTest(ctx, test, config, serverConfig, serverParams, testRepo, tempProfilesDir)
if err != nil {
return err
}
fmt.Println("DUSTIN: created profile:", profile)
}
}

// todo: merge profiles together
profile, err := mergeProfiles(ctx, tempProfilesDir, serverConfig.ProfilePath)
if err != nil {
return err
}

fmt.Println("Profile created at:", profile)

err = os.RemoveAll(testRepo)
if err != nil {
Expand All @@ -80,6 +90,7 @@ func profileTest(ctx context.Context, test *Test, config *Config, serverConfig *
if err != nil {
return "", err
}
defer os.RemoveAll(profilePath)

tempProfile := filepath.Join(profilePath, cpuProfileFilename)
profileParams := make([]string, 0)
Expand All @@ -105,8 +116,6 @@ func profileTest(ctx context.Context, test *Test, config *Config, serverConfig *

// launch the dolt server
gServer.Go(func() error {
server.Stdout = os.Stdout
server.Stderr = os.Stderr
return server.Run()
})

Expand All @@ -121,15 +130,13 @@ func profileTest(ctx context.Context, test *Test, config *Config, serverConfig *
}

// send signal to dolt server
// must be interrupt signal to complete profile
quit <- syscall.SIGINT

err = gServer.Wait()
if err != nil {
// we expect a kill error
// we only exit in error if this is not the
// error
fmt.Println("DUSTIN: wait error:", err.Error())
if err.Error() != "signal: killed" {
fmt.Println(err)
close(quit)
Expand All @@ -155,6 +162,26 @@ func profileTest(ctx context.Context, test *Test, config *Config, serverConfig *
return finalProfile, err
}

func mergeProfiles(ctx context.Context, sourceProfilesDir, destProfileDir string) (string, error) {
tmp, err := os.MkdirTemp("", "final_cpu_pprof")
if err != nil {
return "", err
}
defer os.RemoveAll(tmp)
outfile := filepath.Join(tmp, "cpu.pprof")

merge := ExecCommand(ctx, "/bin/sh", "-c", fmt.Sprintf("go tool pprof -proto *.pprof > %s", outfile))
merge.Dir = sourceProfilesDir
err = merge.Run()
if err != nil {
return "", err
}

final := filepath.Join(destProfileDir, "cpu.pprof")
err = moveFile(outfile, final)
return final, err
}

func moveFile(sourcePath, destPath string) error {
err := copyFile(sourcePath, destPath)
if err != nil {
Expand Down

0 comments on commit 3906451

Please sign in to comment.