mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-06-18 00:27:02 +08:00
Compare commits
2 Commits
b07adea771
...
68e062faa1
| Author | SHA1 | Date | |
|---|---|---|---|
| 68e062faa1 | |||
| 2f1edc4723 |
@@ -87,4 +87,58 @@ inline size_t get_current_rss() {
|
||||
#endif
|
||||
}
|
||||
|
||||
inline std::string get_cpu_info() {
|
||||
#ifdef _WIN32
|
||||
HKEY h_key;
|
||||
std::string cpu_name;
|
||||
|
||||
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
||||
L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
|
||||
0, KEY_READ, &h_key) == ERROR_SUCCESS) {
|
||||
|
||||
DWORD dw_size = 0;
|
||||
if (RegQueryValueExW(h_key, L"ProcessorNameString", NULL, NULL, NULL, &dw_size) == ERROR_SUCCESS && dw_size > 0) {
|
||||
std::vector<wchar_t> buffer(dw_size / sizeof(wchar_t));
|
||||
if (RegQueryValueExW(h_key, L"ProcessorNameString", NULL, NULL, (LPBYTE)buffer.data(), &dw_size) == ERROR_SUCCESS) {
|
||||
int len = WideCharToMultiByte(CP_UTF8, 0, buffer.data(), -1, NULL, 0, NULL, NULL);
|
||||
if (len > 0) {
|
||||
std::vector<char> narrow(len);
|
||||
WideCharToMultiByte(CP_UTF8, 0, buffer.data(), -1, narrow.data(), len, NULL, NULL);
|
||||
cpu_name = narrow.data();
|
||||
}
|
||||
}
|
||||
}
|
||||
RegCloseKey(h_key);
|
||||
}
|
||||
if (cpu_name.empty()) {
|
||||
cpu_name = "Unknown";
|
||||
}
|
||||
return cpu_name;
|
||||
#elif defined (__linux__)
|
||||
std::ifstream file("/proc/cpuinfo");
|
||||
if (!file.is_open()) {
|
||||
return std::string{"Unkown"};
|
||||
}
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
size_t pos = line.find(":");
|
||||
if (pos == std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
std::string key = line.substr(0, pos - 1);
|
||||
key = key.erase(key.find_last_not_of(" \t\n") + 1);
|
||||
if (key != "model name") {
|
||||
continue;
|
||||
}
|
||||
return line.substr(pos + 2);
|
||||
}
|
||||
return std::string{"Unkown"};
|
||||
#else
|
||||
return std::string{"Unkown"};
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ public:
|
||||
Text& operator=(Text&&) noexcept = delete;
|
||||
Text& color(Color color);
|
||||
//Text& color(const glm::vec4& color, int pos);
|
||||
Text& name(std::string_view name);
|
||||
Text& position(float x, float y);
|
||||
Text& scale(float s);
|
||||
Text& text(std::string_view str);
|
||||
|
||||
@@ -18,6 +18,9 @@ void DebugCollector::init_text() {
|
||||
Text player_pos_text("player_pos");
|
||||
Text rendered_chunk_text("rendered_chunk");
|
||||
Text rss_text("rss");
|
||||
Text cpu_text("cpu");
|
||||
Text gpu_text("gpu");
|
||||
Text opengl_version_text("opengl_version");
|
||||
version_text
|
||||
.position(0.0f, 100.0f)
|
||||
.scale(0.8f)
|
||||
@@ -53,12 +56,27 @@ void DebugCollector::init_text() {
|
||||
.text("OS: Unknown");
|
||||
|
||||
}
|
||||
cpu_text
|
||||
.text("CPU: " + Tools::get_cpu_info())
|
||||
.scale(0.7f)
|
||||
.position(0.0f, 350.0f);
|
||||
gpu_text
|
||||
.text(std::string{"GPU: "} + reinterpret_cast<const char*>(glGetString(GL_RENDERER)))
|
||||
.scale(0.7f)
|
||||
.position(0.0f, 400.0f);
|
||||
opengl_version_text
|
||||
.text("OpenGL: " + std::to_string(GLVersion.major) + "." + std::to_string(GLVersion.minor))
|
||||
.scale(0.7f)
|
||||
.position(0.0f, 450.0f);
|
||||
m_texts.insert({version_text.uuid(), std::move(version_text)});
|
||||
m_texts.insert({fps_text.uuid(), std::move(fps_text)});
|
||||
m_texts.insert({player_pos_text.uuid(), std::move(player_pos_text)});
|
||||
m_texts.insert({rendered_chunk_text.uuid(), std::move(rendered_chunk_text)});
|
||||
m_texts.insert({os_text.uuid(), std::move(os_text)});
|
||||
m_texts.insert({rss_text.uuid(), std::move(rss_text)});
|
||||
m_texts.insert({cpu_text.uuid(), std::move(cpu_text)});
|
||||
m_texts.insert({gpu_text.uuid(), std::move(gpu_text)});
|
||||
m_texts.insert({opengl_version_text.uuid(), std::move(opengl_version_text)});
|
||||
}
|
||||
|
||||
std::unordered_map<std::size_t, Text>& DebugCollector::all_texts() {
|
||||
|
||||
Reference in New Issue
Block a user