(b *testing.B)
| 422 | } |
| 423 | |
| 424 | func BenchmarkOTLP(b *testing.B) { |
| 425 | start := time.Date(2000, 1, 2, 3, 4, 5, 0, time.UTC) |
| 426 | |
| 427 | type Type struct { |
| 428 | name string |
| 429 | data func(mode pmetric.AggregationTemporality, dpc, epoch int) []pmetric.Metric |
| 430 | } |
| 431 | types := []Type{{ |
| 432 | name: "sum", |
| 433 | data: func() func(mode pmetric.AggregationTemporality, dpc, epoch int) []pmetric.Metric { |
| 434 | cumul := make(map[int]float64) |
| 435 | return func(mode pmetric.AggregationTemporality, dpc, epoch int) []pmetric.Metric { |
| 436 | m := pmetric.NewMetric() |
| 437 | sum := m.SetEmptySum() |
| 438 | sum.SetAggregationTemporality(mode) |
| 439 | dps := sum.DataPoints() |
| 440 | for id := range dpc { |
| 441 | dp := dps.AppendEmpty() |
| 442 | dp.SetStartTimestamp(pcommon.NewTimestampFromTime(start)) |
| 443 | dp.SetTimestamp(pcommon.NewTimestampFromTime(start.Add(time.Duration(epoch) * time.Minute))) |
| 444 | dp.Attributes().PutStr("id", strconv.Itoa(id)) |
| 445 | v := float64(rand.IntN(100)) / 10 |
| 446 | switch mode { |
| 447 | case pmetric.AggregationTemporalityDelta: |
| 448 | dp.SetDoubleValue(v) |
| 449 | case pmetric.AggregationTemporalityCumulative: |
| 450 | cumul[id] += v |
| 451 | dp.SetDoubleValue(cumul[id]) |
| 452 | } |
| 453 | } |
| 454 | return []pmetric.Metric{m} |
| 455 | } |
| 456 | }(), |
| 457 | }, { |
| 458 | name: "histogram", |
| 459 | data: func() func(mode pmetric.AggregationTemporality, dpc, epoch int) []pmetric.Metric { |
| 460 | bounds := [4]float64{1, 10, 100, 1000} |
| 461 | type state struct { |
| 462 | counts [4]uint64 |
| 463 | count uint64 |
| 464 | sum float64 |
| 465 | } |
| 466 | var cumul []state |
| 467 | return func(mode pmetric.AggregationTemporality, dpc, epoch int) []pmetric.Metric { |
| 468 | if cumul == nil { |
| 469 | cumul = make([]state, dpc) |
| 470 | } |
| 471 | m := pmetric.NewMetric() |
| 472 | hist := m.SetEmptyHistogram() |
| 473 | hist.SetAggregationTemporality(mode) |
| 474 | dps := hist.DataPoints() |
| 475 | for id := range dpc { |
| 476 | dp := dps.AppendEmpty() |
| 477 | dp.SetStartTimestamp(pcommon.NewTimestampFromTime(start)) |
| 478 | dp.SetTimestamp(pcommon.NewTimestampFromTime(start.Add(time.Duration(epoch) * time.Minute))) |
| 479 | dp.Attributes().PutStr("id", strconv.Itoa(id)) |
| 480 | dp.ExplicitBounds().FromRaw(bounds[:]) |
| 481 |
nothing calls this directly
no test coverage detected
searching dependent graphs…