-
Notifications
You must be signed in to change notification settings - Fork 15
Feature/leak detection #224
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
30e822b
Keep track of live allocated memory
r1viollet 31a05ce
Add mmap hooks
nsavoire edd1f7e
Add more m(un)map overrides
nsavoire ceeb757
Add system allocation profiling (#192)
nsavoire b332e2c
PID cleanup
r1viollet 2599c39
Fix missing return value
nsavoire 05558d9
Formalize live alloc setting
r1viollet b92e107
Extract some of the logics reading tracepoint configuration
r1viollet de78185
Minor merge fix
r1viollet 4feed8c
Minor refactoring for Watcher Configurations
r1viollet ab05d2a
Minor rebase fix
r1viollet 494bbfa
Re-introduce the memory leak test
r1viollet 492e9c2
Revert "Re-introduce the memory leak test"
r1viollet 0a09fc4
De-duplicate the live allocation workflow
r1viollet 46f8f0f
Clear memory tracking state beyond a fixed bound (#239)
r1viollet e531c4b
Live Heap - Pid cleanup
r1viollet d912593
Remove check on liveness of process
r1viollet 4f8e137
Split system allocation profiling to a different pull request
r1viollet ac42a3b
Live allocation - unique stacks
r1viollet 5942cbe
Live allocation - out of order deallocations
r1viollet c52180a
Minor CI fixes
r1viollet 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // Unless explicitly stated otherwise all files in this repository are licensed | ||
| // under the Apache License Version 2.0. This product includes software | ||
| // developed at Datadog (https://www.datadoghq.com/). Copyright 2021-Present | ||
| // Datadog, Inc. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <linux/perf_event.h> | ||
| #include <type_traits> | ||
|
|
||
| // Extend the perf event types | ||
| // There are <30 different perf events (starting at 1000 seems safe) | ||
| enum : uint32_t { | ||
| PERF_CUSTOM_EVENT_DEALLOCATION = 1000, | ||
| PERF_CUSTOM_EVENT_CLEAR_LIVE_ALLOCATION | ||
| }; | ||
|
|
||
| static_assert(static_cast<uint32_t>(PERF_CUSTOM_EVENT_DEALLOCATION) > | ||
| PERF_RECORD_MAX, | ||
| "Error from PERF_CUSTOM_EVENT_DEALLOCATION definition"); | ||
|
|
||
| namespace ddprof { | ||
|
|
||
| // Custom sample type | ||
| struct DeallocationEvent { | ||
| perf_event_header hdr; | ||
| struct sample_id sample_id; | ||
| uintptr_t ptr; | ||
| }; | ||
|
|
||
| // Event to notify we have tracked too many allocations | ||
| struct ClearLiveAllocationEvent { | ||
| perf_event_header hdr; | ||
| struct sample_id sample_id; | ||
| }; | ||
|
|
||
| } // namespace ddprof |
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
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,17 @@ | ||
| // Unless explicitly stated otherwise all files in this repository are licensed | ||
| // under the Apache License Version 2.0. This product includes software | ||
| // developed at Datadog (https://www.datadoghq.com/). Copyright 2021-Present | ||
| // Datadog, Inc. | ||
|
|
||
| #pragma once | ||
|
|
||
| namespace ddprof { | ||
| namespace liveallocation { | ||
| #ifdef KMAX_TRACKED_ALLOCATIONS | ||
| // build time override to reduce execution time of test | ||
| static constexpr auto kMaxTracked = KMAX_TRACKED_ALLOCATIONS; | ||
| #else | ||
| static constexpr auto kMaxTracked = 500000; | ||
| #endif | ||
| } // namespace liveallocation | ||
| } // namespace ddprof |
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,92 @@ | ||
| // Unless explicitly stated otherwise all files in this repository are licensed | ||
| // under the Apache License Version 2.0. This product includes software | ||
| // developed at Datadog (https://www.datadoghq.com/). Copyright 2021-Present | ||
| // Datadog, Inc. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "ddprof_defs.hpp" | ||
| #include "unlikely.hpp" | ||
| #include "unwind_output_hash.hpp" | ||
|
|
||
| #include <cstddef> | ||
| #include <sys/types.h> | ||
| #include <unordered_map> | ||
|
|
||
| namespace ddprof { | ||
|
|
||
| template <typename T> | ||
| T &access_resize(std::vector<T> &v, size_t index, | ||
| const T &default_value = T()) { | ||
| if (unlikely(index >= v.size())) { | ||
| v.resize(index + 1, default_value); | ||
| } | ||
| return v[index]; | ||
| } | ||
|
|
||
| class LiveAllocation { | ||
| public: | ||
| // For allocations Value is the size | ||
| // This is the cumulative value and count for a given stack | ||
| struct ValueAndCount { | ||
| int64_t _value = 0; | ||
| int64_t _count = 0; | ||
| }; | ||
|
|
||
| using PprofStacks = | ||
| std::unordered_map<UnwindOutput, ValueAndCount, UnwindOutputHash>; | ||
|
|
||
| struct ValuePerAddress { | ||
| int64_t _value = 0; | ||
| PprofStacks::value_type *_unique_stack = nullptr; | ||
| }; | ||
|
|
||
| using AddressMap = std::unordered_map<uintptr_t, ValuePerAddress>; | ||
| struct PidStacks { | ||
| AddressMap _address_map; | ||
| PprofStacks _unique_stacks; | ||
| }; | ||
|
|
||
| using PidMap = std::unordered_map<pid_t, PidStacks>; | ||
| using WatcherVector = std::vector<PidMap>; | ||
| WatcherVector _watcher_vector; | ||
|
|
||
| // Allocation should be aggregated per stack trace | ||
| // instead of a stack, we would have a total size for this unique stack trace | ||
| // and a count. | ||
| void register_allocation(const UnwindOutput &uo, uintptr_t addr, size_t size, | ||
| int watcher_pos, pid_t pid) { | ||
| PidMap &pid_map = access_resize(_watcher_vector, watcher_pos); | ||
| PidStacks &pid_stacks = pid_map[pid]; | ||
| register_allocation(uo, addr, size, pid_stacks._unique_stacks, | ||
| pid_stacks._address_map); | ||
| } | ||
|
|
||
| void register_deallocation(uintptr_t addr, int watcher_pos, pid_t pid) { | ||
| PidMap &pid_map = access_resize(_watcher_vector, watcher_pos); | ||
| PidStacks &pid_stacks = pid_map[pid]; | ||
| register_deallocation(addr, pid_stacks._unique_stacks, | ||
| pid_stacks._address_map); | ||
| } | ||
|
|
||
| void clear_pid_for_watcher(int watcher_pos, pid_t pid) { | ||
| PidMap &pid_map = access_resize(_watcher_vector, watcher_pos); | ||
| pid_map.erase(pid); | ||
| } | ||
|
|
||
| void clear_pid(pid_t pid) { | ||
| for (auto &pid_map : _watcher_vector) { | ||
| pid_map.erase(pid); | ||
| } | ||
| } | ||
|
|
||
| private: | ||
| static void register_deallocation(uintptr_t address, PprofStacks &stacks, | ||
| AddressMap &address_map); | ||
|
|
||
| static void register_allocation(const UnwindOutput &uo, uintptr_t address, | ||
| int64_t value, PprofStacks &stacks, | ||
| AddressMap &address_map); | ||
| }; | ||
|
|
||
| } // namespace ddprof |
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.
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.
not very idiomatic... Should I rely on constructor ? Can we afford to re-init the mutex.