x[hg pddlZddlZddlZejeZGddZddddededefd Z y) Nc8eZdZdZddddededefdZdZd Zy ) Timeda A context manager which measures and optionally logs context run time. :param msg: A message that describes the thing that is being measured :param threshold: Threshold, in seconds. When the context exceeds this threshold, a log will be made. :param log_mode: Control whether to log. Defaults to "threshold". Possible values include: "always" - Always log 'msg', even when 'threshold' is not reached. "threshold" - Log when context time exceeds 'threshold'. "skip" - Do not log. Context time and message are stored in the 'output' and 'delta' attributes, respectively. Used to manually coalesce with other logs at the call site. usage: this call: ``` with Timed("Configuring the network"): run_configure() ``` might produce this log: ``` Configuring the network took 0.100 seconds ``` {Gz? thresholdrlog_modemsgrcX||_||_||_d|_d|_d|_y)Ng)r rroutputstartdelta)selfr rrs 7/usr/lib/python3/dist-packages/cloudinit/performance.py__init__zTimed.__init__%s."     c8tj|_|S)N)time monotonicr )rs r __enter__zTimed.__enter__3s^^%  rctj|jz |_d|jdd}d|jk(r"t j d|j|yd|jk(ryd|jk(rR|j|jkDr8t j d|j||jd||_ yytd |jd ) Nztook z.3fz secondsalwaysz%s %sskipr zInvalid Timed log_mode value: 'z'.) rrr rrLOGdebugr rr ValueError)rexc_typeexc_valexc_tbsuffixs r__exit__zTimed.__exit__7s^^% 2 C(1 t}} $ IIgtxx 0 t}} $  DMM )zzDNN* '488V4!% !F84 +1$--C rN) __name__ __module__ __qualname____doc__strfloatrrr"rrrrs;@ #      rrrrrr rcfd}|S)a A decorator which measures and optionally logs context run time. :param msg: A message that describes the thing that is being measured :param threshold: Threshold, in seconds. When the context exceeds this threshold, a log will be made. :param log_mode: Control whether to log. Defaults to "threshold". Possible values include: "always" - Always log 'msg', even when 'threshold' is not reached. "threshold" - Log when context time exceeds 'threshold'. usage: this call: ``` @timed("Configuring the network") def run_configure(): ... ``` might produce this log: ``` Configuring the network took 0.100 seconds ``` cJtjfd}|S)Nc\t5|i|cdddS#1swYyxYw)Nr)r)argskwargsfuncrr rs r decoratorz)timed..wrapper..decoratords1si(C -T,V, - - -s"+) functoolswraps)r/r0rr rs` rwrapperztimed..wrappercs&   -  -rr))r rrr3s``` rtimedr4Hs6 Nr) r1loggingr getLoggerr#rrr'r(r4r)rrr7sL g!==@+/ #s#%###r