-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
126810: roachprod-microbench: add clean command r=herkolategan a=sambhav-jain-16 Epic: none Release note: None This change adds a new utility command to `roachprod-microbench` as part of fixing #106661. Co-authored-by: Sambhav Jain <[email protected]>
- Loading branch information
Showing
3 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright 2024 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/cockroachdb/errors" | ||
) | ||
|
||
type cleanConfig struct { | ||
inputFilePath string | ||
outputFilePath string | ||
} | ||
|
||
type clean struct { | ||
cleanConfig | ||
inputFile *os.File | ||
} | ||
|
||
func defaultCleanConfig() cleanConfig { | ||
return cleanConfig{ | ||
inputFilePath: "", | ||
outputFilePath: "", | ||
} | ||
} | ||
|
||
func newClean(config cleanConfig) (*clean, error) { | ||
file, err := os.Open(config.inputFilePath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &clean{cleanConfig: config, inputFile: file}, nil | ||
} | ||
|
||
func (c *clean) writeCleanOutputToFile(cleanedBenchmarkOutputLog benchmarkExtractionResult) error { | ||
|
||
if err := os.MkdirAll(filepath.Dir(c.outputFilePath), os.ModePerm); err != nil { | ||
return err | ||
} | ||
|
||
outputFile, err := os.Create(c.outputFilePath) | ||
if err != nil { | ||
return err | ||
} | ||
defer outputFile.Close() | ||
|
||
for _, benchmarkResult := range cleanedBenchmarkOutputLog.results { | ||
if _, writeErr := outputFile.WriteString( | ||
fmt.Sprintf("%s\n", strings.Join(benchmarkResult, " "))); writeErr != nil { | ||
return errors.Wrap(writeErr, "failed to write benchmark result to file") | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *clean) cleanBenchmarkOutputLog() error { | ||
defer c.inputFile.Close() | ||
|
||
rawBenchmarkLogs, err := io.ReadAll(c.inputFile) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cleanedBenchmarkOutputLog := extractBenchmarkResults(string(rawBenchmarkLogs)) | ||
if err = c.writeCleanOutputToFile(cleanedBenchmarkOutputLog); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters