-
Notifications
You must be signed in to change notification settings - Fork 13
feat(nativemem): instrument remaining allocation sites #724
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * Copyright 2026, Datadog, Inc. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| #ifndef _COUNTINGALLOCATOR_H | ||
| #define _COUNTINGALLOCATOR_H | ||
|
|
||
| #include "nativeMem.h" | ||
| #include <cstddef> | ||
| #include <new> | ||
|
|
||
| // A stateless, C++11-Allocator-conformant wrapper around ::operator new / | ||
| // ::operator delete that records every allocation/deallocation into the given | ||
| // NativeMem category. STL containers rebind the supplied Allocator<value_type> | ||
| // to their actual node type before calling allocate(), so this yields the | ||
| // exact real per-node byte count the implementation uses -- not an estimate. | ||
| template <typename T, NativeMemCategory Cat> | ||
| class CountingAllocator { | ||
| public: | ||
| using value_type = T; | ||
|
|
||
| CountingAllocator() noexcept = default; | ||
| template <typename U> | ||
| CountingAllocator(const CountingAllocator<U, Cat> &) noexcept {} | ||
|
|
||
| T *allocate(std::size_t n) { | ||
| T *p = static_cast<T *>(::operator new(n * sizeof(T))); | ||
| NativeMem::record(Cat, (long long)(n * sizeof(T))); | ||
| return p; | ||
| } | ||
|
|
||
| void deallocate(T *p, std::size_t n) noexcept { | ||
| NativeMem::record(Cat, -(long long)(n * sizeof(T))); | ||
| ::operator delete(p); | ||
| } | ||
|
|
||
| template <typename U> | ||
| struct rebind { | ||
| using other = CountingAllocator<U, Cat>; | ||
| }; | ||
| }; | ||
|
|
||
| template <typename T, NativeMemCategory Cat> | ||
| inline bool operator==(const CountingAllocator<T, Cat> &, | ||
| const CountingAllocator<T, Cat> &) { | ||
| return true; | ||
| } | ||
|
|
||
| template <typename T, NativeMemCategory Cat> | ||
| inline bool operator!=(const CountingAllocator<T, Cat> &, | ||
| const CountingAllocator<T, Cat> &) { | ||
| return false; | ||
| } | ||
|
|
||
| #endif // _COUNTINGALLOCATOR_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
|
|
||
| #include <cassert> | ||
| #include "engine.h" | ||
| #include "nativeMem.h" | ||
| #include "os.h" | ||
| #include "profiler.h" | ||
| #include "reservoirSampler.h" | ||
|
|
@@ -79,6 +80,7 @@ class BaseWallClock : public Engine { | |
|
|
||
| while (_running.load(std::memory_order_relaxed)) { | ||
| collectThreads(threads); | ||
| NativeMem::setLive(NM_MISC, (long long)threads.capacity() * sizeof(ThreadType)); | ||
|
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.
When wall-clock profiling is enabled, this writes an absolute Useful? React with 👍 / 👎. |
||
|
|
||
| int num_failures = 0; | ||
| int threads_already_exited = 0; | ||
|
|
||
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 commit touches files that still do not satisfy the repository copyright rule:
threadInfo.h,threadInfo.cpp, andunwindStats.hstill lack a Datadog header, and several modified files with existing 2025 Datadog headers were not updated to the current year. Please add/update the current-year Datadog headers before landing.AGENTS.md reference: AGENTS.md:L372-L374
Useful? React with 👍 / 👎.