Direct translation of Coordinator::PrintExecSummary() to recursively build a list of rows of summary statistics, one per exec node summary: the TExecSummary object that contains all the summary data idx: the index of the node to print indent_level: the number of spaces to print before wri
(summary, idx, indent_level, new_indent_level, output,
is_prettyprint=True, separate_prefix_column=False)
| 23 | |
| 24 | |
| 25 | def build_exec_summary_table(summary, idx, indent_level, new_indent_level, output, |
| 26 | is_prettyprint=True, separate_prefix_column=False): |
| 27 | """Direct translation of Coordinator::PrintExecSummary() to recursively build a list |
| 28 | of rows of summary statistics, one per exec node |
| 29 | |
| 30 | summary: the TExecSummary object that contains all the summary data |
| 31 | |
| 32 | idx: the index of the node to print |
| 33 | |
| 34 | indent_level: the number of spaces to print before writing the node's label, to give |
| 35 | the appearance of a tree. The 0th child of a node has the same indent_level as its |
| 36 | parent. All other children have an indent_level of one greater than their parent. |
| 37 | |
| 38 | new_indent_level: If true, this indent level is different from the previous row's. |
| 39 | |
| 40 | output: the list of rows into which to append the rows produced for this node and its |
| 41 | children. |
| 42 | |
| 43 | is_prettyprint: Optional. If True, print time, units, and bytes columns in pretty |
| 44 | printed format. |
| 45 | |
| 46 | separate_prefix_column: Optional. If True, the prefix and operator name will be |
| 47 | returned as separate column. Otherwise, prefix and operater name will be concatenated |
| 48 | into single column. |
| 49 | |
| 50 | Returns the index of the next exec node in summary.exec_nodes that should be |
| 51 | processed, used internally to this method only. |
| 52 | """ |
| 53 | if not summary.nodes: |
| 54 | # Summary nodes is empty or None. Nothing to build. |
| 55 | return |
| 56 | assert idx < len(summary.nodes), ( |
| 57 | "Index ({0}) must be less than exec summary count ({1})").format( |
| 58 | idx, len(summary.nodes)) |
| 59 | |
| 60 | attrs = ["latency_ns", "cpu_time_ns", "cardinality", "memory_used"] |
| 61 | |
| 62 | # Initialise aggregate and maximum stats |
| 63 | agg_stats, max_stats = TExecStats(), TExecStats() |
| 64 | for attr in attrs: |
| 65 | setattr(agg_stats, attr, 0) |
| 66 | setattr(max_stats, attr, 0) |
| 67 | |
| 68 | node = summary.nodes[idx] |
| 69 | instances = 0 |
| 70 | if node.exec_stats: |
| 71 | # exec_stats is not None or an empty list. |
| 72 | instances = len(node.exec_stats) |
| 73 | for stats in node.exec_stats: |
| 74 | for attr in attrs: |
| 75 | val = getattr(stats, attr) |
| 76 | if val is not None: |
| 77 | setattr(agg_stats, attr, getattr(agg_stats, attr) + val) |
| 78 | setattr(max_stats, attr, max(getattr(max_stats, attr), val)) |
| 79 | avg_time = agg_stats.latency_ns / instances |
| 80 | else: |
| 81 | avg_time = 0 |
| 82 |
no test coverage detected