-
Notifications
You must be signed in to change notification settings - Fork 502
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Linux/macOS: Implement overlay CPU/memory statistics (#480)
- Loading branch information
1 parent
c170973
commit 9ce52ad
Showing
14 changed files
with
322 additions
and
98 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
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
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
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "util/SystemInfo/SystemInfo.h" | ||
|
||
uint64 ProcessorTime::work() | ||
{ | ||
return user + kernel; | ||
} | ||
|
||
uint64 ProcessorTime::total() | ||
{ | ||
return idle + user + kernel; | ||
} | ||
|
||
double ProcessorTime::Compare(ProcessorTime &last, ProcessorTime &now) | ||
{ | ||
auto dwork = now.work() - last.work(); | ||
auto dtotal = now.total() - last.total(); | ||
|
||
return (double)dwork / dtotal; | ||
} | ||
|
||
uint32 GetProcessorCount() | ||
{ | ||
return std::thread::hardware_concurrency(); | ||
} | ||
|
||
void QueryProcTime(ProcessorTime &out) | ||
{ | ||
uint64 now, user, kernel; | ||
QueryProcTime(now, user, kernel); | ||
|
||
out.idle = now - (user + kernel); | ||
out.kernel = kernel; | ||
out.user = user; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
struct ProcessorTime | ||
{ | ||
uint64 idle{}, kernel{}, user{}; | ||
|
||
uint64 work(); | ||
uint64 total(); | ||
|
||
static double Compare(ProcessorTime &last, ProcessorTime &now); | ||
}; | ||
|
||
uint32 GetProcessorCount(); | ||
uint64 QueryRamUsage(); | ||
void QueryProcTime(uint64 &out_now, uint64 &out_user, uint64 &out_kernel); | ||
void QueryProcTime(ProcessorTime &out); | ||
void QueryCoreTimes(uint32 count, std::vector<ProcessorTime>& out); |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "util/SystemInfo/SystemInfo.h" | ||
|
||
#include <unistd.h> | ||
|
||
uint64 QueryRamUsage() | ||
{ | ||
static long page_size = sysconf(_SC_PAGESIZE); | ||
if (page_size == -1) | ||
{ | ||
return 0; | ||
} | ||
|
||
std::ifstream file("/proc/self/statm"); | ||
if (file) | ||
{ | ||
file.ignore(std::numeric_limits<std::streamsize>::max(), ' '); | ||
uint64 pages; | ||
file >> pages; | ||
|
||
return pages * page_size; | ||
} | ||
return 0; | ||
} | ||
|
||
void QueryCoreTimes(uint32 count, std::vector<ProcessorTime>& out) | ||
{ | ||
std::ifstream file("/proc/stat"); | ||
if (file) | ||
{ | ||
file.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); | ||
|
||
for (auto i = 0; i < out.size(); ++i) | ||
{ | ||
uint64 user, nice, kernel, idle; | ||
file.ignore(std::numeric_limits<std::streamsize>::max(), ' '); | ||
file >> user >> nice >> kernel >> idle; | ||
file.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); | ||
|
||
out[i].idle = idle; | ||
out[i].kernel = kernel; | ||
out[i].user = user + nice; | ||
} | ||
} | ||
else | ||
{ | ||
for (auto i = 0; i < count; ++i) out[i] = { }; | ||
} | ||
} |
Oops, something went wrong.