Changeset 388 for python/vendor/current/Lib/profile.py
- Timestamp:
- Mar 19, 2014, 11:11:30 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/vendor/current/Lib/profile.py
r2 r388 3 3 # Class for profiling python code. rev 1.0 6/2/94 4 4 # 5 # Written by James Roskind 5 6 # Based on prior profile module by Sjoerd Mullender... 6 7 # which was hacked somewhat by: Guido van Rossum … … 8 9 """Class for profiling Python code.""" 9 10 10 # Copyright 1994, by InfoSeek Corporation, all rights reserved.11 # Written by James Roskind11 # Copyright Disney Enterprises, Inc. All Rights Reserved. 12 # Licensed to PSF under a Contributor Agreement 12 13 # 13 # Permission to use, copy, modify, and distribute this Python software 14 # and its associated documentation for any purpose (subject to the 15 # restriction in the following sentence) without fee is hereby granted, 16 # provided that the above copyright notice appears in all copies, and 17 # that both that copyright notice and this permission notice appear in 18 # supporting documentation, and that the name of InfoSeek not be used in 19 # advertising or publicity pertaining to distribution of the software 20 # without specific, written prior permission. This permission is 21 # explicitly restricted to the copying and modification of the software 22 # to remain in Python, compiled Python, or other languages (such as C) 23 # wherein the modified or derived code is exclusively imported into a 24 # Python module. 14 # Licensed under the Apache License, Version 2.0 (the "License"); 15 # you may not use this file except in compliance with the License. 16 # You may obtain a copy of the License at 25 17 # 26 # INFOSEEK CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 27 # SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 28 # FITNESS. IN NO EVENT SHALL INFOSEEK CORPORATION BE LIABLE FOR ANY 29 # SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER 30 # RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF 31 # CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 32 # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 33 18 # http://www.apache.org/licenses/LICENSE-2.0 19 # 20 # Unless required by applicable law or agreed to in writing, software 21 # distributed under the License is distributed on an "AS IS" BASIS, 22 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 23 # either express or implied. See the License for the specific language 24 # governing permissions and limitations under the License. 34 25 35 26 … … 76 67 return prof.print_stats(sort) 77 68 78 def runctx(statement, globals, locals, filename=None ):69 def runctx(statement, globals, locals, filename=None, sort=-1): 79 70 """Run statement under profiler, supplying your own globals and locals, 80 71 optionally saving results in filename. … … 91 82 prof.dump_stats(filename) 92 83 else: 93 return prof.print_stats( )84 return prof.print_stats(sort) 94 85 95 86 # Backwards compatibility. … … 97 88 print "Documentation for the profile module can be found " 98 89 print "in the Python Library Reference, section 'The Python Profiler'." 99 100 if os.name == "mac":101 import MacOS102 def _get_time_mac(timer=MacOS.GetTicks):103 return timer() / 60.0104 90 105 91 if hasattr(os, "times"): … … 179 165 self.dispatcher = self.trace_dispatch 180 166 self.get_time = _get_time_resource 181 elif os.name == 'mac':182 self.timer = MacOS.GetTicks183 self.dispatcher = self.trace_dispatch_mac184 self.get_time = _get_time_mac185 167 elif hasattr(time, 'clock'): 186 168 self.timer = self.get_time = time.clock … … 599 581 help="Save stats to <outfile>", default=None) 600 582 parser.add_option('-s', '--sort', dest="sort", 601 help="Sort order when printing to stdout, based on pstats.Stats class", default=-1) 583 help="Sort order when printing to stdout, based on pstats.Stats class", 584 default=-1) 602 585 603 586 if not sys.argv[1:]: … … 606 589 607 590 (options, args) = parser.parse_args() 608 609 if (len(args) > 0): 610 sys.argv[:] = args 611 sys.path.insert(0, os.path.dirname(sys.argv[0])) 612 run('execfile(%r)' % (sys.argv[0],), options.outfile, options.sort) 591 sys.argv[:] = args 592 593 if len(args) > 0: 594 progname = args[0] 595 sys.path.insert(0, os.path.dirname(progname)) 596 with open(progname, 'rb') as fp: 597 code = compile(fp.read(), progname, 'exec') 598 globs = { 599 '__file__': progname, 600 '__name__': '__main__', 601 '__package__': None, 602 } 603 runctx(code, globs, None, options.outfile, options.sort) 613 604 else: 614 605 parser.print_usage()
Note:
See TracChangeset
for help on using the changeset viewer.