Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../usr/lib64/python3....
File: profile.py
return self._calibrate_inner(m, verbose)
[500] Fix | Delete
finally:
[501] Fix | Delete
self.bias = saved_bias
[502] Fix | Delete
[503] Fix | Delete
def _calibrate_inner(self, m, verbose):
[504] Fix | Delete
get_time = self.get_time
[505] Fix | Delete
[506] Fix | Delete
# Set up a test case to be run with and without profiling. Include
[507] Fix | Delete
# lots of calls, because we're trying to quantify stopwatch overhead.
[508] Fix | Delete
# Do not raise any exceptions, though, because we want to know
[509] Fix | Delete
# exactly how many profile events are generated (one call event, +
[510] Fix | Delete
# one return event, per Python-level call).
[511] Fix | Delete
[512] Fix | Delete
def f1(n):
[513] Fix | Delete
for i in range(n):
[514] Fix | Delete
x = 1
[515] Fix | Delete
[516] Fix | Delete
def f(m, f1=f1):
[517] Fix | Delete
for i in range(m):
[518] Fix | Delete
f1(100)
[519] Fix | Delete
[520] Fix | Delete
f(m) # warm up the cache
[521] Fix | Delete
[522] Fix | Delete
# elapsed_noprofile <- time f(m) takes without profiling.
[523] Fix | Delete
t0 = get_time()
[524] Fix | Delete
f(m)
[525] Fix | Delete
t1 = get_time()
[526] Fix | Delete
elapsed_noprofile = t1 - t0
[527] Fix | Delete
if verbose:
[528] Fix | Delete
print("elapsed time without profiling =", elapsed_noprofile)
[529] Fix | Delete
[530] Fix | Delete
# elapsed_profile <- time f(m) takes with profiling. The difference
[531] Fix | Delete
# is profiling overhead, only some of which the profiler subtracts
[532] Fix | Delete
# out on its own.
[533] Fix | Delete
p = Profile()
[534] Fix | Delete
t0 = get_time()
[535] Fix | Delete
p.runctx('f(m)', globals(), locals())
[536] Fix | Delete
t1 = get_time()
[537] Fix | Delete
elapsed_profile = t1 - t0
[538] Fix | Delete
if verbose:
[539] Fix | Delete
print("elapsed time with profiling =", elapsed_profile)
[540] Fix | Delete
[541] Fix | Delete
# reported_time <- "CPU seconds" the profiler charged to f and f1.
[542] Fix | Delete
total_calls = 0.0
[543] Fix | Delete
reported_time = 0.0
[544] Fix | Delete
for (filename, line, funcname), (cc, ns, tt, ct, callers) in \
[545] Fix | Delete
p.timings.items():
[546] Fix | Delete
if funcname in ("f", "f1"):
[547] Fix | Delete
total_calls += cc
[548] Fix | Delete
reported_time += tt
[549] Fix | Delete
[550] Fix | Delete
if verbose:
[551] Fix | Delete
print("'CPU seconds' profiler reported =", reported_time)
[552] Fix | Delete
print("total # calls =", total_calls)
[553] Fix | Delete
if total_calls != m + 1:
[554] Fix | Delete
raise ValueError("internal error: total calls = %d" % total_calls)
[555] Fix | Delete
[556] Fix | Delete
# reported_time - elapsed_noprofile = overhead the profiler wasn't
[557] Fix | Delete
# able to measure. Divide by twice the number of calls (since there
[558] Fix | Delete
# are two profiler events per call in this test) to get the hidden
[559] Fix | Delete
# overhead per event.
[560] Fix | Delete
mean = (reported_time - elapsed_noprofile) / 2.0 / total_calls
[561] Fix | Delete
if verbose:
[562] Fix | Delete
print("mean stopwatch overhead per profile event =", mean)
[563] Fix | Delete
return mean
[564] Fix | Delete
[565] Fix | Delete
#****************************************************************************
[566] Fix | Delete
[567] Fix | Delete
def main():
[568] Fix | Delete
import os
[569] Fix | Delete
from optparse import OptionParser
[570] Fix | Delete
[571] Fix | Delete
usage = "profile.py [-o output_file_path] [-s sort] [-m module | scriptfile] [arg] ..."
[572] Fix | Delete
parser = OptionParser(usage=usage)
[573] Fix | Delete
parser.allow_interspersed_args = False
[574] Fix | Delete
parser.add_option('-o', '--outfile', dest="outfile",
[575] Fix | Delete
help="Save stats to <outfile>", default=None)
[576] Fix | Delete
parser.add_option('-m', dest="module", action="store_true",
[577] Fix | Delete
help="Profile a library module.", default=False)
[578] Fix | Delete
parser.add_option('-s', '--sort', dest="sort",
[579] Fix | Delete
help="Sort order when printing to stdout, based on pstats.Stats class",
[580] Fix | Delete
default=-1)
[581] Fix | Delete
[582] Fix | Delete
if not sys.argv[1:]:
[583] Fix | Delete
parser.print_usage()
[584] Fix | Delete
sys.exit(2)
[585] Fix | Delete
[586] Fix | Delete
(options, args) = parser.parse_args()
[587] Fix | Delete
sys.argv[:] = args
[588] Fix | Delete
[589] Fix | Delete
# The script that we're profiling may chdir, so capture the absolute path
[590] Fix | Delete
# to the output file at startup.
[591] Fix | Delete
if options.outfile is not None:
[592] Fix | Delete
options.outfile = os.path.abspath(options.outfile)
[593] Fix | Delete
[594] Fix | Delete
if len(args) > 0:
[595] Fix | Delete
if options.module:
[596] Fix | Delete
import runpy
[597] Fix | Delete
code = "run_module(modname, run_name='__main__')"
[598] Fix | Delete
globs = {
[599] Fix | Delete
'run_module': runpy.run_module,
[600] Fix | Delete
'modname': args[0]
[601] Fix | Delete
}
[602] Fix | Delete
else:
[603] Fix | Delete
progname = args[0]
[604] Fix | Delete
sys.path.insert(0, os.path.dirname(progname))
[605] Fix | Delete
with io.open_code(progname) as fp:
[606] Fix | Delete
code = compile(fp.read(), progname, 'exec')
[607] Fix | Delete
globs = {
[608] Fix | Delete
'__file__': progname,
[609] Fix | Delete
'__name__': '__main__',
[610] Fix | Delete
'__package__': None,
[611] Fix | Delete
'__cached__': None,
[612] Fix | Delete
}
[613] Fix | Delete
try:
[614] Fix | Delete
runctx(code, globs, None, options.outfile, options.sort)
[615] Fix | Delete
except BrokenPipeError as exc:
[616] Fix | Delete
# Prevent "Exception ignored" during interpreter shutdown.
[617] Fix | Delete
sys.stdout = None
[618] Fix | Delete
sys.exit(exc.errno)
[619] Fix | Delete
else:
[620] Fix | Delete
parser.print_usage()
[621] Fix | Delete
return parser
[622] Fix | Delete
[623] Fix | Delete
# When invoked as main program, invoke the profiler on a script
[624] Fix | Delete
if __name__ == '__main__':
[625] Fix | Delete
main()
[626] Fix | Delete
[627] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function