o $a @sdZddlmZmZddlmZddlmZddlmZm Z m Z m Z ddl m Z ddlmZddlmZdd lmZdd lmZeeZGd d d eZd eddfddZd edede eddfddZd ede jddfddZd ededdfddZ d ede eeffddZ!dS)z sphinx.ext.duration ~~~~~~~~~~~~~~~~~~~ Measure durations of Sphinx processing. :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. )datetime timedelta)islice) itemgetter)AnyDictListcast)nodes)Sphinx)Domain)__)loggingc@s~eZdZdZdZedeeeffddZ deddfddZ dd d Z d eddfd d Z de edeeefddfddZdS)DurationDomainz,A domain for durations of Sphinx processing.durationreturncCs|jdiS)Nreading_durations)data setdefaultselfr5/usr/lib/python3/dist-packages/sphinx/ext/duration.pyrsz DurationDomain.reading_durationsNcCs||j|jj<dSN)renvdocname)rrrrrnote_reading_duration"z$DurationDomain.note_reading_durationcCs|jdSr)rclearrrrrr%szDurationDomain.clearrcCs|j|ddSr)rpop)rrrrr clear_doc(rzDurationDomain.clear_docdocnames otherdatacCs(|D] \}}||vr||j|<qdSr)itemsr)rr!r"rrrrrmerge_domaindata+s  zDurationDomain.merge_domaindata)rN)__name__ __module__ __qualname____doc__namepropertyrstrrrrrr rr$rrrrrs &rapprNcCstt|jd}|dS)zTInitialize DurationDomain on bootstrap. This clears results of last build. rN)r rr get_domainr)r,domainrrron_builder_inited1s r/rcontentcCst|jjd<dS)z"Start to measure reading duration. started_atN)rnowr temp_data)r,rr0rrron_source_read:sr4doctreecCs:|jjd}t|}tt|jd}||dS)zRecord a reading duration.r1rN) rr3getrr2r rr-r)r,r5r1rr.rrron_doctree_read?s r7errorcCsztt|jd}t|jtddd}|sdSt dt t dt |dD]\}}t d |j |j d |q*dS) z*Display duration ranking on current build.rT)keyreverseNzH====================== slowest reading durations =======================z %d.%03d %si)r rrr-sortedrr#rloggerinfor rseconds microseconds)r,r8r. durationsrdrrron_build_finishedGs rEcCsF|t|dt|dt|dt|dtddddS)Nzbuilder-initedz source-readz doctree-readzbuild-finishedbuiltinT)versionparallel_read_safeparallel_write_safe) add_domainrconnectr/r4r7rE)r,rrrsetupTs     rL)"r(rr itertoolsroperatorrtypingrrrr docutilsr sphinx.applicationr sphinx.domainsr sphinx.localer sphinx.utilr getLoggerr%r?rr/r+r4documentr7 ExceptionrErLrrrrs"