This class is used for creating reports from data generated by the Profile class. It is a "friend" of that class, and imports data either by direct access to members of Profile class, or by reading in a dictionary that was emitted (via marshal) from the Profile class. The big chang
| 71 | func_profiles: dict[str, FunctionProfile] |
| 72 | |
| 73 | class Stats: |
| 74 | """This class is used for creating reports from data generated by the |
| 75 | Profile class. It is a "friend" of that class, and imports data either |
| 76 | by direct access to members of Profile class, or by reading in a dictionary |
| 77 | that was emitted (via marshal) from the Profile class. |
| 78 | |
| 79 | The big change from the previous Profiler (in terms of raw functionality) |
| 80 | is that an "add()" method has been provided to combine Stats from |
| 81 | several distinct profile runs. Both the constructor and the add() |
| 82 | method now take arbitrarily many file names as arguments. |
| 83 | |
| 84 | All the print methods now take an argument that indicates how many lines |
| 85 | to print. If the arg is a floating-point number between 0 and 1.0, then |
| 86 | it is taken as a decimal percentage of the available lines to be printed |
| 87 | (e.g., .1 means print 10% of all available lines). If it is an integer, |
| 88 | it is taken to mean the number of lines of data that you wish to have |
| 89 | printed. |
| 90 | |
| 91 | The sort_stats() method now processes some additional options (i.e., in |
| 92 | addition to the old -1, 0, 1, or 2 that are respectively interpreted as |
| 93 | 'stdname', 'calls', 'time', and 'cumulative'). It takes either an |
| 94 | arbitrary number of quoted strings or SortKey enum to select the sort |
| 95 | order. |
| 96 | |
| 97 | For example sort_stats('time', 'name') or sort_stats(SortKey.TIME, |
| 98 | SortKey.NAME) sorts on the major key of 'internal function time', and on |
| 99 | the minor key of 'the name of the function'. Look at the two tables in |
| 100 | sort_stats() and get_sort_arg_defs(self) for more examples. |
| 101 | |
| 102 | All methods return self, so you can string together commands like: |
| 103 | Stats('foo', 'goo').strip_dirs().sort_stats('calls').\ |
| 104 | print_stats(5).print_callers(5) |
| 105 | """ |
| 106 | |
| 107 | def __init__(self, *args, stream=None): |
| 108 | self.stream = stream or sys.stdout |
| 109 | if not len(args): |
| 110 | arg = None |
| 111 | else: |
| 112 | arg = args[0] |
| 113 | args = args[1:] |
| 114 | self.init(arg) |
| 115 | self.add(*args) |
| 116 | |
| 117 | def init(self, arg): |
| 118 | self.all_callees = None # calc only if needed |
| 119 | self.files = [] |
| 120 | self.fcn_list = None |
| 121 | self.total_tt = 0 |
| 122 | self.total_calls = 0 |
| 123 | self.prim_calls = 0 |
| 124 | self.max_name_len = 0 |
| 125 | self.top_level = set() |
| 126 | self.stats = {} |
| 127 | self.sort_arg_dict = {} |
| 128 | self.load_stats(arg) |
| 129 | try: |
| 130 | self.get_top_level_stats() |
no outgoing calls
no test coverage detected
searching dependent graphs…