U |f+tR@sdZddlmZddlmZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlmZddl mZddl mZddl mZzdd l mZWnek rdZYnXzdd l mZWnek rdZYnXe jdd kZerddlZndZeed ZeZd ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;dd?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^gRZejd_kZejd`kZ e j!"daZ#e j!"dbZ$e$Z%e j!"dcZ&e j!"ddZ'e j!"deZ(e&p0e'p0e(Z)e j!"dfZ*e j!"dgZ+dhZ,diZ-djZ.dkZ/dlZ0dmZ1dnZ2doZ3dpZ4dqZ5drZ6dsZ7dtZ8duZ9dvZ:dwZ;dxZd{Z?d|Z@d}ZAd~ZBdZCdZDdZEedkrdZFdZGdZHn GdddejIZJeKLeJjMedkrdZNdZOn GdddejIZPeKLePjMe QZRes2dZSn2z e TZSWn$eUk rberZdndZSYnXedHddddddgZVedDddddgZWedBddddddgZXedCddddgZYedEddddddddgZZedIdddddgZ[ed@dddddddgZ\edFdddddgZ]edGdddddgZ^edAddddgZ_eddddgZ`edddddgZaeddddgZbedddgZced8ddddgZded=ddgZeed>dddgZfed?dddgZged:dddgZhed;ddddgZiedddZn ddZe|e jfdd]Zddd\Zdde jfd d^Zd d[ZdS(z9Common objects shared by __init__.py and _ps*.py modules.)division)print_functionN) namedtuple)AF_INET) SOCK_DGRAM) SOCK_STREAM)AF_INET6)AF_UNIX PSUTIL_DEBUGFREEBSDBSDLINUXNETBSDOPENBSDMACOSOSXPOSIXSUNOSWINDOWS CONN_CLOSECONN_CLOSE_WAIT CONN_CLOSINGCONN_ESTABLISHEDCONN_FIN_WAIT1CONN_FIN_WAIT2 CONN_LAST_ACK CONN_LISTEN CONN_NONE CONN_SYN_RECV CONN_SYN_SENTCONN_TIME_WAITNIC_DUPLEX_FULLNIC_DUPLEX_HALFNIC_DUPLEX_UNKNOWN STATUS_DEADSTATUS_DISK_SLEEP STATUS_IDLE STATUS_LOCKEDSTATUS_RUNNINGSTATUS_SLEEPINGSTATUS_STOPPEDSTATUS_SUSPENDEDSTATUS_TRACING_STOPSTATUS_WAITINGSTATUS_WAKE_KILL STATUS_WAKING STATUS_ZOMBIE STATUS_PARKEDENCODING ENCODING_ERRSrpconn pcputimespctxswpgidspiopionice popenfilepthreadpuidssconn scpustatssdiskio sdiskpart sdiskusagesnetiosnicaddr snicstatssswapsuser conn_tmapdeprecated_method isfile_strictmemoizeparse_environ_blockpath_exists_strict usage_percent supports_ipv6sockfam_to_enumsocktype_to_enum wrap_numbers open_text open_binarycatbcat bytes2humanconn_to_ntupledebughiliteterm_supports_colors print_colorposixntlinuxdarwin)ZfreebsdZ midnightbsdZopenbsdZnetbsd)sunossolarisaixrunningsleepingz disk-sleepstoppedz tracing-stopzombieZdeadz wake-killZwakingidlelockedZwaitingZ suspendedZparkedZ ESTABLISHEDZSYN_SENTZSYN_RECVZ FIN_WAIT1Z FIN_WAIT2Z TIME_WAITZCLOSEZ CLOSE_WAITZLAST_ACKZLISTENZCLOSINGNONEc@seZdZdZdZdZdS) NicDuplexrkrlrN)__name__ __module__ __qualname__r"r#r$rqrqA/opt/alt/python38/lib64/python3.8/site-packages/psutil/_common.pyrmsrmc@seZdZdZdZdS) BatteryTimersrtN)rnrorpPOWER_TIME_UNKNOWNPOWER_TIME_UNLIMITEDrqrqrqrrrusrureplacesurrogateescapetotalusedfreepercentsinZsoutZ read_countZ write_count read_bytes write_bytesZ read_timeZ write_timeZdeviceZ mountpointZfstypeoptsZ bytes_sentZ bytes_recvZ packets_sentZ packets_recvZerrinZerroutZdropinZdropoutnameZterminalhoststartedpidfdfamilytypeladdrraddrstatusaddressnetmask broadcastZptpZisupZduplexspeedZmtuflagsZ ctx_switchesZ interruptsZsoft_interruptsZsyscallsscpufreqcurrentminmaxshwtemplabelhighcriticalsbatteryZsecsleftZ power_pluggedsfanusersystem children_userchildren_systempathidZ user_timeZ system_timerealZ effectiveZsavedZioclassvalueZ voluntaryZ involuntaryaddripport)allZtcpZtcp4ZudpZudp4ZinetZinet4Zinet6)Ztcp6Zudp6unixc@s,eZdZdZdZddZddZddZd S) ErrorzQBase exception class. All other psutil exceptions inherit from this one. psutilcCsHt}|D]6}t||d}|r*|||<q |dkr |dkr |||<q |S)Nrr) collections OrderedDictgetattr)selfattrsinforrrqrqrr _infodict$s   zError._infodictcCsP|d}|r,dddd|D}nd}dddt|dd |fDS) N)rppidrz(%s), cSsg|]\}}d||fqSz%s=%rrq.0kvrqrqrr 3sz!Error.__str__.. cSsg|] }|r|qSrqrq)rxrqrqrrr7smsg)rjoinitemsrrrdetailsrqrqrr__str__.s z Error.__str__cCs2|d}ddd|D}d|jj|fS)N)rrrsecondsrrcSsg|]\}}d||fqSrrqrrqrqrrr<sz"Error.__repr__..z psutil.%s(%s))rrr __class__rnrrqrqrr__repr__9s zError.__repr__N)rnrorp__doc__rrrrqrqrqrrrs   rc@s&eZdZdZdZdddZddZdS) NoSuchProcesszXException raised when a process with a certain PID doesn't or no longer exists. rNcCs$t|||_||_|pd|_dS)Nzprocess no longer existsr__init__rrrrrrrrqrqrrrGs zNoSuchProcess.__init__cCs|j|j|j|jffSNrrrrrrqrqrr __reduce__MszNoSuchProcess.__reduce__)NNrnrorprrrrqrqrqrrr@s rc@s&eZdZdZdZdddZddZdS) ZombieProcessa1Exception raised when querying a zombie process. This is raised on macOS, BSD and Solaris only, and not always: depending on the query the OS may be able to succeed anyway. On Linux all zombie processes are querable (hence this is never raised). Windows doesn't have zombie processes. rNcCs$t||||||_|pd|_dS)Nz"PID still exists but it's a zombie)rrrr)rrrrrrqrqrrr[szZombieProcess.__init__cCs|j|j|j|j|jffSr)rrrrrrrqrqrrr`szZombieProcess.__reduce__)NNNrrqrqrqrrrQs rc@s&eZdZdZdZdddZddZdS) AccessDeniedz@Exception raised when permission to perform an action is denied.rNcCs$t|||_||_|pd|_dS)Nrrrrqrqrrris zAccessDenied.__init__cCs|j|j|j|jffSrrrrqrqrrroszAccessDenied.__reduce__)NNNrrqrqrqrrrds rc@s&eZdZdZdZdddZddZdS) TimeoutExpiredzWRaised on Process.wait(timeout) if timeout expires and process is still alive. rNcCs*t|||_||_||_d||_dS)Nztimeout after %s seconds)rrrrrr)rrrrrqrqrrrzs  zTimeoutExpired.__init__cCs|j|j|j|jffSr)rrrrrrqrqrrrszTimeoutExpired.__reduce__)NNrrqrqrqrrrss rexeczvdef raise_from(value, from_value): try: raise value from from_value finally: value = None cCs|dSrrq)r from_valuerqrqrr raise_fromsrcCsFzt||d}Wntk r*YdSX|dk r>t||}|SdS)z5Calculate percentage usage of 'used' against 'total'.dgN)floatZeroDivisionErrorround)r{rzZround_retrqrqrrrNs cs2tfdd}fdd}i||_|S)aA simple memoize decorator for functions supporting (hashable) positional arguments. It also provides a cache_clear() function for clearing the cache: >>> @memoize ... def foo() ... return 1 ... >>> foo() 1 >>> foo.cache_clear() >>> It supports: - functions - classes (acts as a @singleton) - staticmethods - classmethods It does NOT support: - methods c s|tt|f}z |WStk rzz||}|<Wn,tk rp}zt|dW5d}~XYnX|YSXdSr) frozensetsortedrKeyError Exceptionr)argskwargskeyrerrcachefunrqrrwrappers zmemoize..wrappercs dS)z Clear cache.N)clearrq)rrqrr cache_clearszmemoize..cache_clear) functoolswrapsr)rrrrqrrrrKs  cs6tfdd}dd}dd}||_||_|S)aA memoize decorator which is disabled by default. It can be activated and deactivated on request. For efficiency reasons it can be used only against class methods accepting no arguments. >>> class Foo: ... @memoize ... def foo() ... print(1) ... >>> f = Foo() >>> # deactivated (default) >>> foo() 1 >>> foo() 1 >>> >>> # activated >>> foo.cache_activate(self) >>> foo() 1 >>> foo() >>> foo() >>> c sz|j}Wntk r^z|WYStk rX}zt|dW5d}~XYnXYnrtk rz |}Wn,tk r}zt|dW5d}~XYnXz||j<Wntk rYnXYnX|Sr)_cacheAttributeErrorrrr)rrrrrqrrrs"   z'memoize_when_activated..wrappercSs i|_dS)zsActivate cache. Expects a Process instance. Cache will be stored as a "_cache" instance attribute. N)rprocrqrqrrcache_activate sz.memoize_when_activated..cache_activatecSs"z|`Wntk rYnXdS)zDeactivate and clear cache.N)rrrrqrqrrcache_deactivatesz0memoize_when_activated..cache_deactivate)rrrr)rrrrrqrrrmemoize_when_activatedsrc Cs\zt|}Wn<tk rJ}z|jtjtjfkr4WYdSd}~XYnXt|jSdS)zSame as os.path.isfile() but does not swallow EACCES / EPERM exceptions, see: http://mail.python.org/pipermail/python-dev/2012-June/120787.html. FN)osstatOSErrorerrnoEPERMEACCESS_ISREGst_mode)rstrrqrqrrrJsc CsTzt|Wn<tk rJ}z|jtjtjfkr4WYdSd}~XYnXdSdS)zSame as os.path.exists() but does not swallow EACCES / EPERM exceptions. See: http://mail.python.org/pipermail/python-dev/2012-June/120787.html. FNT)rrrrrr)rrrqrqrrrM-sc CsdtjrtdkrdSz4tttj}t||dW5QRXWdStjk r^YdSXdS)z2Return True if IPv6 is supported on this platform.NF)z::1rT)sockethas_ipv6rr contextlibclosingbinderror)sockrqrqrrrO<s cCsvi}d}t}|d|}||kr"qr|d||}||krh|||}||d|}|r`|}|||<|d}q |S)zCParse a C environ block of environment variables into a dictionary.r=rl)rfindupper)datarposZWINDOWS_Znext_posZ equal_posrrrqrqrrrLJs   cCs6tdkr |Sz t|WStk r0|YSXdS)zConvert a numeric socket family value to an IntEnum member. If it's not a known member, return the numeric value itself. N)enumr AddressFamily ValueErrornumrqrqrrrPfs  cCs6tdkr |Sz t|WStk r0|YSXdS)zConvert a numeric socket type value to an IntEnum member. If it's not a known member, return the numeric value itself. N)rr SocketKindr r rqrqrrrQss  cCs|tjtfkr&|rt|}|r&t|}|tjkrJ|ttfkrJ||t}nt}t|}t|}|dkrxt ||||||St |||||||SdS)z2Convert a raw connection tuple to a proper ntuple.N) rrrrrgetrrPrQr5r>)rfamtype_rrrZ status_maprrqrqrrrXscsfdd}|S)zA decorator which can be used to mark a method as deprecated 'replcement' is the method name which will be called instead. cs:d|jf|jdkr|_t|fdd}|S)Nz8%s() is deprecated and will be removed; use %s() insteadcs tjtddt|||S)Nrk)category stacklevel)warningswarnDeprecationWarningr)rrr)r replacementrqrrinnersz/deprecated_method..outer..inner)rnrrr)rrr)rrrouters z deprecated_method..outerrq)rrrqrrrrIs c@sBeZdZdZddZddZddZdd Zdd d Zd dZ d S) _WrapNumberszNWatches numbers so that they don't overflow and wrap (reset to zero). cCs t|_i|_i|_i|_dSr) threadingLocklockr reminders reminder_keysrrqrqrrrs z_WrapNumbers.__init__cCsX||jkst||jkst||jks*t||j|<tt|j|<tt|j|<dSr)rAssertionErrorrrr defaultdictintset)r input_dictrrqrqrr _add_dicts  z_WrapNumbers._add_dictcCs\|j|}t|t|}|D]0}|j||D]}|j||=q8|j||=q&dS)zIn case the number of keys changed between calls (e.g. a disk disappears) this removes the entry from self.reminders. N)rr#keysrr)rr$rold_dictZ gone_keysZgone_keyremkeyrqrqrr_remove_dead_reminderss  z#_WrapNumbers._remove_dead_remindersc Cs||jkr||||S||||j|}i}|D]}||}z ||}Wn tk rp|||<Yq8YnXg}tt|D]f} || } || } || f} | | kr|j|| | 7<|j||| | | |j|| qt |||<q8||j|<|S)zlCache dict and sum numbers which overflow and wrap. Return an updated copy of `input_dict`. ) rr%r)rrangelenrraddappendtuple) rr$rr'Znew_dictrZ input_tupleZ old_tuplebitsiZ input_value old_valuer(rqrqrrruns2       z_WrapNumbers.runNc Csh|jX|dkr0|j|j|jn*|j|d|j|d|j|dW5QRXdS)z>Clear the internal cache, optionally only for function 'name'.N)rrrrrpop)rrrqrqrrrs   z_WrapNumbers.cache_clearc Cs.|j|j|j|jfW5QRSQRXdS)z5Return internal cache dicts as a tuple of 3 elements.N)rrrrrrqrqrr cache_infosz_WrapNumbers.cache_info)N) rnrorprrr%r)r2rr4rqrqrqrrrs ' rc Cs*tjt||W5QRSQRXdS)zGiven an `input_dict` and a function `name`, adjust the numbers which "wrap" (restart from zero) across different calls by adding "old value" to "new value" and return an updated dict. N)_wnrr2)r$rrqrqrrrRsicCst|dtdS)Nrb buffering)openFILE_READ_BUFFER_SIZE)fnamerqrqrrrTscCs`tst|tdSt|tttd}z t|_Wn0tk r>Yntk rZ|YnX|S)zOn Python 3 opens a file in text mode by using fs encoding and a proper en/decoding errors handler. On Python 2 this is just an alias for open(name, 'rt'). r7)r8encodingerrors) PY3r9r:r3r4 _CHUNK_SIZErrclose)r;ZfobjrqrqrrrS"s   c Csz|tkr.||}|W5QRSQRXnHz*||}|W5QRWSQRXWnttfk rt|YSXdS)zRead entire file content and return it as a string. File is opened in text mode. If specified, `fallback` is the value returned in case of error, either if the file does not exist or it can't be read(). N)_DEFAULTreadIOErrorr)r;fallback_openfrqrqrrrU@s   cCst||tdS)z,Same as above but opens file in binary mode.)rDrE)rUrT)r;rDrqrqrrrVQs%(value).1f%(symbol)scCsd}i}t|ddD]\}}d|dd>||<qt|ddD]2}t|||krFt|||}|tSqF|t|d|dS)zUsed by various scripts. See: http://goo.gl/zeJZl. >>> bytes2human(10000) '9.8K' >>> bytes2human(100001221) '95.4M' ) BKMGTPEZYrlN r)symbolr) enumeratereversedabsrlocalsdict)nformatsymbolsprefixr0srRrrqrqrrrWVscCs tjdjS)z+Return updated psutil.PROCFS_PATH constant.r)sysmodulesZ PROCFS_PATHrqrqrqrrget_procfs_pathisr_cCs|jttdS)N)r<r=)decoder3r4r\rqrqrrr`psr`cCs|Srrqrarqrqrrr`uscCs`tjdkrdSz2ddl}|s$t||ddks>tWntk rVYdSXdSdS)Nr^TrcolorsF)rrcursesisattyr Z setuptermZtigetnumr)filercrqrqrrr[~s  Fc Csts |Sg}tddddddddd d }d |d <z ||}Wn(tk rdtd t|YnX|||r~|ddd||fS)z*Return an highlighted version of 'string'.Z34Z33Z30Z32Z37Z36Z91Z35Z93) bluebrownZdarkgreygreenZgreyZ lightblueredvioletyellowZ29Nz#invalid color %r; choose between %s1z [%sm%s;)r[rWrr listr&r-r)r\colorboldattrrbrqrqrrrZs2     c Cstst||dntr.tt||||dnddl}d}|jjj}|jjj}t ddddd}||d<z ||}Wn,t k rt d |t | fYnX|r|dkr|d 7}|tjkrd nd } |j|_|| } || |zt||dW5|| |XdS) z$Print a colorized version of string.rerNrk)rhrirgrkz#invalid color %r; choose between %rii)r[printrrZctypeswindllZKernel32 GetStdHandleSetConsoleTextAttributerWrr rnr&r]stderrZc_ulongrestype) r\rorprerxZ DEFAULT_COLORrzr{rbZ handle_idhandlerqrqrrr\s8     cCsntrjddl}||j\}}}}}t|trRt|ttt frJd|}nd|}t d|||ft j ddS)z@If PSUTIL_DEBUG env var is set, print a debug message to stderr.rNz ignoring %sz ignoring %rzpsutil-debug [%s:%s]> %srr) r inspect getframeinfo currentframef_back isinstancerrrCEnvironmentErrorrwr]r|)rrr;lineno__lines_indexrqrqrrrYs   )N)N)rG)NF)r __future__rrrrrrrrrr]rrrrrrr ImportErrorr version_infor>rboolgetenvr objectrA__all__rrrplatform startswithrrrr rrr rZAIXr)r*r&r+r-r1r%r/r0r'r(r.r,r2rr rrrr!rrrrrrr"r#r$IntEnumrmglobalsupdate __members__rvrwrugetfilesystemencodingr3r4getfilesystemencodeerrorsrrFrBr@rArCrGr>rDrEr?rrrrr6r;r<r=r8r9r:r7r5rrHrrrrrrr __builtins__rWexec_rrrNrKrrJrMrOrLrPrQrXrIrrRr5rr4r:rTrSrUrVrWr_r`stdoutr[rZr\rYrqrqrqrrsD         &                              #     -G   W     '