Skip to content
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

Threading manager stresstest and fixes #15470

Merged
merged 5 commits into from
Apr 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Time the stress test
  • Loading branch information
hrydgard committed Apr 8, 2022
commit e0f73507f90f3642dcbdc7a18ad72d8eec63c2c1
2 changes: 1 addition & 1 deletion Common/TimeUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void sleep_ms(int ms) {

// Return the current time formatted as Minutes:Seconds:Milliseconds
// in the form 00:00:000.
void GetTimeFormatted(char formattedTime[11]) {
void GetTimeFormatted(char formattedTime[13]) {
time_t sysTime;
time(&sysTime);

Expand Down
14 changes: 14 additions & 0 deletions Common/TimeUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,17 @@ double time_now_d();
void sleep_ms(int ms);

void GetTimeFormatted(char formattedTime[13]);

// Rust-style Instant for clear and easy timing.
class Instant {
public:
static Instant Now() {
return Instant(time_now_d());
}
double Elapsed() const {
return time_now_d() - instantTime_;
}
private:
explicit Instant(double initTime) : instantTime_(initTime) {}
double instantTime_;
};
5 changes: 5 additions & 0 deletions unittest/TestThreadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ void ThreadFunc() {

bool TestMultithreadedScheduling() {
g_atomicCounter = 0;

auto start = Instant::Now();

std::thread thread1(ThreadFunc);
std::thread thread2(ThreadFunc);
std::thread thread3(ThreadFunc);
Expand All @@ -108,6 +111,8 @@ bool TestMultithreadedScheduling() {
thread5.join();
thread6.join();

printf("Stress test elapsed: %0.2f", start.Elapsed());

return true;
}

Expand Down