#NEWLINE# def build_summary_table( summary , idx , is_fragment_root , indent_level , output ) : #NEWLINE# #INDENT# "Direct translation of Coordinator::PrintExecSummary() to recursively\n    build a list of rows of summary statistics, one per exec node\n\n    summary: the TExecSummary object that contains all the summary data\n\n    idx: the index of the node to print\n\n    is_fragment_root: true if the node to print is the root of a fragment (and\n    therefore feeds into an exchange)\n\n    indent_level: the number of spaces to print before writing the node's\n    label, to give the appearance of a tree. The 0th child of a node has the\n    same indent_level as its parent. All other children have an indent_level\n    of one greater than their parent.\n\n    output: the list of rows into which to append the rows produced for this\n    node and its children.\n\n    Returns the index of the next exec node in summary.exec_nodes that should\n    be processed, used internally to this method only.\n    " #NEWLINE# attrs = [ 'latency_ns' , 'cpu_time_ns' , 'cardinality' , 'memory_used' ] #NEWLINE# ( agg_stats , max_stats ) = ( TExecStats ( ) , TExecStats ( ) ) #NEWLINE# for attr in attrs : #NEWLINE# #INDENT# setattr ( agg_stats , attr , 0 ) #NEWLINE# setattr ( max_stats , attr , 0 ) #NEWLINE# #UNINDENT# node = summary . nodes [ idx ] #NEWLINE# for stats in node . exec_stats : #NEWLINE# #INDENT# for attr in attrs : #NEWLINE# #INDENT# val = getattr ( stats , attr ) #NEWLINE# if ( val is not None ) : #NEWLINE# #INDENT# setattr ( agg_stats , attr , ( getattr ( agg_stats , attr ) + val ) ) #NEWLINE# setattr ( max_stats , attr , max ( getattr ( max_stats , attr ) , val ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( len ( node . exec_stats ) > 0 ) : #NEWLINE# #INDENT# avg_time = ( agg_stats . latency_ns / len ( node . exec_stats ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# avg_time = 0 #NEWLINE# #UNINDENT# if ( node . is_broadcast and is_fragment_root ) : #NEWLINE# #INDENT# cardinality = max_stats . cardinality #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cardinality = agg_stats . cardinality #NEWLINE# #UNINDENT# est_stats = node . estimated_stats #NEWLINE# label_prefix = '' #NEWLINE# if ( indent_level > 0 ) : #NEWLINE# #INDENT# label_prefix = '|' #NEWLINE# if is_fragment_root : #NEWLINE# #INDENT# label_prefix += ( '    ' * indent_level ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# label_prefix += ( '--' * indent_level ) #NEWLINE# #UNINDENT# #UNINDENT# def prettyprint( val , units , divisor ) : #NEWLINE# #INDENT# for unit in units : #NEWLINE# #INDENT# if ( val < divisor ) : #NEWLINE# #INDENT# if ( unit == units [ 0 ] ) : #NEWLINE# #INDENT# return ( '%d%s' % ( val , unit ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( '%3.2f%s' % ( val , unit ) ) #NEWLINE# #UNINDENT# #UNINDENT# val /= divisor #NEWLINE# #UNINDENT# #UNINDENT# def prettyprint_bytes( byte_val ) : #NEWLINE# #INDENT# return prettyprint ( byte_val , [ ' B' , ' KB' , ' MB' , ' GB' , ' TB' ] , 1024.0 ) #NEWLINE# #UNINDENT# def prettyprint_units( unit_val ) : #NEWLINE# #INDENT# return prettyprint ( unit_val , [ '' , 'K' , 'M' , 'B' ] , 1000.0 ) #NEWLINE# #UNINDENT# def prettyprint_time( time_val ) : #NEWLINE# #INDENT# return prettyprint ( time_val , [ 'ns' , 'us' , 'ms' , 's' ] , 1000.0 ) #NEWLINE# #UNINDENT# row = [ ( label_prefix + node . label ) , len ( node . exec_stats ) , prettyprint_time ( avg_time ) , prettyprint_time ( max_stats . latency_ns ) , prettyprint_units ( cardinality ) , prettyprint_units ( est_stats . cardinality ) , prettyprint_bytes ( max_stats . memory_used ) , prettyprint_bytes ( est_stats . memory_used ) , node . label_detail ] #NEWLINE# output . append ( row ) #NEWLINE# try : #NEWLINE# #INDENT# sender_idx = summary . exch_to_sender_map [ idx ] #NEWLINE# build_summary_table ( summary , sender_idx , True , indent_level , output ) #NEWLINE# #UNINDENT# except ( KeyError , TypeError ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# idx += 1 #NEWLINE# if ( node . num_children > 0 ) : #NEWLINE# #INDENT# first_child_output = [ ] #NEWLINE# idx = build_summary_table ( summary , idx , False , indent_level , first_child_output ) #NEWLINE# for child_idx in range ( 1 , node . num_children ) : #NEWLINE# #INDENT# idx = build_summary_table ( summary , idx , False , ( indent_level + 1 ) , output ) #NEWLINE# #UNINDENT# output += first_child_output #NEWLINE# #UNINDENT# return idx