doc.odin 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. Copyright 2022 Jeroen van Rijn <[email protected]>.
  3. Made available under Odin's BSD-3 license.
  4. Package `core:sys/info` gathers system information on:
  5. Windows, Linux, macOS, FreeBSD & OpenBSD.
  6. Simply import the package and you'll have access to the OS version, RAM amount
  7. and CPU information.
  8. On Windows, GPUs will also be enumerated using the registry.
  9. CPU feature flags can be tested against `cpu_features`, where applicable, e.g.
  10. `if .aes in si.aes { ... }`
  11. Example:
  12. import "core:fmt"
  13. import si "core:sys/info"
  14. main :: proc() {
  15. fmt.printfln("Odin: %v", ODIN_VERSION)
  16. fmt.printfln("OS: %v", si.os_version.as_string)
  17. fmt.printfln("OS: %#v", si.os_version)
  18. fmt.printfln("CPU: %v", si.cpu_name)
  19. fmt.printfln("RAM: %#.1M", si.ram.total_ram)
  20. // fmt.printfln("Features: %v", si.cpu_features)
  21. // fmt.printfln("MacOS version: %v", si.macos_version)
  22. fmt.println()
  23. for gpu, i in si.gpus {
  24. fmt.printfln("GPU #%v:", i)
  25. fmt.printfln("\tVendor: %v", gpu.vendor_name)
  26. fmt.printfln("\tModel: %v", gpu.model_name)
  27. fmt.printfln("\tVRAM: %#.1M", gpu.total_ram)
  28. }
  29. }
  30. - Example Windows output:
  31. Odin: dev-2022-09
  32. OS: Windows 10 Professional (version: 20H2), build: 19042.1466
  33. OS: OS_Version{
  34. platform = "Windows",
  35. major = 10,
  36. minor = 0,
  37. patch = 0,
  38. build = [
  39. 19042,
  40. 1466,
  41. ],
  42. version = "20H2",
  43. as_string = "Windows 10 Professional (version: 20H2), build: 19042.1466",
  44. }
  45. CPU: AMD Ryzen 7 1800X Eight-Core Processor
  46. RAM: 64.0 GiB
  47. GPU #0:
  48. Vendor: Advanced Micro Devices, Inc.
  49. Model: Radeon RX Vega
  50. VRAM: 8.0 GiB
  51. - Example macOS output:
  52. ODIN: dev-2022-09
  53. OS: OS_Version{
  54. platform = "MacOS",
  55. major = 21,
  56. minor = 5,
  57. patch = 0,
  58. build = [
  59. 0,
  60. 0,
  61. ],
  62. version = "21F79",
  63. as_string = "macOS Monterey 12.4 (build 21F79, kernel 21.5.0)",
  64. }
  65. CPU: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
  66. RAM: 8.0 GiB
  67. */
  68. package sysinfo