doc.odin 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. Gathers system information on `Windows`, `Linux`, `macOS`, `FreeBSD` & `OpenBSD`.
  3. Simply import the package and you'll have access to the OS version, RAM amount
  4. and CPU information.
  5. On Windows, GPUs will also be enumerated using the registry.
  6. CPU feature flags can be tested against `cpu_features`, where applicable, e.g.
  7. `if .aes in info.cpu_features.? { ... }`
  8. Example:
  9. package main
  10. import "core:fmt"
  11. import si "core:sys/info"
  12. main :: proc() {
  13. fmt.printfln("Odin: %v", ODIN_VERSION)
  14. fmt.printfln("OS: %v", si.os_version.as_string)
  15. fmt.printfln("OS: %#v", si.os_version)
  16. fmt.printfln("CPU: %v", si.cpu.name)
  17. fmt.printfln("CPU cores: %vc/%vt", si.cpu.physical_cores, si.cpu.logical_cores)
  18. fmt.printfln("RAM: %#.1M", si.ram.total_ram)
  19. fmt.println()
  20. for gpu, i in si.gpus {
  21. fmt.printfln("GPU #%v:", i)
  22. fmt.printfln("\tVendor: %v", gpu.vendor_name)
  23. fmt.printfln("\tModel: %v", gpu.model_name)
  24. fmt.printfln("\tVRAM: %#.1M", gpu.total_ram)
  25. }
  26. }
  27. - Example Windows output:
  28. Odin: dev-2025-10
  29. OS: Windows 10 Professional (version: 22H2), build: 19045.6396
  30. OS: OS_Version{
  31. platform = "Windows",
  32. _ = Version{
  33. major = 10,
  34. minor = 0,
  35. patch = 0,
  36. },
  37. build = [
  38. 19045,
  39. 6396,
  40. ],
  41. version = "22H2",
  42. as_string = "Windows 10 Professional (version: 22H2), build: 19045.6396",
  43. }
  44. CPU: AMD Ryzen 9 5950X 16-Core Processor
  45. CPU cores: 16c/32t
  46. RAM: 63.9 GiB
  47. GPU #0:
  48. Vendor: Advanced Micro Devices, Inc.
  49. Model: AMD Radeon RX 9070
  50. VRAM: 15.9 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
  69. /*
  70. Copyright 2022 Jeroen van Rijn <[email protected]>.
  71. Made available under Odin's BSD-3 license.
  72. List of contributors:
  73. Jeroen van Rijn: Initial implementation.
  74. Laytan: ARM and RISC-V CPU feature detection, iOS/macOS platform overhaul.
  75. */