sweet: fix redundant runs in pgo benchmarks

This CL fix a bug that duplicates benchmark runs for every configs if
it's under pgo settings. The unnecessary codes are removed.

Change-Id: Ic03294034ace4534802eefa96cc113646d8ed159
Reviewed-on: https://go-review.googlesource.com/c/benchmarks/+/621535
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Junyang Shao <shaojunyang@google.com>
diff --git a/sweet/cmd/sweet/run.go b/sweet/cmd/sweet/run.go
index 92ba5c9..2d222c8 100644
--- a/sweet/cmd/sweet/run.go
+++ b/sweet/cmd/sweet/run.go
@@ -427,31 +427,33 @@
 
 	// Merge all the profiles and add new PGO configs.
 	newConfigs := configs
-	var successfullyMergedBenchmarks []*benchmark
 	for i := range configs {
 		origConfig := configs[i]
 		profileConfig := profileConfigs[i]
 		pgoConfig := origConfig.Copy()
 		pgoConfig.Name += ".pgo"
 		pgoConfig.PGOFiles = make(map[string]string)
+		noMergeError := true
 
 		for _, b := range successfullyExecutedBenchmarks {
 			p, err := mergeCPUProfiles(profileRunCfg.runProfilesDir(b, profileConfig))
 			if err != nil {
 				log.Error(fmt.Errorf("error merging profiles for %s/%s: %w", b.name, profileConfig.Name, err))
+				noMergeError = false
 			} else {
-				successfullyMergedBenchmarks = append(successfullyMergedBenchmarks, b)
 				pgoConfig.PGOFiles[b.name] = p
 			}
 		}
 
-		newConfigs = append(newConfigs, pgoConfig)
+		if noMergeError {
+			newConfigs = append(newConfigs, pgoConfig)
+		}
 	}
 	if len(successfullyExecutedBenchmarks) == 0 {
 		return nil, nil, fmt.Errorf("failed to merge profiles for any benchmarks, see logs for more details")
 	}
 
-	return newConfigs, successfullyMergedBenchmarks, nil
+	return newConfigs, successfullyExecutedBenchmarks, nil
 }
 
 var cpuProfileRe = regexp.MustCompile(`-cpu\.prof$`)