[nccl-profiler] fix profiling logic for proxyCtrl idle/active events #1662
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.
Context for this change
ProxyCtrl
event state is only recorded inexampleProfilerRecordEventState
, and notexampleProfilerStartEvent
orexampleProfilerStopEvent
.This is fine as long as we can guarantee that the start/stop goes together with the record state function. However, that's not true for
ncclProfilerProxyCtrlIdle
/ncclProfilerProxyCtrlActive
state used in this code excerpt fromproxy.cc
When
idle
= 1 andlastIdle
= 1 (or both = 0), then we cannot register the correct state for ProxyCtrl event -> thatstate
field become uninitialized, or some default undefined state.The fix
Without the correct state, we are attempting to
fprintf
an uninitializedconst char* str;
, which is undefined behavior. This fix (1st commit) address that by adding an else clause for early return in that case.I also propose a fix (2nd commit) for the root cause of this by adding an if guard around the
proxyCtrl
profiling logic mentioned above. This will also improve the profiler performance a lot since we would not have to constantly profile proxy Ctrl event if proxy thread idling state doesn't change.