doc.odin 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. */
  12. //+build ignore
  13. package sysinfo
  14. import "core:fmt"
  15. import si "core:sys/info"
  16. main :: proc() {
  17. fmt.printf("Odin: %v\n", ODIN_VERSION)
  18. fmt.printf("OS: %v\n", si.os_version.as_string)
  19. fmt.printf("OS: %#v\n", si.os_version)
  20. fmt.printf("CPU: %v\n", si.cpu_name)
  21. fmt.printf("RAM: %v MiB\n", si.ram.total_ram / 1024 / 1024)
  22. fmt.println()
  23. for gpu, i in si.gpus {
  24. fmt.printf("GPU #%v:\n", i)
  25. fmt.printf("\tVendor: %v\n", gpu.vendor_name)
  26. fmt.printf("\tModel: %v\n", gpu.model_name)
  27. fmt.printf("\tVRAM: %v MiB\n", gpu.total_ram / 1024 / 1024)
  28. }
  29. }
  30. /*
  31. Example Windows output:
  32. Odin: dev-2022-09
  33. OS: Windows 10 Professional (version: 20H2), build: 19042.1466
  34. OS: OS_Version{
  35. platform = "Windows",
  36. major = 10,
  37. minor = 0,
  38. patch = 0,
  39. build = [
  40. 19042,
  41. 1466,
  42. ],
  43. version = "20H2",
  44. as_string = "Windows 10 Professional (version: 20H2), build: 19042.1466",
  45. }
  46. CPU: AMD Ryzen 7 1800X Eight-Core Processor
  47. RAM: 65469 MiB
  48. GPU #0:
  49. Vendor: Advanced Micro Devices, Inc.
  50. Model: Radeon RX Vega
  51. VRAM: 8176 MiB
  52. Example macOS output:
  53. ODIN: dev-2022-09
  54. OS: OS_Version{
  55. platform = "MacOS",
  56. major = 21,
  57. minor = 5,
  58. patch = 0,
  59. build = [
  60. 0,
  61. 0,
  62. ],
  63. version = "21F79",
  64. as_string = "macOS Monterey 12.4 (build 21F79, kernel 21.5.0)",
  65. }
  66. CPU: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
  67. RAM: 8192 MiB
  68. */