code: def wrap_tree(nodetrees):
      """
      Using HostStatisticNode to wrap original profiler result tree, and calculate node statistic metrics.
      """
      node_statistic_tree = {}
      results = collections.defaultdict(list)
      newresults = collections.defaultdict(list)
      for thread_id, rootnode in nodetrees.items():
          stack = []
          stack.append(rootnode)
          root_statistic_node = HostStatisticNode(rootnode)
          newstack = []
          newstack.append(root_statistic_node)
          node_statistic_tree[thread_id] = root_statistic_node
          threadlist = results[thread_id]
          newthreadlist = newresults[thread_id]
          while stack:
              current_node = stack.pop()
              threadlist.append(current_node)
              current_statistic_node = newstack.pop()
              newthreadlist.append(current_statistic_node)
              for childnode in current_node.children_node:
                  stack.append(childnode)
                  child_statistic_node = HostStatisticNode(childnode)
                  current_statistic_node.children_node.append(
                      child_statistic_node
                  )
                  newstack.append(child_statistic_node)
              for runtimenode in current_node.runtime_node:
                  runtime_statistic_node = HostStatisticNode(
                      runtimenode
                  )
                  current_statistic_node.runtime_node.append(
                      runtime_statistic_node
                  )
      # recursive calculate node statistic values
      for thread_id, root_statistic_node in node_statistic_tree.items():
          root_statistic_node.cal_statistic()
  
      return node_statistic_tree, newresults
  
imports: import collections
  import os
  import sys
label_desc: Use image node_id 8 for calling a global function with example usage: wrap_tree(nodetrees) and returns: node_statistic_tree,  newresults