|
30 | 30 | _temp_home_dir = None |
31 | 31 |
|
32 | 32 |
|
| 33 | +class UnknownPlatformError(Exception): |
| 34 | + """Exception raised for unknown platforms.""" |
| 35 | + |
| 36 | + |
33 | 37 | def set_cache_dir(cache_dir): |
34 | 38 | """Set the directory to be used for temporary file storage. |
35 | 39 |
|
@@ -605,6 +609,47 @@ def _get_gpu_info(): |
605 | 609 | return out |
606 | 610 |
|
607 | 611 |
|
| 612 | +def _get_total_memory(): |
| 613 | + """Return the total memory of the system in bytes.""" |
| 614 | + if platform.system() == "Windows": |
| 615 | + o = subprocess.check_output( |
| 616 | + [ |
| 617 | + "powershell.exe", |
| 618 | + "(Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory", |
| 619 | + ] |
| 620 | + ).decode() |
| 621 | + total_memory = int(o) |
| 622 | + elif platform.system() == "Linux": |
| 623 | + o = subprocess.check_output(["free", "-b"]).decode() |
| 624 | + total_memory = int(o.splitlines()[1].split()[1]) |
| 625 | + elif platform.system() == "Darwin": |
| 626 | + o = subprocess.check_output(["sysctl", "hw.memsize"]).decode() |
| 627 | + total_memory = int(o.split(":")[1].strip()) |
| 628 | + else: |
| 629 | + raise UnknownPlatformError("Could not determine total memory") |
| 630 | + |
| 631 | + return total_memory |
| 632 | + |
| 633 | + |
| 634 | +def _get_cpu_brand(): |
| 635 | + """Return the CPU brand string.""" |
| 636 | + if platform.system() == "Windows": |
| 637 | + o = subprocess.check_output( |
| 638 | + ["powershell.exe", "(Get-CimInstance Win32_Processor).Name"] |
| 639 | + ).decode() |
| 640 | + cpu_brand = o.strip().splitlines()[-1] |
| 641 | + elif platform.system() == "Linux": |
| 642 | + o = subprocess.check_output(["grep", "model name", "/proc/cpuinfo"]).decode() |
| 643 | + cpu_brand = o.splitlines()[0].split(": ")[1] |
| 644 | + elif platform.system() == "Darwin": |
| 645 | + o = subprocess.check_output(["sysctl", "machdep.cpu"]).decode() |
| 646 | + cpu_brand = o.split("brand_string: ")[1].strip() |
| 647 | + else: |
| 648 | + cpu_brand = "?" |
| 649 | + |
| 650 | + return cpu_brand |
| 651 | + |
| 652 | + |
608 | 653 | def sys_info( |
609 | 654 | fid=None, |
610 | 655 | show_paths=False, |
@@ -656,15 +701,20 @@ def sys_info( |
656 | 701 | out("Platform".ljust(ljust) + platform_str + "\n") |
657 | 702 | out("Python".ljust(ljust) + str(sys.version).replace("\n", " ") + "\n") |
658 | 703 | out("Executable".ljust(ljust) + sys.executable + "\n") |
659 | | - out("CPU".ljust(ljust) + f"{platform.processor()} ") |
| 704 | + try: |
| 705 | + cpu_brand = _get_cpu_brand() |
| 706 | + except Exception: |
| 707 | + cpu_brand = "?" |
| 708 | + out("CPU".ljust(ljust) + f"{cpu_brand} ") |
660 | 709 | out(f"({multiprocessing.cpu_count()} cores)\n") |
661 | 710 | out("Memory".ljust(ljust)) |
662 | 711 | try: |
663 | | - import psutil |
664 | | - except ImportError: |
665 | | - out('Unavailable (requires "psutil" package)') |
| 712 | + total_memory = _get_total_memory() |
| 713 | + except UnknownPlatformError: |
| 714 | + total_memory = "?" |
666 | 715 | else: |
667 | | - out(f"{psutil.virtual_memory().total / float(2 ** 30):0.1f} GB\n") |
| 716 | + total_memory = f"{total_memory / 1024**3:.1f}" # convert to GiB |
| 717 | + out(f"{total_memory} GiB\n") |
668 | 718 | out("\n") |
669 | 719 | ljust -= 3 # account for +/- symbols |
670 | 720 | libs = _get_numpy_libs() |
|
0 commit comments