-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2337fd3
commit 631b9f5
Showing
4 changed files
with
18 additions
and
16 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
#include "ResourceMonitorThread.h" | ||
#include "libstuff/libstuff.h" | ||
#include "format" | ||
#include <format> | ||
#include <cmath> | ||
|
||
thread_local uint64_t ResourceMonitorThread::startTime; | ||
thread_local double ResourceMonitorThread::cpuStartTime; | ||
uint64_t ResourceMonitorThread::threadStartTime; | ||
double ResourceMonitorThread::cpuStartTime; | ||
|
||
void ResourceMonitorThread::before(){ | ||
startTime = STimeNow(); | ||
void ResourceMonitorThread::before() { | ||
threadStartTime = STimeNow(); | ||
cpuStartTime = SGetCPUUserTime(); | ||
} | ||
|
||
void ResourceMonitorThread::after(){ | ||
const uint64_t threadEndTime = STimeNow() - startTime; | ||
const double CPUUserTime = SGetCPUUserTime() - cpuStartTime; | ||
void ResourceMonitorThread::after() { | ||
const uint64_t threadUserTime = STimeNow() - threadStartTime; | ||
const double cpuUserTime = SGetCPUUserTime() - cpuStartTime; | ||
|
||
// This shouldn't happen since the time to start/finish a thread should take more than a microsecond, but to be | ||
// sure we're not dividing by 0 and causing crashes, let's add an if here and return if threadEndTime is 0. | ||
if (threadEndTime == 0) { | ||
if (threadUserTime == 0) { | ||
return; | ||
} | ||
const double cpuUserPercentage = round((CPUUserTime / static_cast<double>(threadEndTime)) * 100 * 1000) / 1000; | ||
const double cpuUserPercentage = round((cpuUserTime / static_cast<double>(threadUserTime)) * 100 * 1000) / 1000; | ||
const pid_t tid = syscall(SYS_gettid); | ||
SINFO(format("Thread finished. pID: '{}', CPUTime: '{}µs', CPUPercentage: '{}%'", tid, CPUUserTime, cpuUserPercentage, startTime, cpuStartTime)); | ||
SINFO(format("Thread finished. pID: '{}', CPUTime: '{}µs', CPUPercentage: '{}%'", tid, cpuUserTime, cpuUserPercentage)); | ||
} |
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