-
Notifications
You must be signed in to change notification settings - Fork 116
Object stats #616
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
Open
mjp41
wants to merge
19
commits into
microsoft:main
Choose a base branch
from
mjp41:object_stats
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Object stats #616
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
757c236
Rename corealloc.h to alloc.h
mjp41 6447c87
Some outstanding tests.
mjp41 d29fffa
Add statistic to snmalloc.
mjp41 8eda79d
conversion fix.
mjp41 462402d
Fix header
mjp41 9987987
Clangformat
mjp41 0f4477c
Do not write to the default allocators state.
mjp41 19dc26a
temporarily disable test to get a cleaner CI run
mjp41 77e14eb
Change headers slightly.
mjp41 098b1c4
Move seqset as it uses pointeroffset and that is aal.
mjp41 5bc8fd8
Fix stl
mjp41 0338c70
stl const?
mjp41 1768968
Fixing CI
mjp41 fc395dd
Fix inflight check
mjp41 5071db0
Fix inflight statistic
mjp41 94d7a26
Shrink test size.
mjp41 6474380
Remove interlocked from fast path.
mjp41 1a7c372
capptr_reveal position was causing GCC to emit a frame which wasn't r…
mjp41 85dac30
Alter inlining for GCC
mjp41 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,101 @@ | ||
#pragma once | ||
|
||
#include "defines.h" | ||
#include "snmalloc/stl/atomic.h" | ||
#include "stddef.h" | ||
|
||
namespace snmalloc | ||
{ | ||
/** | ||
* Very basic statistic that tracks current and peak values. | ||
*/ | ||
class Stat | ||
{ | ||
private: | ||
stl::Atomic<size_t> curr{0}; | ||
stl::Atomic<size_t> peak{0}; | ||
|
||
public: | ||
void increase(size_t amount) | ||
{ | ||
size_t old = curr.fetch_add(amount); | ||
size_t c = old + amount; | ||
size_t p = peak.load(stl::memory_order_relaxed); | ||
while (c > p) | ||
{ | ||
if (peak.compare_exchange_strong(p, c)) | ||
break; | ||
} | ||
} | ||
|
||
void decrease(size_t amount) | ||
{ | ||
size_t prev = curr.fetch_sub(amount); | ||
SNMALLOC_ASSERT_MSG( | ||
prev >= amount, "prev = {}, amount = {}", prev, amount); | ||
UNUSED(prev); | ||
} | ||
|
||
size_t get_curr() | ||
{ | ||
return curr.load(stl::memory_order_relaxed); | ||
} | ||
|
||
size_t get_peak() | ||
{ | ||
return peak.load(stl::memory_order_relaxed); | ||
} | ||
|
||
void operator+=(size_t amount) | ||
{ | ||
increase(amount); | ||
} | ||
|
||
void operator-=(size_t amount) | ||
{ | ||
decrease(amount); | ||
} | ||
|
||
void operator++() | ||
{ | ||
increase(1); | ||
} | ||
|
||
void operator--() | ||
{ | ||
decrease(1); | ||
} | ||
}; | ||
|
||
/** | ||
* Very basic statistic that can only grow. Not thread-safe. | ||
*/ | ||
class MonotoneLocalStat | ||
{ | ||
stl::Atomic<size_t> value{0}; | ||
|
||
public: | ||
void operator++(int) | ||
{ | ||
auto old = value.load(stl::memory_order_relaxed); | ||
value.store(old + 1, stl::memory_order_relaxed); | ||
} | ||
|
||
void operator+=(const MonotoneLocalStat& other) | ||
{ | ||
auto v = other.value.load(stl::memory_order_relaxed); | ||
value.fetch_add(v, stl::memory_order_relaxed); | ||
} | ||
|
||
void operator+=(size_t v) | ||
{ | ||
auto old = value.load(stl::memory_order_relaxed); | ||
value.store(old + v, stl::memory_order_relaxed); | ||
} | ||
|
||
size_t operator*() | ||
{ | ||
return value.load(stl::memory_order_relaxed); | ||
} | ||
}; | ||
} // namespace snmalloc |
This file contains hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.