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

Extended RuntimeInfo #1230

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion core/include/mmcore/utility/graphics/ScreenShotComments.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include <png.h>

#include "RuntimeInfo.h"

namespace megamol::core::utility::graphics {

class ScreenShotComments {
Expand All @@ -26,7 +28,7 @@ class ScreenShotComments {
* constructor and later get out the png_text you need for feeding libpng. Note that the returned png_text array
* is only valid as long as the ScreenShotComments instance is in scope!
*/
ScreenShotComments(std::string const& project_configuration,
ScreenShotComments(std::string const& project_configuration, megamol::frontend_resources::RuntimeInfo const* ri,
const std::optional<comments_storage_map>& additional_comments = std::nullopt);

png_comments GetComments() const;
Expand Down
48 changes: 48 additions & 0 deletions core/include/mmcore/utility/platform/RuntimeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
#pragma once

#include <mutex>
#include <string>

#include "WMIUtil.h"
Expand All @@ -15,25 +16,60 @@ class RuntimeInfo {
public:
static std::string GetHardwareInfo() {
if (m_hardware_info.empty()) {
std::lock_guard<std::mutex> lock(write_mtx_);
get_hardware_info();
}
return m_hardware_info;
}

static std::string GetOsInfo() {
if (m_os_info.empty()) {
std::lock_guard<std::mutex> lock(write_mtx_);
get_os_info();
}
return m_os_info;
}

static std::string GetRuntimeLibraries() {
if (m_runtime_libraries.empty()) {
std::lock_guard<std::mutex> lock(write_mtx_);
get_runtime_libraries();
}
return m_runtime_libraries;
}

static std::string GetSMBIOSInfo() {
if (smbios_.empty()) {
std::lock_guard<std::mutex> lock(write_mtx_);
get_smbios_info();
}
return smbios_;
}

static std::string GetCPUInfo() {
if (cpu_.empty()) {
std::lock_guard<std::mutex> lock(write_mtx_);
get_cpu_info();
}
return cpu_;
}

static std::string GetGPUInfo() {
if (gpu_.empty()) {
std::lock_guard<std::mutex> lock(write_mtx_);
get_gpu_info();
}
return gpu_;
}

static std::string GetOSInfo() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference to GetOsInfo, do we really need this twice or can one be removed?

if (os_.empty()) {
std::lock_guard<std::mutex> lock(write_mtx_);
get_OS_info();
}
return os_;
}


private:
static void get_hardware_info();
Expand All @@ -45,6 +81,18 @@ class RuntimeInfo {
inline static std::string m_os_info;
inline static std::string m_hardware_info;

static void get_smbios_info(bool serial = false);
static void get_cpu_info();
static void get_gpu_info();
static void get_OS_info();

inline static std::string smbios_;
inline static std::string cpu_;
inline static std::string gpu_;
inline static std::string os_;

inline static std::mutex write_mtx_;

#ifdef _WIN32
inline static WMIUtil wmi;
#endif
Expand Down
7 changes: 5 additions & 2 deletions core/include/mmcore/utility/platform/WMIUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#ifdef _WIN32

#include <iostream>
#include <wil/com.h>

#define _WIN32_DCOM
#include <Wbemidl.h>
Expand All @@ -27,8 +28,10 @@ class WMIUtil {
std::string get_value(const std::string& wmi_class, const std::string& attribute);

private:
IWbemLocator* locator = nullptr;
IWbemServices* service = nullptr;
//IWbemLocator* locator = nullptr;
//IWbemServices* service = nullptr;
wil::com_ptr<IWbemServices> service;
//wil::unique_couninitialize_call cleanup;
};
} // namespace megamol::core::utility::platform

Expand Down
14 changes: 9 additions & 5 deletions core/src/utility/graphics/ScreenShotComments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@

namespace mcu_graphics = megamol::core::utility::graphics;

mcu_graphics::ScreenShotComments::ScreenShotComments(
std::string const& project_configuration, const std::optional<comments_storage_map>& additional_comments) {
mcu_graphics::ScreenShotComments::ScreenShotComments(std::string const& project_configuration,
megamol::frontend_resources::RuntimeInfo const* ri,
const std::optional<comments_storage_map>& additional_comments) {

the_comments["Title"] = "MegaMol Screen Capture " + utility::DateTime::CurrentDateTimeFormatted();
//the_comments["Author"] = "";
Expand All @@ -34,11 +35,14 @@ mcu_graphics::ScreenShotComments::ScreenShotComments(

the_comments["Remote Branch"] = megamol::core::utility::buildinfo::MEGAMOL_GIT_BRANCH_NAME_FULL();
the_comments["Remote URL"] = megamol::core::utility::buildinfo::MEGAMOL_GIT_REMOTE_URL();
the_comments["Software Environment"] = platform::RuntimeInfo::GetRuntimeLibraries();
the_comments["Hardware Environment"] = platform::RuntimeInfo::GetHardwareInfo();
the_comments["CMakeCache"] = megamol::core::utility::buildinfo::MEGAMOL_CMAKE_CACHE();
the_comments["Git Diff"] = megamol::core::utility::buildinfo::MEGAMOL_GIT_DIFF();
the_comments["Operating System"] = platform::RuntimeInfo::GetOsInfo();

if (ri) {
the_comments["Hardware Environment"] = ri->get_hardware_info();
the_comments["Operating System"] = ri->get_os_info();
the_comments["Software Environment"] = ri->get_runtime_libraries();
}

//the_comments["Disclaimer"] = "";
//the_comments["Warning"] = "";
Expand Down
183 changes: 136 additions & 47 deletions core/src/utility/platform/RuntimeInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,73 +117,79 @@ std::vector<std::string> dlinfo_linkmap(void* handle) {
} // namespace

void megamol::core::utility::platform::RuntimeInfo::get_hardware_info() {
if (m_hardware_info.empty()) {
#ifdef _WIN32
//m_hardware_info = execute("systeminfo");
std::stringstream s;
s << "{" << std::endl;
s << R"("Processor Name":")" << wmi.get_value("Win32_Processor", "Name") << "\"," << std::endl;
s << R"("Processor Version":")" << wmi.get_value("Win32_Processor", "Version") << "\"," << std::endl;
s << R"("GPU Name":")" << wmi.get_value("Win32_VideoController", "Name") << "\"," << std::endl;
s << R"("OS Name":")" << wmi.get_value("Win32_OperatingSystem", "Name") << "\"," << std::endl;
s << R"("OS Version":")" << wmi.get_value("Win32_OperatingSystem", "Version") << "\"," << std::endl;
s << R"("OS Architecture":")" << wmi.get_value("Win32_OperatingSystem", "OSArchitecture") << "\"," << std::endl;
s << R"("Available Memory":")" << wmi.get_value("Win32_OperatingSystem", "TotalVisibleMemorySize") << "\""
<< std::endl;
s << "}";
m_hardware_info = s.str();
//m_hardware_info = execute("systeminfo");
std::stringstream s;
s << "{" << std::endl;
s << R"("Processor Name":")" << wmi.get_value("Win32_Processor", "Name") << "\"," << std::endl;
s << R"("Processor Version":")" << wmi.get_value("Win32_Processor", "Version") << "\"," << std::endl;
s << R"("GPU Name":")" << wmi.get_value("Win32_VideoController", "Name") << "\"," << std::endl;
s << R"("OS Name":")" << wmi.get_value("Win32_OperatingSystem", "Name") << "\"," << std::endl;
s << R"("OS Version":")" << wmi.get_value("Win32_OperatingSystem", "Version") << "\"," << std::endl;
s << R"("OS Architecture":")" << wmi.get_value("Win32_OperatingSystem", "OSArchitecture") << "\"," << std::endl;
s << R"("Available Memory":")" << wmi.get_value("Win32_OperatingSystem", "TotalVisibleMemorySize") << "\""
<< std::endl;
s << "}";
m_hardware_info = s.str();
#else
m_hardware_info = execute("cat /proc/cpuinfo /proc/meminfo");
m_hardware_info = execute("cat /proc/cpuinfo /proc/meminfo");
#endif
}
}

void megamol::core::utility::platform::RuntimeInfo::get_runtime_libraries() {
if (m_runtime_libraries.empty()) {
#ifdef _WIN32
HANDLE h_mod_snap = INVALID_HANDLE_VALUE;
h_mod_snap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId());
if (h_mod_snap != INVALID_HANDLE_VALUE) {
std::stringstream out;
MODULEENTRY32 me32;
me32.dwSize = sizeof(MODULEENTRY32);
if (Module32First(h_mod_snap, &me32)) {
do {
out << me32.szExePath << " (";
out << get_file_version(me32.szExePath) << ")" << std::endl;
} while (Module32Next(h_mod_snap, &me32));
HANDLE h_mod_snap = INVALID_HANDLE_VALUE;
h_mod_snap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId());
if (h_mod_snap != INVALID_HANDLE_VALUE) {
std::stringstream out;
MODULEENTRY32 me32;
me32.dwSize = sizeof(MODULEENTRY32);
if (Module32First(h_mod_snap, &me32)) {
do {
out << me32.szExePath << " (";
out << get_file_version(me32.szExePath) << ")" << std::endl;
} while (Module32Next(h_mod_snap, &me32));
}
CloseHandle(h_mod_snap);
m_runtime_libraries = out.str();
} else {
m_runtime_libraries = "";
}
CloseHandle(h_mod_snap);
m_runtime_libraries = out.str();
} else {
m_runtime_libraries = "";
}
#else
void* handle = dlopen(nullptr, RTLD_NOW);
void* handle = dlopen(nullptr, RTLD_NOW);

// TODO looks like all library paths are already absolute, do we need search paths here?
// const auto paths = dlinfo_search_path(handle);
// TODO looks like all library paths are already absolute, do we need search paths here?
// const auto paths = dlinfo_search_path(handle);

const auto list = dlinfo_linkmap(handle);
const auto list = dlinfo_linkmap(handle);

std::stringstream out;
for (const auto& lib : list) {
out << lib;
// If the library is a symlink, print link target to get the filename with the full version number.
std::filesystem::path p(lib);
if (std::filesystem::is_symlink(p)) {
p = std::filesystem::canonical(p);
out << " (=> " << p.string() << ")";
std::stringstream out;
for (const auto& lib : list) {
out << lib;
// If the library is a symlink, print link target to get the filename with the full version number.
std::filesystem::path p(lib);
if (std::filesystem::is_symlink(p)) {
p = std::filesystem::canonical(p);
out << " (=> " << p.string() << ")";
}
out << std::endl;
}
out << std::endl;
}
m_runtime_libraries = out.str();
m_runtime_libraries = out.str();
#endif
}
}

void megamol::core::utility::platform::RuntimeInfo::get_os_info() {
if (m_os_info.empty()) {
#ifdef _WIN32
m_os_info = execute("ver");
m_os_info = execute("ver");
#else
m_os_info = execute("cat /etc/issue");
m_os_info = execute("cat /etc/issue");
#endif
}
}


Expand All @@ -209,3 +215,86 @@ std::string megamol::core::utility::platform::RuntimeInfo::execute(const std::st
return "unable to execute " + cmd;
}
}


void megamol::core::utility::platform::RuntimeInfo::get_smbios_info(bool serial) {
if (smbios_.empty()) {
#ifdef _WIN32
std::stringstream s;
s << "{" << std::endl;
s << R"("Manufacturer":")" << wmi.get_value("Win32_BaseBoard", "Manufacturer") << "\"," << std::endl;
s << R"("Product":")" << wmi.get_value("Win32_BaseBoard", "Product") << "\"," << std::endl;
s << R"("Version":")" << wmi.get_value("Win32_BaseBoard", "Version") << "\"," << std::endl;
if (serial)
s << R"("SerialNumber":")" << wmi.get_value("Win32_BaseBoard", "SerialNumber") << "\"," << std::endl;
s << "}";
smbios_ = s.str();
#else
smbios_ = "SMBIOS info not available";
#endif
}
}


void megamol::core::utility::platform::RuntimeInfo::get_cpu_info() {
if (cpu_.empty()) {
#ifdef _WIN32
std::stringstream s;
s << "{" << std::endl;
s << R"("Manufacturer":")" << wmi.get_value("Win32_Processor", "Manufacturer") << "\"," << std::endl;
s << R"("Name":")" << wmi.get_value("Win32_Processor", "Name") << "\"," << std::endl;
s << R"("ProcessorId":")" << wmi.get_value("Win32_Processor", "ProcessorId") << "\"," << std::endl;
s << R"("NumberOfCores":")" << wmi.get_value("Win32_Processor", "NumberOfCores") << "\"," << std::endl;
s << R"("NumberOfLogicalProcessors":")" << wmi.get_value("Win32_Processor", "NumberOfLogicalProcessors")
<< "\"," << std::endl;
s << R"("AvailableRam":")" << wmi.get_value("Win32_OperatingSystem", "TotalVisibleMemorySize") << "\","
<< std::endl;
s << "}";
cpu_ = s.str();
#else
cpu_ = execute("cat /proc/cpuinfo /proc/meminfo");
#endif
}
}


void megamol::core::utility::platform::RuntimeInfo::get_gpu_info() {
if (gpu_.empty()) {
#ifdef _WIN32
std::stringstream s;
s << "{" << std::endl;
s << R"("Name":")" << wmi.get_value("Win32_VideoController", "Name") << "\"," << std::endl;
s << R"("DriverVersion":")" << wmi.get_value("Win32_VideoController", "DriverVersion") << "\"," << std::endl;
s << R"("AdapterRam":")" << wmi.get_value("Win32_VideoController", "AdapterRam") << "\"," << std::endl;
s << "}";
gpu_ = s.str();
#else
gpu_ = "GPU info not available";
#endif
}
}


void megamol::core::utility::platform::RuntimeInfo::get_OS_info() {
if (os_.empty()) {
#ifdef _WIN32
std::stringstream s;
s << "{" << std::endl;
s << R"("Name":")" << wmi.get_value("Win32_ComputerSystem", "Name") << "\"," << std::endl;
s << R"("OSName":")" << wmi.get_value("Win32_OperatingSystem", "Name") << "\"," << std::endl;
s << R"("Manufacturer":")" << wmi.get_value("Win32_OperatingSystem", "Manufacturer") << "\"," << std::endl;
s << R"("Version":")" << wmi.get_value("Win32_OperatingSystem", "Version") << "\"," << std::endl;
s << R"("OSArchitecture":")" << wmi.get_value("Win32_OperatingSystem", "OSArchitecture") << "\"," << std::endl;
s << "}";
os_ = s.str();
#else
std::stringstream s;
s << "{" << std::endl;
s << R"("Name":")" << execute("cat /proc/sys/kernel/hostname") << "\"," << std::endl;
s << R"("OSName":")" << execute("cat /etc/issue") << "\"," << std::endl;
s << R"("Version":")" << execute("cat /proc/sys/kernel/osrelease") << "\"," << std::endl;
s << "}";
os_ = s.str();
#endif
}
}
Loading
Loading