-
Notifications
You must be signed in to change notification settings - Fork 5.5k
stats: cleanup APIs and avoid extra conversions between StatName and string. #10165
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 13 commits
5e51d3d
cff4a13
3ce28a6
1eb059c
a38c460
382e33d
26dbd13
6afd704
e74aa85
fb8ff53
a9b9f8b
273bd26
7f5c1e2
4ee741a
2abf0a5
10cc060
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 |
|---|---|---|
|
|
@@ -173,6 +173,16 @@ void SymbolTableImpl::Encoding::moveToMemBlock(MemBlockBuilder<uint8_t>& mem_blo | |
| mem_block_.reset(); // Logically transfer ownership, enabling empty assert on destruct. | ||
| } | ||
|
|
||
| void SymbolTableImpl::Encoding::appendToMemBlock(StatName stat_name, | ||
| MemBlockBuilder<uint8_t>& mem_block) { | ||
| const uint8_t* data = stat_name.dataIncludingSize(); | ||
| if (data == nullptr) { | ||
| mem_block.appendOne(0); | ||
| } else { | ||
| mem_block.appendData(absl::MakeSpan(data, stat_name.size())); | ||
| } | ||
| } | ||
|
|
||
| SymbolTableImpl::SymbolTableImpl() | ||
| // Have to be explicitly initialized, if we want to use the GUARDED_BY macro. | ||
| : next_symbol_(FirstValidSymbol), monotonic_counter_(FirstValidSymbol) {} | ||
|
|
@@ -516,7 +526,9 @@ void StatNameStorageSet::free(SymbolTable& symbol_table) { | |
| SymbolTable::StoragePtr SymbolTableImpl::join(const StatNameVec& stat_names) const { | ||
| uint64_t num_bytes = 0; | ||
| for (StatName stat_name : stat_names) { | ||
| num_bytes += stat_name.dataSize(); | ||
| if (!stat_name.empty()) { | ||
|
Contributor
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. why do we need this now?
Contributor
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. There are places in the code where elements being join()ed are empty, and we have been skipping these. Here though we just have another case of an empty-constructed StatName() will crash now if we don't special-case this. |
||
| num_bytes += stat_name.dataSize(); | ||
| } | ||
| } | ||
| MemBlockBuilder<uint8_t> mem_block(Encoding::totalSizeBytes(num_bytes)); | ||
| Encoding::appendEncoding(num_bytes, mem_block); | ||
|
|
@@ -543,8 +555,8 @@ void SymbolTableImpl::populateList(const StatName* names, uint32_t num_names, St | |
| mem_block.appendOne(num_names); | ||
| for (uint32_t i = 0; i < num_names; ++i) { | ||
| const StatName stat_name = names[i]; | ||
| Encoding::appendToMemBlock(stat_name, mem_block); | ||
| incRefCount(stat_name); | ||
| mem_block.appendData(absl::MakeSpan(stat_name.sizeAndData(), stat_name.size())); | ||
| } | ||
|
|
||
| // This assertion double-checks the arithmetic where we computed | ||
|
|
||
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.
what's the use case for appending a stat name with no data? is this just to make it easier in test?
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.
no, empty constructor for null-stats and for when there is no tag-extracted-name.
This wasn't necessary before because a StatName constructed from
""didn't require this special-casing, but I wanted to allow StatName() to also work; without this it crashes.