
    /j                        d dl mZ d dlZd dlZd dlZd dlZd dlmZ  G d d          Ze	dk    r e
e                                           dS dS )    )annotationsN)Pathc                  J    e Zd ZdZed	d            Zed
d            Zd	dZdS )CPUInfoa  Provide cross-platform CPU brand and model information.

    Query platform-specific sources to retrieve a human-readable CPU descriptor and normalize it for consistent
    presentation across macOS, Linux, and Windows. If platform-specific probing fails, generic platform identifiers are
    used to ensure a stable string is always returned.

    Methods:
        name: Return the normalized CPU name using platform-specific sources with robust fallbacks.
        _clean: Normalize and prettify common vendor brand strings and frequency patterns.
        __str__: Return the normalized CPU name for string contexts.

    Examples:
        >>> CPUInfo.name()
        'Apple M4 Pro'
        >>> str(CPUInfo())
        'Intel Core i7-9750H 2.60GHz'
    returnstrc                    	 t           j        dk    rNt          j        g ddd          j                                        } | rt                              |           S nRt           j                            d          rt          d          }|
                                re|                    d                                          D ]<}d	|v r6t                              |                    d
d          d                   c S =nt           j                            d          r	 ddl}|                    |j        d          5 }|                    |d          \  }}|r&t                              |          cddd           S 	 ddd           n# 1 swxY w Y   n# t$          $ r Y nw xY wt          j                    p4t)          t          j                    dd          pt          j                    } t                              | pd          S # t$          $ rG t          j                    pt          j                    pd} t                              | pd          cY S w xY w)zDReturn a normalized CPU model string from platform-specific sources.darwin)sysctlz-nzmachdep.cpu.brand_stringT)capture_outputtextlinuxz/proc/cpuinfoignore)errorsz
model name:   winr   Nz.HARDWARE\DESCRIPTION\System\CentralProcessor\0ProcessorNameString	processor zUnknown CPU)sysplatform
subprocessrunstdoutstripr   _clean
startswithr   exists	read_text
splitlinessplitwinregOpenKeyHKEY_LOCAL_MACHINEQueryValueEx	Exceptionr   getattrunamemachine)splinewrkval_s          Z/home/longshao/multi-rider-rag/.venv/lib/python3.11/site-packages/ultralytics/utils/cpu.pynamezCPUInfo.name   s    	6|x''N@@@QU\`     -">>!,,,-((11 ))88:: I !8 < < G G I I I I'4//#*>>$**S!2D2DQ2G#H#HHHH 0((// 
	''''B$9;lmm 7qr!#4I!J!JQ 7#*>>##6#67 7 7 7 7 7 7 777 7 7 7 7 7 7 7 7 7 7 7 7 7 7 !   D "$$h0@0@+r(R(RhV^VfVhVhA>>!"4}555 	6 	6 	6"$$@(8(:(:@bA>>!"4}55555	6so   AH B'H !H (F" 5F<F" 
F" FF" FF" !H "
F/,H .F//A&H AI'&I'r+   c                Z   t          j        dd|                                           } |                     dd                              dd                              dd                              dd                                          } t          j        d| t           j                  x}r-|                    d	           d|                    d
           S t          j        d| t           j                  x}r-|                    d	           d|                    d
           S | S )z3Normalize and prettify a raw CPU descriptor string.z\s+ z(TM)r   z(tm)z(R)z(r)z%(Intel.*?i\d[\w-]*) CPU @ ([\d.]+GHz)r      z((AMD.*?Ryzen.*?[\w-]*) CPU @ ([\d.]+GHz))resubr   replacesearchIgroup)r+   ms     r2   r   zCPUInfo._cleanD   s    F63		**IIfb!!))&"55==eRHHPPQVXZ[[aacc	BArtLLL1 	0ggajj//1771::///	Eq"$OOO1 	0ggajj//1771::///    c                *    |                                  S )zReturn the normalized CPU name.)r3   )selfs    r2   __str__zCPUInfo.__str__O   s    yy{{r>   N)r   r   )r+   r   r   r   )__name__
__module____qualname____doc__staticmethodr3   r   rA    r>   r2   r   r      ss         $ "6 "6 "6 \"6H    \     r>   r   __main__)
__future__r   r   r7   r   r   pathlibr   r   rB   printr3   rG   r>   r2   <module>rL      s    # " " " " "  				     



      E E E E E E E EP z	E',,.. r>   