-
Notifications
You must be signed in to change notification settings - Fork 0
[DRAFT] Refcount stats across scopes #1
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
Changes from all commits
e3f59d5
bfd2084
c306c01
a263690
9298e3c
f1e94fa
e49a15a
d7dc10e
de2879d
e9c65fa
5dde224
46d4b9e
5466e13
04d28f2
bc25b35
adf9a6e
3dde624
3c773a8
01c70ca
2b9f176
1916c2c
765df8e
afeb8f2
5aff3d1
cc22d9e
fafdf72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,13 +149,53 @@ bool TagExtractorImpl::extractTag(const std::string& stat_name, std::vector<Tag> | |
| return false; | ||
| } | ||
|
|
||
| RawStatData* BlockRawStatDataAllocator::alloc(const std::string& name) { | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved a lot of these tests from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What tests are you referring to? This is an implementation file...?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow, I don't know how this ended up here. I think I meant to say I moved these ::alloc and ::free functions from hot_restart_impl.cc. |
||
| std::unique_lock<Thread::BasicLockable> lock(stat_lock_); | ||
|
|
||
| absl::string_view key = name; | ||
| if (key.size() > Stats::RawStatData::maxNameLength()) { | ||
| key.remove_suffix(key.size() - Stats::RawStatData::maxNameLength()); | ||
| } | ||
| auto value_created = stats_set_->insert(key); | ||
| Stats::RawStatData* data = value_created.first; | ||
| if (data == nullptr) { | ||
| return nullptr; | ||
| } | ||
| // For new entries (value-created.second==true), BlockMemoryHashSet calls Value::initialize() | ||
| // automatically, but on recycled entries (value-created.second==false) we need to bump the | ||
| // ref-count. | ||
| if (!value_created.second) { | ||
| ++data->ref_count_; | ||
| } | ||
| return data; | ||
| } | ||
|
|
||
| void BlockRawStatDataAllocator::free(RawStatData& data) { | ||
| // We must hold the lock since the reference decrement can race with an initialize above. | ||
| std::unique_lock<Thread::BasicLockable> lock(stat_lock_); | ||
|
|
||
| ASSERT(data.ref_count_ > 0); | ||
| if (--data.ref_count_ > 0) { | ||
| return; | ||
| } | ||
| bool key_removed = stats_set_->remove(data.key()); | ||
| ASSERT(key_removed); | ||
| memset(&data, 0, Stats::RawStatData::size()); | ||
| } | ||
|
|
||
| RawStatData* HeapRawStatDataAllocator::alloc(const std::string& name) { | ||
| // This must be zero-initialized | ||
| RawStatData* data = static_cast<RawStatData*>(::calloc(RawStatData::size(), 1)); | ||
| data->initialize(name); | ||
| return data; | ||
| } | ||
|
|
||
| void HeapRawStatDataAllocator::free(RawStatData& data) { | ||
| // This allocator does not ever have concurrent access to the raw data. | ||
| ASSERT(data.ref_count_ == 1); | ||
| ::free(&data); | ||
| } | ||
|
|
||
| TagProducerImpl::TagProducerImpl(const envoy::config::metrics::v2::StatsConfig& config) | ||
| : TagProducerImpl() { | ||
| // To check name conflict. | ||
|
|
@@ -255,12 +295,6 @@ TagProducerImpl::addDefaultExtractors(const envoy::config::metrics::v2::StatsCon | |
| return names; | ||
| } | ||
|
|
||
| void HeapRawStatDataAllocator::free(RawStatData& data) { | ||
| // This allocator does not ever have concurrent access to the raw data. | ||
| ASSERT(data.ref_count_ == 1); | ||
| ::free(&data); | ||
| } | ||
|
|
||
| void RawStatData::initialize(absl::string_view key) { | ||
| ASSERT(!initialized()); | ||
| ASSERT(key.size() <= maxNameLength()); | ||
|
|
||
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.
@mrice32 This is one of a few commits which rename
SharedMemoryHashSettoMemoryHashSet, orshared_memory_hash_settomemory_hash_set, orsharedMemOptionstomemOptions. I wanted to indicate that the MemoryHashSet doesn't need to be run on shared memory.