Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix reading benchmark from the wrong directory #2272

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions internal/perf/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const (
k9sUA = "k9s/"
)


var (
// K9sBenchDir directory to store K9s Benchmark files.
K9sBenchDir = filepath.Join(os.TempDir(), fmt.Sprintf("k9s-bench-%s", config.MustK9sUser()))
Expand Down Expand Up @@ -107,15 +106,15 @@ func (b *Benchmark) Canceled() bool {
return b.canceled
}

// Run starts a benchmark,.
// Run starts a benchmark.
func (b *Benchmark) Run(cluster string, done func()) {
log.Debug().Msgf("Running benchmark on cluster %s", cluster)
buff := new(bytes.Buffer)
b.worker.Writer = buff
// this call will block until the benchmark is complete or times out.
b.worker.Run()
b.worker.Stop()
if len(buff.Bytes()) > 0 {
if buff.Len() > 0 {
if err := b.save(cluster, buff); err != nil {
log.Error().Err(err).Msg("Saving Benchmark")
}
Expand All @@ -141,11 +140,7 @@ func (b *Benchmark) save(cluster string, r io.Reader) error {
}
}()

bb, err := io.ReadAll(r)
if err != nil {
return err
}
if _, err := f.Write(bb); err != nil {
if _, err = io.Copy(f, r); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion internal/view/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func fileToSubject(path string) string {
}

func benchDir(cfg *config.Config) string {
return filepath.Join(perf.K9sBenchDir, cfg.K9s.CurrentContextDir())
return filepath.Join(perf.K9sBenchDir, cfg.K9s.CurrentCluster)
}

func readBenchFile(cfg *config.Config, n string) (string, error) {
Expand Down