Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../proc/self/root/lib64/python3....
File: cProfile.py
#! /usr/libexec/platform-python
[0] Fix | Delete
[1] Fix | Delete
"""Python interface for the 'lsprof' profiler.
[2] Fix | Delete
Compatible with the 'profile' module.
[3] Fix | Delete
"""
[4] Fix | Delete
[5] Fix | Delete
__all__ = ["run", "runctx", "Profile"]
[6] Fix | Delete
[7] Fix | Delete
import _lsprof
[8] Fix | Delete
import profile as _pyprofile
[9] Fix | Delete
[10] Fix | Delete
# ____________________________________________________________
[11] Fix | Delete
# Simple interface
[12] Fix | Delete
[13] Fix | Delete
def run(statement, filename=None, sort=-1):
[14] Fix | Delete
return _pyprofile._Utils(Profile).run(statement, filename, sort)
[15] Fix | Delete
[16] Fix | Delete
def runctx(statement, globals, locals, filename=None, sort=-1):
[17] Fix | Delete
return _pyprofile._Utils(Profile).runctx(statement, globals, locals,
[18] Fix | Delete
filename, sort)
[19] Fix | Delete
[20] Fix | Delete
run.__doc__ = _pyprofile.run.__doc__
[21] Fix | Delete
runctx.__doc__ = _pyprofile.runctx.__doc__
[22] Fix | Delete
[23] Fix | Delete
# ____________________________________________________________
[24] Fix | Delete
[25] Fix | Delete
class Profile(_lsprof.Profiler):
[26] Fix | Delete
"""Profile(timer=None, timeunit=None, subcalls=True, builtins=True)
[27] Fix | Delete
[28] Fix | Delete
Builds a profiler object using the specified timer function.
[29] Fix | Delete
The default timer is a fast built-in one based on real time.
[30] Fix | Delete
For custom timer functions returning integers, timeunit can
[31] Fix | Delete
be a float specifying a scale (i.e. how long each integer unit
[32] Fix | Delete
is, in seconds).
[33] Fix | Delete
"""
[34] Fix | Delete
[35] Fix | Delete
# Most of the functionality is in the base class.
[36] Fix | Delete
# This subclass only adds convenient and backward-compatible methods.
[37] Fix | Delete
[38] Fix | Delete
def print_stats(self, sort=-1):
[39] Fix | Delete
import pstats
[40] Fix | Delete
pstats.Stats(self).strip_dirs().sort_stats(sort).print_stats()
[41] Fix | Delete
[42] Fix | Delete
def dump_stats(self, file):
[43] Fix | Delete
import marshal
[44] Fix | Delete
with open(file, 'wb') as f:
[45] Fix | Delete
self.create_stats()
[46] Fix | Delete
marshal.dump(self.stats, f)
[47] Fix | Delete
[48] Fix | Delete
def create_stats(self):
[49] Fix | Delete
self.disable()
[50] Fix | Delete
self.snapshot_stats()
[51] Fix | Delete
[52] Fix | Delete
def snapshot_stats(self):
[53] Fix | Delete
entries = self.getstats()
[54] Fix | Delete
self.stats = {}
[55] Fix | Delete
callersdicts = {}
[56] Fix | Delete
# call information
[57] Fix | Delete
for entry in entries:
[58] Fix | Delete
func = label(entry.code)
[59] Fix | Delete
nc = entry.callcount # ncalls column of pstats (before '/')
[60] Fix | Delete
cc = nc - entry.reccallcount # ncalls column of pstats (after '/')
[61] Fix | Delete
tt = entry.inlinetime # tottime column of pstats
[62] Fix | Delete
ct = entry.totaltime # cumtime column of pstats
[63] Fix | Delete
callers = {}
[64] Fix | Delete
callersdicts[id(entry.code)] = callers
[65] Fix | Delete
self.stats[func] = cc, nc, tt, ct, callers
[66] Fix | Delete
# subcall information
[67] Fix | Delete
for entry in entries:
[68] Fix | Delete
if entry.calls:
[69] Fix | Delete
func = label(entry.code)
[70] Fix | Delete
for subentry in entry.calls:
[71] Fix | Delete
try:
[72] Fix | Delete
callers = callersdicts[id(subentry.code)]
[73] Fix | Delete
except KeyError:
[74] Fix | Delete
continue
[75] Fix | Delete
nc = subentry.callcount
[76] Fix | Delete
cc = nc - subentry.reccallcount
[77] Fix | Delete
tt = subentry.inlinetime
[78] Fix | Delete
ct = subentry.totaltime
[79] Fix | Delete
if func in callers:
[80] Fix | Delete
prev = callers[func]
[81] Fix | Delete
nc += prev[0]
[82] Fix | Delete
cc += prev[1]
[83] Fix | Delete
tt += prev[2]
[84] Fix | Delete
ct += prev[3]
[85] Fix | Delete
callers[func] = nc, cc, tt, ct
[86] Fix | Delete
[87] Fix | Delete
# The following two methods can be called by clients to use
[88] Fix | Delete
# a profiler to profile a statement, given as a string.
[89] Fix | Delete
[90] Fix | Delete
def run(self, cmd):
[91] Fix | Delete
import __main__
[92] Fix | Delete
dict = __main__.__dict__
[93] Fix | Delete
return self.runctx(cmd, dict, dict)
[94] Fix | Delete
[95] Fix | Delete
def runctx(self, cmd, globals, locals):
[96] Fix | Delete
self.enable()
[97] Fix | Delete
try:
[98] Fix | Delete
exec(cmd, globals, locals)
[99] Fix | Delete
finally:
[100] Fix | Delete
self.disable()
[101] Fix | Delete
return self
[102] Fix | Delete
[103] Fix | Delete
# This method is more useful to profile a single function call.
[104] Fix | Delete
def runcall(self, func, *args, **kw):
[105] Fix | Delete
self.enable()
[106] Fix | Delete
try:
[107] Fix | Delete
return func(*args, **kw)
[108] Fix | Delete
finally:
[109] Fix | Delete
self.disable()
[110] Fix | Delete
[111] Fix | Delete
# ____________________________________________________________
[112] Fix | Delete
[113] Fix | Delete
def label(code):
[114] Fix | Delete
if isinstance(code, str):
[115] Fix | Delete
return ('~', 0, code) # built-in functions ('~' sorts at the end)
[116] Fix | Delete
else:
[117] Fix | Delete
return (code.co_filename, code.co_firstlineno, code.co_name)
[118] Fix | Delete
[119] Fix | Delete
# ____________________________________________________________
[120] Fix | Delete
[121] Fix | Delete
def main():
[122] Fix | Delete
import os, sys, pstats
[123] Fix | Delete
from optparse import OptionParser
[124] Fix | Delete
usage = "cProfile.py [-o output_file_path] [-s sort] scriptfile [arg] ..."
[125] Fix | Delete
parser = OptionParser(usage=usage)
[126] Fix | Delete
parser.allow_interspersed_args = False
[127] Fix | Delete
parser.add_option('-o', '--outfile', dest="outfile",
[128] Fix | Delete
help="Save stats to <outfile>", default=None)
[129] Fix | Delete
parser.add_option('-s', '--sort', dest="sort",
[130] Fix | Delete
help="Sort order when printing to stdout, based on pstats.Stats class",
[131] Fix | Delete
default=-1,
[132] Fix | Delete
choices=sorted(pstats.Stats.sort_arg_dict_default))
[133] Fix | Delete
[134] Fix | Delete
if not sys.argv[1:]:
[135] Fix | Delete
parser.print_usage()
[136] Fix | Delete
sys.exit(2)
[137] Fix | Delete
[138] Fix | Delete
(options, args) = parser.parse_args()
[139] Fix | Delete
sys.argv[:] = args
[140] Fix | Delete
[141] Fix | Delete
if len(args) > 0:
[142] Fix | Delete
progname = args[0]
[143] Fix | Delete
sys.path.insert(0, os.path.dirname(progname))
[144] Fix | Delete
with open(progname, 'rb') as fp:
[145] Fix | Delete
code = compile(fp.read(), progname, 'exec')
[146] Fix | Delete
globs = {
[147] Fix | Delete
'__file__': progname,
[148] Fix | Delete
'__name__': '__main__',
[149] Fix | Delete
'__package__': None,
[150] Fix | Delete
'__cached__': None,
[151] Fix | Delete
}
[152] Fix | Delete
runctx(code, globs, None, options.outfile, options.sort)
[153] Fix | Delete
else:
[154] Fix | Delete
parser.print_usage()
[155] Fix | Delete
return parser
[156] Fix | Delete
[157] Fix | Delete
# When invoked as main program, invoke the profiler on a script
[158] Fix | Delete
if __name__ == '__main__':
[159] Fix | Delete
main()
[160] Fix | Delete
[161] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function