-
Notifications
You must be signed in to change notification settings - Fork 0
[DRAFT] refcount stats across scopes #2
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 1 commit
3d5849d
b6aa029
d615eef
cdd8418
101c7aa
282c56b
830c718
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 |
|---|---|---|
|
|
@@ -150,9 +150,21 @@ bool TagExtractorImpl::extractTag(const std::string& stat_name, std::vector<Tag> | |
| } | ||
|
|
||
| RawStatData* HeapRawStatDataAllocator::alloc(const std::string& name) { | ||
| // This must be zero-initialized | ||
| RawStatData* data = static_cast<RawStatData*>(::calloc(RawStatData::size(), 1)); | ||
| data->initialize(name); | ||
| absl::string_view key = name; | ||
|
|
||
| if (key.size() > Stats::RawStatData::maxNameLength()) { | ||
| key.remove_suffix(key.size() - Stats::RawStatData::maxNameLength()); | ||
| } | ||
|
|
||
| RawStatData* data = stats_set_[std::string(key)]; | ||
|
|
||
| if (stats_set_.count(std::string(key)) == 1) { // TODO do better | ||
|
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 think this if statement is backwards. |
||
| // didn't exist before now, actually create | ||
|
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. nit: make this a full sentence comment or remove. |
||
| data = static_cast<RawStatData*>(::calloc(RawStatData::size(), 1)); | ||
| data->initialize(name); | ||
|
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. Doesn't this need to be truncated?
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 think it expects the full |
||
| } else { | ||
| ++data->ref_count_; | ||
| } | ||
| return data; | ||
| } | ||
|
|
||
|
|
@@ -256,8 +268,15 @@ TagProducerImpl::addDefaultExtractors(const envoy::config::metrics::v2::StatsCon | |
| } | ||
|
|
||
| void HeapRawStatDataAllocator::free(RawStatData& data) { | ||
| // This allocator does not ever have concurrent access to the raw data. | ||
| ASSERT(data.ref_count_ == 1); | ||
| ASSERT(data.ref_count_ > 0); | ||
| if (--data.ref_count_ > 0) { | ||
| return; | ||
| } | ||
|
|
||
| std::cout << data.key() << "\n"; | ||
| size_t key_removed = stats_set_.erase(std::string(data.key())); | ||
| std::cout << key_removed << "\n"; | ||
| ASSERT(key_removed >= 1); | ||
| ::free(&data); | ||
| } | ||
|
|
||
|
|
||
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.
You're copying this pointer, not grabbing a reference to it (yes, a reference to a pointer haha), so anything you do to it after this is only affecting the local variable data and not the pointer you copied from in the map.
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.
This is the syntax for a ref to a pointer:
RawStatData*& data.