3

T'ícã@sdZddlmZmZddlmZddlmZddlmZm	Z	m
Z
mZddlm
Z
ddlmZddlmZdd	lmZdd
lmZejeƒZGdd„deƒZed
dœdd„Zeee
ed
dœdd„Zee
jd
dœdd„Zeed
dœdd„Z ee	eefdœdd„Z!d
S)z'Measure durations of Sphinx processing.é)ÚdatetimeÚ	timedelta)Úislice)Ú
itemgetter)ÚAnyÚDictÚListÚcast)Únodes)ÚSphinx)ÚDomain)Ú__)Úloggingc@szeZdZdZdZeeeefdœdd„ƒZ	eddœdd	„Z
ddœd
d„Zeddœd
d„Ze
eeeefddœdd„ZdS)ÚDurationDomainz,A domain for durations of Sphinx processing.Úduration)ÚreturncCs|jjdiƒS)NÚreading_durations)ÚdataÚ
setdefault)Úself©rú5/tmp/pip-build-gk9425m9/sphinx/sphinx/ext/duration.pyrsz DurationDomain.reading_durationsN)rrcCs||j|jj<dS)N)rÚenvÚdocname)rrrrrÚnote_reading_durationsz$DurationDomain.note_reading_durationcCs|jjƒdS)N)rÚclear)rrrrrszDurationDomain.clear)rrcCs|jj|dƒdS)N)rÚpop)rrrrrÚ	clear_doc szDurationDomain.clear_doc)ÚdocnamesÚ	otherdatarcCs,x&|jƒD]\}}||kr
||j|<q
WdS)N)Úitemsr)rrrrrrrrÚmerge_domaindata#szDurationDomain.merge_domaindata)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚnameÚpropertyrÚstrrrrrrrr!rrrrrsrN)ÚapprcCstt|jjdƒƒ}|jƒdS)zTInitialize DurationDomain on bootstrap.

    This clears results of last build.
    rN)r	rrÚ
get_domainr)r)ÚdomainrrrÚon_builder_inited)sr,)r)rÚcontentrcCstjƒ|jjd<dS)z"Start to measure reading duration.Ú
started_atN)rÚnowrÚ	temp_data)r)rr-rrrÚon_source_read2sr1)r)ÚdoctreercCs:|jjjdƒ}tjƒ|}tt|jjdƒƒ}|j|ƒdS)zRecord a reading duration.r.rN)	rr0Úgetrr/r	rr*r)r)r2r.rr+rrrÚon_doctree_read7sr4)r)ÚerrorrcCs~tt|jjdƒƒ}t|jjƒtdƒdd}|s2dStj	dƒtj	t
dƒƒx.t|dƒD] \}}tj	d	|j|j
d
|ƒqVWdS)z*Display duration ranking on current build.réT)ÚkeyÚreverseNÚzH====================== slowest reading durations =======================éz
%d.%03d %siè)r	rrr*Úsortedrr rÚloggerÚinfor
rÚsecondsÚmicroseconds)r)r5r+Z	durationsrÚdrrrÚon_build_finished?s
rAcCsF|jtƒ|jdtƒ|jdtƒ|jdtƒ|jdtƒddddœS)Nzbuilder-initedzsource-readzdoctree-readzbuild-finishedÚbuiltinT)ÚversionZparallel_read_safeZparallel_write_safe)Z
add_domainrÚconnectr,r1r4rA)r)rrrÚsetupLs
rE)"r%rrÚ	itertoolsrÚoperatorrÚtypingrrrr	Zdocutilsr
Zsphinx.applicationrZsphinx.domainsrZ
sphinx.localer
Zsphinx.utilrÚ	getLoggerr"r<rr,r(r1Údocumentr4Ú	ExceptionrArErrrrÚ<module>s