Initial stats cleanup#1009
Conversation
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
| RmmResourceAdaptor mr, | ||
| std::optional<PinnedMemoryResource> pinned_mr = PinnedMemoryResource::Disabled | ||
| ); | ||
| static std::shared_ptr<Statistics> create(bool enabled = true); |
There was a problem hiding this comment.
question: What does having a create static method buy us over a constructor?
There was a problem hiding this comment.
factory methods allows us to safely use std::enable_shared_from_this, where we can pass a shared_ptr to memory recorder rather than a ptr
2889f62 to
8236c70
Compare
Signed-off-by: niranda perera <niranda.perera@gmail.com> remove stats from allgather Signed-off-by: niranda perera <niranda.perera@gmail.com> stats provider concept Signed-off-by: niranda perera <niranda.perera@gmail.com> WIP Signed-off-by: niranda perera <niranda.perera@gmail.com>
8236c70 to
0c6cc9c
Compare
Signed-off-by: niranda perera <niranda.perera@gmail.com>
Signed-off-by: niranda perera <niranda.perera@gmail.com>
|
@wence- this is ready for review now |
pentschev
left a comment
There was a problem hiding this comment.
At a high-level this looks ok. Left some minor suggestions.
| * @return Shared pointer the Statistics instance. | ||
| */ | ||
| std::shared_ptr<Statistics> statistics(); | ||
| std::shared_ptr<Statistics> const& statistics() const noexcept; |
There was a problem hiding this comment.
This is OK as you're going for a hot-path optimization, but the lifetime contract should be explicit. Otherwise returning shared_ptr by value is the safer and more idiomatic API.
There was a problem hiding this comment.
@pentschev I was addressing @wence- 's earlier suggestion.
I am more inclined to use const ref, because I think the StatisticsProvider in the scope will likely keep the stats alive. Ex:
void bar(const foo& f){ // foo is a Stats provider
// multiple statistics calls
f->statistics()->add_bytes_stat(..);
f->statistics()->add_duration_stat(..);
}So, here, unless a temp stats copy is kept in bar scope, we will be creating two unnecessary copies. We dont really need a copy anyway, because f is keeping stats alive.
Now, copy will definitely a must, if statistics were a class variable. Ex: MemoryRecorder.
There was a problem hiding this comment.
At a minimum you should make the contract explicit in the docs, it is one of those things that are easy to overlook when you're just glancing at the return type and think "this returns a shared_ptr, so I can manage it's lifetime have a copy while I keep it alive".
There was a problem hiding this comment.
@pentschev After thinking about this a bit more, I reverted stats to return by value.
| * @param statistics The statistics instance to use (disabled by default). The caller | ||
| * is responsible for creating and owning this object. |
There was a problem hiding this comment.
"and owning this object" doesn't make sense here, std::shared_ptr<Statistics> is passed by value.
| * by-value `std::shared_ptr` return would incur on hot paths. | ||
| * | ||
| * Each provider asserts this concept via `static_assert` in its own header. | ||
| * Current providers: `BufferResource`, `ProgressThread`, `streaming::Context`. |
There was a problem hiding this comment.
| * Current providers: `BufferResource`, `ProgressThread`, `streaming::Context`. |
There was a problem hiding this comment.
Probably best not to document providers here as this will eventually fall out-of-sync.
Signed-off-by: niranda perera <niranda.perera@gmail.com>
Signed-off-by: niranda perera <niranda.perera@gmail.com>
pentschev
left a comment
There was a problem hiding this comment.
This looks good to me, thanks Niranda.
Statisticswas constructible directly (make_shared<Statistics>(false)was not equal toStatistics::disabled()),MemoryRecorderheld a rawStatistics*(lifetime hazard noted by an existing TODO), providerstatistics()accessors returnedshared_ptrby value (atomic refcount bumps on hot paths), and secondary objects likeAllGatherredundantly carried their ownstatistics_member already reachable through the buffer resource / context.In this PR, following changes were made
Statisticsconstructible only through factory methods (create(),from_options(),disabled()); the public ctor is removed anddisabled()is now the canonical singleton for the disabled case.Statisticsfromstd::enable_shared_from_thissoMemoryRecorderowns ashared_ptr<Statistics>instead of a raw pointer; recorder no-ops when stats are disabled.StatisticsProviderconcept and have providers (BufferResource,ProgressThread,streaming::Context) returnstd::shared_ptr<Statistics> const&fromstatistics(); each providerstatic_asserts the concept.statisticsparameter andstatistics_member fromcoll::AllGather(and its Python binding); secondary classes now derive theirStatisticsfrom the provider they already receive.Related to #1008
Depends on #1003