Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
system.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <cstdint>
5#include <cstdlib>
6#include <cstring>
7#include <ctime>
8#include <optional>
9#include <string>
10#include <string_view>
11
12namespace pulp::runtime {
13
14inline std::optional<std::string> get_env(std::string_view name) {
15 std::string key{name};
16#ifdef _WIN32
17 char* value = nullptr;
18 size_t size = 0;
19 if (_dupenv_s(&value, &size, key.c_str()) != 0 || value == nullptr)
20 return std::nullopt;
21
22 std::string result(value);
23 std::free(value);
24 if (result.empty()) return std::nullopt;
25 return result;
26#else
27 if (const char* value = std::getenv(key.c_str()); value && *value)
28 return std::string(value);
29 return std::nullopt;
30#endif
31}
32
33inline std::tm gmtime_utc(std::time_t value) {
34 std::tm out{};
35#ifdef _WIN32
36 gmtime_s(&out, &value);
37#else
38 if (gmtime_r(&value, &out) == nullptr)
39 out = {};
40#endif
41 return out;
42}
43
44inline std::tm localtime_local(std::time_t value) {
45 std::tm out{};
46#ifdef _WIN32
47 localtime_s(&out, &value);
48#else
49 if (localtime_r(&value, &out) == nullptr)
50 out = {};
51#endif
52 return out;
53}
54
55inline void copy_c_string(char* dest, std::size_t dest_size, std::string_view src) {
56 if (dest == nullptr || dest_size == 0) return;
57 const auto count = (std::min)(src.size(), dest_size - 1);
58 std::memcpy(dest, src.data(), count);
59 dest[count] = '\0';
60}
61
62template <std::size_t N>
63inline void copy_c_string(char (&dest)[N], std::string_view src) {
64 copy_c_string(dest, N, src);
65}
66
67// ── System information ──────────────────────────────────────────────────
68
69struct SystemInfo {
70 std::string os_name; // "macOS", "Windows", "Linux"
71 std::string os_version; // "15.0", "10.0.22621", "6.5.0"
72 std::string cpu_model; // "Apple M2 Pro", "Intel Core i9-13900K"
73 int cpu_cores = 0; // Physical cores
74 int cpu_threads = 0; // Logical threads
75 uint64_t total_memory_mb = 0; // Total RAM in MB
76 std::string arch; // "arm64", "x86_64"
77
78 // Extended CPU features
79 bool has_sse2 = false;
80 bool has_sse4_1 = false;
81 bool has_avx = false;
82 bool has_avx2 = false;
83 bool has_avx512 = false;
84 bool has_neon = false; // ARM NEON (always true on arm64)
85 bool has_fma = false; // Fused multiply-add
86
87 // Display info
91 float primary_display_scale = 1.0f; // HiDPI scale factor
92};
93
96
99
102
103} // namespace pulp::runtime
Definition generated_event_source.hpp:33
std::tm gmtime_utc(std::time_t value)
Definition system.hpp:33
const SystemInfo & get_system_info()
Query system information (cached after first call).
std::optional< std::string > get_env(std::string_view name)
Definition system.hpp:14
int cpu_thread_count()
Number of logical CPU threads (convenience).
uint64_t total_memory_mb()
Total physical memory in MB (convenience).
std::tm localtime_local(std::time_t value)
Definition system.hpp:44
void copy_c_string(char *dest, std::size_t dest_size, std::string_view src)
Definition system.hpp:55
Definition system.hpp:69
std::string arch
Definition system.hpp:76
bool has_fma
Definition system.hpp:85
bool has_avx2
Definition system.hpp:82
bool has_sse4_1
Definition system.hpp:80
std::string os_version
Definition system.hpp:71
bool has_avx
Definition system.hpp:81
bool has_avx512
Definition system.hpp:83
uint64_t total_memory_mb
Definition system.hpp:75
int display_count
Definition system.hpp:88
float primary_display_scale
Definition system.hpp:91
std::string os_name
Definition system.hpp:70
int cpu_threads
Definition system.hpp:74
int primary_display_height
Definition system.hpp:90
bool has_neon
Definition system.hpp:84
std::string cpu_model
Definition system.hpp:72
bool has_sse2
Definition system.hpp:79
int cpu_cores
Definition system.hpp:73
int primary_display_width
Definition system.hpp:89