-
Notifications
You must be signed in to change notification settings - Fork 981
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
chore: Remove manual memory management from stats #2550
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -23,32 +23,12 @@ namespace dfly { | |
|
||
__thread ServerState* ServerState::state_ = nullptr; | ||
|
||
ServerState::Stats::Stats() { | ||
ServerState::Stats::Stats(unsigned num_shards) : tx_width_freq_arr(num_shards) { | ||
tx_type_cnt.fill(0); | ||
} | ||
|
||
ServerState::Stats::~Stats() { | ||
delete[] tx_width_freq_arr; | ||
} | ||
|
||
auto ServerState::Stats::operator=(Stats&& other) -> Stats& { | ||
for (int i = 0; i < NUM_TX_TYPES; ++i) { | ||
this->tx_type_cnt[i] = other.tx_type_cnt[i]; | ||
} | ||
this->eval_io_coordination_cnt = other.eval_io_coordination_cnt; | ||
this->eval_shardlocal_coordination_cnt = other.eval_shardlocal_coordination_cnt; | ||
this->eval_squashed_flushes = other.eval_squashed_flushes; | ||
this->tx_schedule_cancel_cnt = other.tx_schedule_cancel_cnt; | ||
|
||
delete[] this->tx_width_freq_arr; | ||
this->tx_width_freq_arr = other.tx_width_freq_arr; | ||
other.tx_width_freq_arr = nullptr; | ||
|
||
return *this; | ||
} | ||
|
||
ServerState::Stats& ServerState::Stats::Add(unsigned num_shards, const ServerState::Stats& other) { | ||
static_assert(sizeof(Stats) == 13 * 8, "Stats size mismatch"); | ||
ServerState::Stats& ServerState::Stats::Add(const ServerState::Stats& other) { | ||
static_assert(sizeof(Stats) == 14 * 8, "Stats size mismatch"); | ||
|
||
for (int i = 0; i < NUM_TX_TYPES; ++i) { | ||
this->tx_type_cnt[i] += other.tx_type_cnt[i]; | ||
|
@@ -65,15 +45,12 @@ ServerState::Stats& ServerState::Stats::Add(unsigned num_shards, const ServerSta | |
|
||
this->blocked_on_interpreter += other.blocked_on_interpreter; | ||
|
||
if (this->tx_width_freq_arr == nullptr) { | ||
this->tx_width_freq_arr = new uint64_t[num_shards]; | ||
std::copy_n(other.tx_width_freq_arr, num_shards, this->tx_width_freq_arr); | ||
if (this->tx_width_freq_arr.size() > 0) { | ||
DCHECK_EQ(this->tx_width_freq_arr.size(), other.tx_width_freq_arr.size()); | ||
this->tx_width_freq_arr += other.tx_width_freq_arr; | ||
} else { | ||
for (unsigned i = 0; i < num_shards; ++i) { | ||
this->tx_width_freq_arr[i] += other.tx_width_freq_arr[i]; | ||
} | ||
this->tx_width_freq_arr = other.tx_width_freq_arr; | ||
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. should never happen |
||
} | ||
|
||
return *this; | ||
} | ||
|
||
|
@@ -121,8 +98,7 @@ void ServerState::Init(uint32_t thread_index, uint32_t num_shards, acl::UserRegi | |
state_->gstate_ = GlobalState::ACTIVE; | ||
state_->thread_index_ = thread_index; | ||
state_->user_registry = registry; | ||
state_->stats.tx_width_freq_arr = new uint64_t[num_shards]; | ||
std::fill_n(state_->stats.tx_width_freq_arr, num_shards, 0); | ||
state_->stats = Stats(num_shards); | ||
} | ||
|
||
void ServerState::Destroy() { | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think this assertion is better move under the Stats definition
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.
and instead of 8 use sizeof(int64_t)