def calculate_stats(self):
    assert self.is_complete()
    self.mytree.remove_ignored()
    self.mytree.remove_dummies()
    self.mytree.copy_subtracted_init_and_wrong_la()
    self.mytree.add_missing_la_nodes()
    self.mytree.validate_nesting()

    def recurse(node, prev_layer, prev_phase, indent, in_pe_layers):
        [begun, mark, layer, phase] = [node.start_time_s, node.mark, node.layer, node.phase()]
        time = node.end_time_s
        tag = None
        elapsed0 = 'DETAIL'
        elapsed1 = node.elapsed_less_subtracted_ms()
        if (elapsed1 is None):
            raise Exception('Elapsed for {} returned None'.format(node.to_str()))
        if ((not node.is_added_detail()) and (not node.subtract)):
            tag = ((((node.app_phase + '_') + layer) + '_') + phase)
            elapsed0 = elapsed1
            self.stats[tag] = (self.stats.get(tag, 0.0) + elapsed0)
            self.items[tag] = (self.items.get(tag, []) + [((((((mark + ' ') + str(elapsed0)) + ' ') + str(elapsed1)) + ' ') + tag)])
            if (phase in subphases[PHASE_EXECUTION]):
                if (not in_pe_layers.get(layer)):
                    pe_tag = ((node.app_phase + '_') + make_tag(layer, PHASE_EXECUTION))
                    self.stats[pe_tag] = (self.stats.get(pe_tag, 0.0) + elapsed0)
                    self.items[pe_tag] = (self.items.get(pe_tag, []) + [((((((mark + ' ') + str(elapsed0)) + ' ') + str(elapsed1)) + ' ') + pe_tag)])
        if (phase == PHASE_EXECUTION):
            in_pe_layers[layer] = (in_pe_layers.get(layer, 0) + 1)
        for c in node.children:
            recurse(c, (layer or prev_layer), (phase or prev_phase), (indent + '  '), in_pe_layers)
        if (phase == PHASE_EXECUTION):
            in_pe_layers[layer] = (in_pe_layers[layer] - 1)
        return
    for top in self.mytree.root.children:
        recurse(top, None, None, '', {})
    self.debugstring = self.mytree.to_str()
def calculate_stats(self):
    assert self.is_complete()
    self.mytree.remove_ignored()
    self.mytree.remove_dummies()
    self.mytree.copy_subtracted_init_and_wrong_la()
    self.mytree.add_missing_la_nodes()
    self.mytree.validate_nesting()

    def recurse(node, prev_layer, prev_phase, indent, in_pe_layers):
        [begun, mark, layer, phase] = [node.start_time_s, node.mark, node.layer, node.phase()]
        time = node.end_time_s
        tag = None
        elapsed0 = 'DETAIL'
        elapsed1 = node.elapsed_less_subtracted_ms()
        if (elapsed1 is None):
            raise Exception('Elapsed for {} returned None'.format(node.to_str()))
        if ((not node.is_added_detail()) and (not node.subtract)):
            tag = ((((node.app_phase + '_') + layer) + '_') + phase)
            elapsed0 = elapsed1
            self.stats[tag] = (self.stats.get(tag, 0.0) + elapsed0)
            self.items[tag] = (self.items.get(tag, []) + [((((((mark + ' ') + str(elapsed0)) + ' ') + str(elapsed1)) + ' ') + tag)])
            if (phase in subphases[PHASE_EXECUTION]):
                if (not in_pe_layers.get(layer)):
                    pe_tag = ((node.app_phase + '_') + make_tag(layer, PHASE_EXECUTION))
                    self.stats[pe_tag] = (self.stats.get(pe_tag, 0.0) + elapsed0)
                    self.items[pe_tag] = (self.items.get(pe_tag, []) + [((((((mark + ' ') + str(elapsed0)) + ' ') + str(elapsed1)) + ' ') + pe_tag)])
        if (phase == PHASE_EXECUTION):
            in_pe_layers[layer] = (in_pe_layers.get(layer, 0) + 1)
        for c in node.children:
            recurse(c, (layer or prev_layer), (phase or prev_phase), (indent + '  '), in_pe_layers)
        if (phase == PHASE_EXECUTION):
            in_pe_layers[layer] = (in_pe_layers[layer] - 1)
        return
    for top in self.mytree.root.children:
        recurse(top, None, None, , {})
    self.debugstring = self.mytree.to_str()