-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use template class for in-memory data. (#1496)
- Loading branch information
Showing
4 changed files
with
73 additions
and
55 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
62 changes: 62 additions & 0 deletions
62
exporters/memory/include/opentelemetry/exporters/memory/in_memory_data.h
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,62 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include "opentelemetry/sdk/common/circular_buffer.h" | ||
|
||
#include <vector> | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace exporter | ||
{ | ||
namespace memory | ||
{ | ||
/** | ||
* A wrapper class holding in memory exporter data | ||
*/ | ||
template <typename T> | ||
class InMemoryData | ||
{ | ||
public: | ||
/** | ||
* @param buffer_size a required value that sets the size of the CircularBuffer | ||
*/ | ||
InMemoryData(size_t buffer_size) : data_(buffer_size) {} | ||
|
||
/** | ||
* @param data a required unique pointer to the data to add to the CircularBuffer | ||
*/ | ||
void Add(std::unique_ptr<T> data) noexcept { data_.Add(data); } | ||
|
||
/** | ||
* @return Returns a vector of unique pointers containing all the data in the | ||
* CircularBuffer. This operation will empty the Buffer, which is why the data | ||
* is returned as unique pointers | ||
*/ | ||
std::vector<std::unique_ptr<T>> Get() noexcept | ||
{ | ||
std::vector<std::unique_ptr<T>> res; | ||
|
||
// Pointer swap is required because the Consume function requires that the | ||
// AtomicUniquePointer be set to null | ||
data_.Consume( | ||
data_.size(), [&](opentelemetry::sdk::common::CircularBufferRange< | ||
opentelemetry::sdk::common::AtomicUniquePtr<T>> range) noexcept { | ||
range.ForEach([&](opentelemetry::sdk::common::AtomicUniquePtr<T> &ptr) noexcept { | ||
std::unique_ptr<T> swap_ptr = nullptr; | ||
ptr.Swap(swap_ptr); | ||
res.push_back(std::move(swap_ptr)); | ||
return true; | ||
}); | ||
}); | ||
|
||
return res; | ||
} | ||
|
||
private: | ||
opentelemetry::sdk::common::CircularBuffer<T> data_; | ||
}; | ||
} // namespace memory | ||
} // namespace exporter | ||
OPENTELEMETRY_END_NAMESPACE |
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
4062237
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
.BM_AttributseHashMap
23119664.192199707
ns/iter10891712.62887808
ns/iter2.12
BM_LockFreeBuffer/1
777603.8646697998
ns/iter295930.403795066
ns/iter2.63
BM_LockFreeBuffer/2
1983299.0169525146
ns/iter986895.5612182617
ns/iter2.01
This comment was automatically generated by workflow using github-action-benchmark.
4062237
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible performance regression was detected for benchmark 'OpenTelemetry-cpp api Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
2
.BM_SpinLockThrashing/1/process_time/real_time
0.6769353693181818
ms/iter0.12063959513715306
ms/iter5.61
BM_SpinLockThrashing/2/process_time/real_time
1.6767105586092237
ms/iter0.23872146801072724
ms/iter7.02
BM_ProcYieldSpinLockThrashing/1/process_time/real_time
0.5251633698673924
ms/iter0.12088441766114127
ms/iter4.34
BM_ProcYieldSpinLockThrashing/2/process_time/real_time
1.4159321784973145
ms/iter0.24126741711488167
ms/iter5.87
BM_NaiveSpinLockThrashing/1/process_time/real_time
0.7165804911216409
ms/iter0.12069827718291554
ms/iter5.94
BM_NaiveSpinLockThrashing/2/process_time/real_time
2.9533360455487228
ms/iter0.23896458205916368
ms/iter12.36
BM_ThreadYieldSpinLockThrashing/1/process_time/real_time
38.23590278625488
ms/iter8.930504322052002
ms/iter4.28
This comment was automatically generated by workflow using github-action-benchmark.