Skip to content

Commit

Permalink
fix data race on MeterContext::meters_ (#1668)
Browse files Browse the repository at this point in the history
  • Loading branch information
esigo authored Oct 9, 2022
1 parent 79a9471 commit 7140166
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions sdk/include/opentelemetry/sdk/metrics/meter_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class MeterContext : public std::enable_shared_from_this<MeterContext>

std::atomic_flag shutdown_latch_ = ATOMIC_FLAG_INIT;
opentelemetry::common::SpinLockMutex forceflush_lock_;
opentelemetry::common::SpinLockMutex storage_lock_;
};

} // namespace metrics
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/metrics/meter_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ViewRegistry *MeterContext::GetViewRegistry() const noexcept

nostd::span<std::shared_ptr<Meter>> MeterContext::GetMeters() noexcept
{
std::lock_guard<opentelemetry::common::SpinLockMutex> guard(storage_lock_);
return nostd::span<std::shared_ptr<Meter>>{meters_};
}

Expand Down Expand Up @@ -59,6 +60,7 @@ void MeterContext::AddView(std::unique_ptr<InstrumentSelector> instrument_select

void MeterContext::AddMeter(std::shared_ptr<Meter> meter)
{
std::lock_guard<opentelemetry::common::SpinLockMutex> guard(storage_lock_);
meters_.push_back(meter);
}

Expand Down

1 comment on commit 7140166

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'OpenTelemetry-cpp sdk Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 7140166 Previous: 79a9471 Ratio
BM_BaselineBuffer/2 19381151.19934082 ns/iter 4407275.915145874 ns/iter 4.40
BM_BaselineBuffer/4 13398520.946502686 ns/iter 6410932.64523429 ns/iter 2.09
BM_LockFreeBuffer/1 3354575.0734150917 ns/iter 318578.90525479906 ns/iter 10.53
BM_LockFreeBuffer/2 4359145.402908325 ns/iter 1137902.9750823975 ns/iter 3.83

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.