|
6 | 6 | package main |
7 | 7 |
|
8 | 8 | import ( |
9 | | - "bytes" |
10 | 9 | "context" |
11 | 10 | "fmt" |
12 | 11 | "log" |
@@ -350,159 +349,54 @@ func (c *compare) compareUsingThreshold(comparisonResultsMap model.ComparisonRes |
350 | 349 | return nil |
351 | 350 | } |
352 | 351 |
|
353 | | -func (c *compare) createBenchSeries() ([]*benchseries.ComparisonSeries, error) { |
354 | | - opts := benchseries.DefaultBuilderOptions() |
355 | | - opts.Experiment = "run-time" |
356 | | - opts.Compare = "cockroach" |
357 | | - builder, err := benchseries.NewBuilder(opts) |
358 | | - if err != nil { |
359 | | - return nil, err |
360 | | - } |
361 | | - |
362 | | - var benchBuf bytes.Buffer |
363 | | - readFileFn := func(filePath string, required bool) error { |
364 | | - data, err := os.ReadFile(filePath) |
365 | | - if err != nil { |
366 | | - if !required && oserror.IsNotExist(err) { |
367 | | - return nil |
368 | | - } |
369 | | - return errors.Wrapf(err, "failed to read file %s", filePath) |
370 | | - } |
371 | | - benchBuf.Write(data) |
372 | | - benchBuf.WriteString("\n") |
373 | | - return nil |
374 | | - } |
375 | | - |
376 | | - for k, v := range c.influxConfig.metadata { |
377 | | - benchBuf.WriteString(fmt.Sprintf("%s: %s\n", k, v)) |
378 | | - } |
379 | | - |
380 | | - logPaths := map[string]string{ |
381 | | - "experiment": c.experimentDir, |
382 | | - "baseline": c.baselineDir, |
383 | | - } |
384 | | - for logType, dir := range logPaths { |
385 | | - benchBuf.WriteString(fmt.Sprintf("cockroach: %s\n", logType)) |
386 | | - logPath := filepath.Join(dir, "metadata.log") |
387 | | - if err = readFileFn(logPath, true); err != nil { |
388 | | - return nil, err |
389 | | - } |
390 | | - for _, pkg := range c.packages { |
391 | | - benchBuf.WriteString(fmt.Sprintf("pkg: %s\n", pkg)) |
392 | | - logPath = filepath.Join(dir, getReportLogName(reportLogName, pkg)) |
393 | | - if err = readFileFn(logPath, false); err != nil { |
394 | | - return nil, err |
395 | | - } |
396 | | - } |
397 | | - } |
398 | | - |
399 | | - benchReader := benchfmt.NewReader(bytes.NewReader(benchBuf.Bytes()), "buffer") |
400 | | - recordsMap := make(map[string][]*benchfmt.Result) |
401 | | - seen := make(map[string]map[string]struct{}) |
402 | | - for benchReader.Scan() { |
403 | | - switch rec := benchReader.Result().(type) { |
404 | | - case *benchfmt.SyntaxError: |
405 | | - // In case the benchmark log is corrupted or contains a syntax error, we |
406 | | - // want to return an error to the caller. |
407 | | - return nil, fmt.Errorf("syntax error: %v", rec) |
408 | | - case *benchfmt.Result: |
409 | | - var cmp, pkg string |
410 | | - for _, config := range rec.Config { |
411 | | - if config.Key == "pkg" { |
412 | | - pkg = string(config.Value) |
413 | | - } |
414 | | - if config.Key == opts.Compare { |
415 | | - cmp = string(config.Value) |
416 | | - } |
417 | | - } |
418 | | - key := pkg + util.PackageSeparator + string(rec.Name) |
419 | | - // Update the name to include the package name. This is a workaround for |
420 | | - // `benchseries`, that currently does not support package names. |
421 | | - rec.Name = benchfmt.Name(key) |
422 | | - recordsMap[key] = append(recordsMap[key], rec.Clone()) |
423 | | - // Determine if we've seen this package/benchmark combination for both |
424 | | - // the baseline and experiment run. |
425 | | - if _, ok := seen[key]; !ok { |
426 | | - seen[key] = make(map[string]struct{}) |
427 | | - } |
428 | | - seen[key][cmp] = struct{}{} |
429 | | - } |
430 | | - } |
431 | | - |
432 | | - // Add only the benchmarks that have been seen in both the baseline and |
433 | | - // experiment run. |
434 | | - for key, records := range recordsMap { |
435 | | - if len(seen[key]) != 2 { |
436 | | - continue |
437 | | - } |
438 | | - for _, rec := range records { |
439 | | - builder.Add(rec) |
440 | | - } |
441 | | - } |
442 | | - |
443 | | - comparisons, err := builder.AllComparisonSeries(nil, benchseries.DUPE_REPLACE) |
444 | | - if err != nil { |
445 | | - return nil, errors.Wrap(err, "failed to create comparison series") |
446 | | - } |
447 | | - return comparisons, nil |
448 | | -} |
449 | | - |
450 | | -func (c *compare) pushToInfluxDB() error { |
| 352 | +func (c *compare) pushToInfluxDB(comparisonResultsMap model.ComparisonResultsMap) error { |
451 | 353 | client := influxdb2.NewClient(c.influxConfig.host, c.influxConfig.token) |
452 | 354 | defer client.Close() |
453 | 355 | writeAPI := client.WriteAPI("cockroach", "microbench") |
454 | 356 | errorChan := writeAPI.Errors() |
455 | 357 |
|
456 | | - comparisons, err := c.createBenchSeries() |
| 358 | + metadata, err := loadMetadata(filepath.Join(c.experimentDir, "metadata.log")) |
457 | 359 | if err != nil { |
458 | 360 | return err |
459 | 361 | } |
| 362 | + experimentTime := metadata.ExperimentCommitTime |
| 363 | + normalizedDateString, err := benchseries.NormalizeDateString(experimentTime) |
| 364 | + if err != nil { |
| 365 | + return errors.Wrap(err, "error normalizing experiment commit date") |
| 366 | + } |
| 367 | + ts, err := benchseries.ParseNormalizedDateString(normalizedDateString) |
| 368 | + if err != nil { |
| 369 | + return errors.Wrap(err, "error parsing experiment commit date") |
| 370 | + } |
460 | 371 |
|
461 | | - for _, cs := range comparisons { |
462 | | - cs.AddSummaries(0.95, 1000) |
463 | | - residues := make(map[string]string) |
464 | | - for _, r := range cs.Residues { |
465 | | - residues[r.S] = r.Slice[0] |
466 | | - } |
467 | | - |
468 | | - for idx, benchmarkName := range cs.Benchmarks { |
469 | | - if len(cs.Summaries) == 0 { |
470 | | - log.Printf("WARN: no summaries for %s", benchmarkName) |
471 | | - continue |
472 | | - } |
473 | | - sum := cs.Summaries[0][idx] |
474 | | - if !sum.Defined() { |
475 | | - continue |
476 | | - } |
477 | | - |
478 | | - experimentTime := cs.Series[0] |
479 | | - ts, err := benchseries.ParseNormalizedDateString(experimentTime) |
480 | | - if err != nil { |
481 | | - return errors.Wrap(err, "error parsing experiment commit date") |
482 | | - } |
483 | | - fields := map[string]interface{}{ |
484 | | - "low": sum.Low, |
485 | | - "center": sum.Center, |
486 | | - "high": sum.High, |
487 | | - "upload-time": residues["upload-time"], |
488 | | - "baseline-commit": cs.HashPairs[experimentTime].DenHash, |
489 | | - "experiment-commit": cs.HashPairs[experimentTime].NumHash, |
490 | | - "benchmarks-commit": residues["benchmarks-commit"], |
491 | | - } |
492 | | - pkg := strings.Split(benchmarkName, util.PackageSeparator)[0] |
493 | | - benchmarkName = strings.Split(benchmarkName, util.PackageSeparator)[1] |
494 | | - tags := map[string]string{ |
495 | | - "name": benchmarkName, |
496 | | - "unit": cs.Unit, |
497 | | - "pkg": pkg, |
498 | | - "repository": "cockroach", |
499 | | - "branch": residues["branch"], |
500 | | - "goarch": residues["goarch"], |
501 | | - "goos": residues["goos"], |
502 | | - "machine-type": residues["machine-type"], |
| 372 | + for _, group := range comparisonResultsMap { |
| 373 | + for _, result := range group { |
| 374 | + for _, detail := range result.Comparisons { |
| 375 | + ci := detail.Comparison.ConfidenceInterval |
| 376 | + fields := map[string]interface{}{ |
| 377 | + "low": ci.Low, |
| 378 | + "center": ci.Center, |
| 379 | + "high": ci.High, |
| 380 | + "upload-time": metadata.RunTime, |
| 381 | + "baseline-commit": metadata.BaselineCommit, |
| 382 | + "experiment-commit": metadata.ExperimentCommit, |
| 383 | + "benchmarks-commit": metadata.BenchmarksCommit, |
| 384 | + } |
| 385 | + pkg := strings.Split(detail.BenchmarkName, util.PackageSeparator)[0] |
| 386 | + benchmarkName := strings.Split(detail.BenchmarkName, util.PackageSeparator)[1] |
| 387 | + tags := map[string]string{ |
| 388 | + "name": benchmarkName, |
| 389 | + "unit": result.Metric.Unit, |
| 390 | + "pkg": pkg, |
| 391 | + "repository": "cockroach", |
| 392 | + "branch": "master", |
| 393 | + "goarch": metadata.GoArch, |
| 394 | + "goos": metadata.GoOS, |
| 395 | + "machine-type": metadata.Machine, |
| 396 | + } |
| 397 | + p := influxdb2.NewPoint("benchmark-result", tags, fields, ts) |
| 398 | + writeAPI.WritePoint(p) |
503 | 399 | } |
504 | | - p := influxdb2.NewPoint("benchmark-result", tags, fields, ts) |
505 | | - writeAPI.WritePoint(p) |
506 | 400 | } |
507 | 401 | } |
508 | 402 | done := make(chan struct{}) |
|
0 commit comments