-
Notifications
You must be signed in to change notification settings - Fork 304
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
HPCC-32259 Track time spent in different parts of Roxie receive thread #18885
Merged
ghalliday
merged 1 commit into
hpcc-systems:candidate-9.6.x
from
richardkchapman:time-gone
Jul 24, 2024
Merged
Changes from all commits
Commits
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 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 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 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 |
---|---|---|
|
@@ -334,4 +334,107 @@ extern jlib_decl char **getSystemEnv(); | |
|
||
extern jlib_decl char *getHPCCEnvVal(const char *name, const char *defaultValue); | ||
|
||
// class TimeDivisionTracker is useful for working out what a thread spends its time doing. See udptrrr.cpp for an example | ||
// of its usage | ||
|
||
template<unsigned NUMSTATES, bool reportOther> class TimeDivisionTracker | ||
{ | ||
protected: | ||
unsigned __int64 totals[NUMSTATES] = {0}; | ||
unsigned counts[NUMSTATES] = {0}; | ||
const char *stateNames[NUMSTATES]; | ||
unsigned __int64 lastTick = get_cycles_now(); | ||
unsigned currentState = 0; | ||
StringAttr name; | ||
unsigned __int64 reportIntervalCycles = 0; | ||
unsigned __int64 lastReport = 0; | ||
|
||
unsigned enterState(unsigned newState) | ||
{ | ||
unsigned prevState = currentState; | ||
unsigned __int64 now = get_cycles_now(); | ||
if (reportIntervalCycles && now - lastReport >= reportIntervalCycles) | ||
{ | ||
report(true); | ||
now = get_cycles_now(); | ||
} | ||
if (newState != prevState) | ||
{ | ||
totals[currentState] += now - lastTick; | ||
currentState = newState; | ||
counts[newState]++; | ||
lastTick = now; | ||
} | ||
return prevState; | ||
} | ||
|
||
void leaveState(unsigned backToState) | ||
{ | ||
unsigned __int64 now = get_cycles_now(); | ||
if (reportIntervalCycles && now - lastReport >= reportIntervalCycles) | ||
report(true); | ||
if (backToState != currentState) | ||
{ | ||
totals[currentState] += now - lastTick; | ||
lastTick = now; | ||
currentState = backToState; | ||
} | ||
} | ||
|
||
public: | ||
TimeDivisionTracker(const char *_name, unsigned reportIntervalSeconds) : name(_name) | ||
{ | ||
if (reportIntervalSeconds) | ||
reportIntervalCycles = millisec_to_cycle(reportIntervalSeconds * 1000); | ||
} | ||
|
||
void report(bool reset) | ||
{ | ||
VStringBuffer str("%s spent ", name.str()); | ||
auto now = get_cycles_now(); | ||
totals[currentState] += now - lastTick; | ||
lastTick = now; | ||
lastReport = now; | ||
bool doneOne = false; | ||
for (unsigned i = reportOther ? 0 : 1; i < NUMSTATES; i++) | ||
{ | ||
if (counts[i]) | ||
{ | ||
if (doneOne) | ||
str.append(", "); | ||
formatTime(str, cycle_to_nanosec(totals[i])); | ||
str.appendf(" %s (%u times)", stateNames[i], counts[i]); | ||
doneOne = true; | ||
} | ||
if (reset) | ||
{ | ||
totals[i] = 0; | ||
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. Also reset counts[i]? |
||
counts[i] = 0; | ||
} | ||
} | ||
if (doneOne) | ||
DBGLOG("%s", str.str()); | ||
} | ||
|
||
class TimeDivision | ||
{ | ||
unsigned prevState = 0; | ||
TimeDivisionTracker &t; | ||
public: | ||
TimeDivision(TimeDivisionTracker &_t, unsigned newState) : t(_t) | ||
{ | ||
prevState = t.enterState(newState); | ||
} | ||
~TimeDivision() | ||
{ | ||
t.leaveState(prevState); | ||
} | ||
void switchState(unsigned newState) | ||
{ | ||
t.enterState(newState); | ||
} | ||
}; | ||
}; | ||
|
||
|
||
#endif |
This file contains 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 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
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.
If report() has been called, this will cause totals to be set to a very high number - because lastTick will be set to the latest value of get_cycles_now() - which will be larger than 'now'.
Probably simplest to pass now into the report function, and have a public helper which does not require it to be passed (or similar).
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.
note: This will self correct later, so maybe not worth worrying about - but if so, it is worth adding a comment to clarify.