-
Notifications
You must be signed in to change notification settings - Fork 120
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
Draft
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.
Draft
Object stats #616
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7c9f6b5
Some outstanding tests.
mjp41 d15c1bc
Add statistic to snmalloc.
mjp41 efb4263
conversion fix.
mjp41 fcfbd25
Fix header
mjp41 229a330
Clangformat
mjp41 ee46a3f
Do not write to the default allocators state.
mjp41 40e84f5
temporarily disable test to get a cleaner CI run
mjp41 5dca692
Change headers slightly.
mjp41 b8f369c
Move seqset as it uses pointeroffset and that is aal.
mjp41 1ed9ab2
Fix stl
mjp41 be43d4c
stl const?
mjp41 b3d9ff8
Fixing CI
mjp41 e395751
Fix inflight check
mjp41 5b4e542
Fix inflight statistic
mjp41 f97e741
Remove interlocked from fast path.
mjp41 28c7f4b
Fix comment
mjp41 fa8814e
WIP: Rebasing to latest snmalloc.
mjp41 3af40d2
CF
mjp41 9a7d04b
Fix inlining for failure.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,185 @@ | ||
| #pragma once | ||
|
|
||
| #include "defines.h" | ||
|
|
||
| #include <stddef.h> | ||
|
|
||
| namespace snmalloc | ||
| { | ||
| /** | ||
| * A simple fixed-size array container. | ||
| * | ||
| * This provides a std::array-like interface without depending on the | ||
| * standard library. The array supports aggregate initialization and | ||
| * provides iterators for range-based for loops. | ||
| * | ||
| * @tparam T The element type | ||
| * @tparam N The number of elements | ||
| */ | ||
| template<typename T, size_t N> | ||
| struct Array | ||
| { | ||
| // Expose this to public to allow aggregate initialization. | ||
| T storage_[N]; | ||
|
|
||
| [[nodiscard]] constexpr SNMALLOC_FAST_PATH size_t size() const | ||
| { | ||
| return N; | ||
| } | ||
|
|
||
| constexpr T& operator[](size_t i) | ||
| { | ||
| return storage_[i]; | ||
| } | ||
|
|
||
| constexpr const T& operator[](size_t i) const | ||
| { | ||
| return storage_[i]; | ||
| } | ||
|
|
||
| using value_type = T; | ||
| using size_type = size_t; | ||
| using iterator = T*; | ||
| using const_iterator = const T*; | ||
|
|
||
| [[nodiscard]] constexpr SNMALLOC_FAST_PATH iterator begin() | ||
| { | ||
| return &storage_[0]; | ||
| } | ||
|
|
||
| [[nodiscard]] constexpr SNMALLOC_FAST_PATH const_iterator begin() const | ||
| { | ||
| return &storage_[0]; | ||
| } | ||
|
|
||
| [[nodiscard]] constexpr SNMALLOC_FAST_PATH iterator end() | ||
| { | ||
| return &storage_[N]; | ||
| } | ||
|
|
||
| [[nodiscard]] constexpr SNMALLOC_FAST_PATH const_iterator end() const | ||
| { | ||
| return &storage_[N]; | ||
| } | ||
|
|
||
| [[nodiscard]] constexpr SNMALLOC_FAST_PATH T* data() | ||
| { | ||
| return &storage_[0]; | ||
| } | ||
|
|
||
| [[nodiscard]] constexpr SNMALLOC_FAST_PATH const T* data() const | ||
| { | ||
| return &storage_[0]; | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Specialization for zero-length arrays. | ||
| * | ||
| * Zero-length arrays are not valid in standard C++, so we provide | ||
| * a specialization that has no storage but maintains the same interface. | ||
| */ | ||
| template<typename T> | ||
| struct Array<T, 0> | ||
| { | ||
| [[nodiscard]] constexpr SNMALLOC_FAST_PATH size_t size() const | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| constexpr T& operator[](size_t) | ||
| { | ||
| SNMALLOC_FAST_FAIL(); | ||
| } | ||
|
|
||
| constexpr const T& operator[](size_t) const | ||
| { | ||
| SNMALLOC_FAST_FAIL(); | ||
| } | ||
|
|
||
| using value_type = T; | ||
| using size_type = size_t; | ||
| using iterator = T*; | ||
| using const_iterator = const T*; | ||
|
|
||
| [[nodiscard]] constexpr SNMALLOC_FAST_PATH iterator begin() | ||
| { | ||
| return nullptr; | ||
| } | ||
|
|
||
| [[nodiscard]] constexpr SNMALLOC_FAST_PATH const_iterator begin() const | ||
| { | ||
| return nullptr; | ||
| } | ||
|
|
||
| [[nodiscard]] constexpr SNMALLOC_FAST_PATH iterator end() | ||
| { | ||
| return nullptr; | ||
| } | ||
|
|
||
| [[nodiscard]] constexpr SNMALLOC_FAST_PATH const_iterator end() const | ||
| { | ||
| return nullptr; | ||
| } | ||
|
|
||
| [[nodiscard]] constexpr SNMALLOC_FAST_PATH T* data() | ||
| { | ||
| return nullptr; | ||
| } | ||
|
|
||
| [[nodiscard]] constexpr SNMALLOC_FAST_PATH const T* data() const | ||
| { | ||
| return nullptr; | ||
| } | ||
| }; | ||
|
|
||
| // Free function begin/end for Array | ||
| template<typename T, size_t N> | ||
| constexpr T* begin(Array<T, N>& a) | ||
| { | ||
| return a.begin(); | ||
| } | ||
|
|
||
| template<typename T, size_t N> | ||
| constexpr T* end(Array<T, N>& a) | ||
| { | ||
| return a.end(); | ||
| } | ||
|
|
||
| template<typename T, size_t N> | ||
| constexpr const T* begin(const Array<T, N>& a) | ||
| { | ||
| return a.begin(); | ||
| } | ||
|
|
||
| template<typename T, size_t N> | ||
| constexpr const T* end(const Array<T, N>& a) | ||
| { | ||
| return a.end(); | ||
| } | ||
|
|
||
| // Free function begin/end for C-style arrays | ||
| template<typename T, size_t N> | ||
| constexpr T* begin(T (&a)[N]) | ||
| { | ||
| return &a[0]; | ||
| } | ||
|
|
||
| template<typename T, size_t N> | ||
| constexpr T* end(T (&a)[N]) | ||
| { | ||
| return &a[N]; | ||
| } | ||
|
|
||
| template<typename T, size_t N> | ||
| constexpr const T* begin(const T (&a)[N]) | ||
| { | ||
| return &a[0]; | ||
| } | ||
|
|
||
| template<typename T, size_t N> | ||
| constexpr const T* end(const T (&a)[N]) | ||
| { | ||
| return &a[N]; | ||
| } | ||
| } // 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
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: | ||
| SNMALLOC_FAST_PATH void operator++(int) | ||
| { | ||
| auto old = value.load(stl::memory_order_relaxed); | ||
| value.store(old + 1, stl::memory_order_relaxed); | ||
| } | ||
|
|
||
| SNMALLOC_FAST_PATH void operator+=(const MonotoneLocalStat& other) | ||
| { | ||
| auto v = other.value.load(stl::memory_order_relaxed); | ||
| value.fetch_add(v, stl::memory_order_relaxed); | ||
| } | ||
|
|
||
| SNMALLOC_FAST_PATH void operator+=(size_t v) | ||
| { | ||
| auto old = value.load(stl::memory_order_relaxed); | ||
| value.store(old + v, stl::memory_order_relaxed); | ||
| } | ||
|
|
||
| SNMALLOC_FAST_PATH size_t operator*() | ||
| { | ||
| return value.load(stl::memory_order_relaxed); | ||
| } | ||
| }; | ||
| } // namespace snmalloc | ||
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.