'Prune the profile'

def prune(self, node_thres, edge_thres):

    for function in self.functions.itervalues():
        try:
            function.weight = function[TOTAL_TIME_RATIO]
        except UndefinedEvent:
            pass
        for call in function.calls.itervalues():
            callee = self.functions[call.callee_id]
            if (TOTAL_TIME_RATIO in call):
                call.weight = call[TOTAL_TIME_RATIO]
            else:
                try:
                    call.weight = min(function[TOTAL_TIME_RATIO], callee[TOTAL_TIME_RATIO])
                except UndefinedEvent:
                    pass
    for function_id in self.functions.keys():
        function = self.functions[function_id]
        if (function.weight is not None):
            if (function.weight < node_thres):
                del self.functions[function_id]
    for function in self.functions.itervalues():
        for callee_id in function.calls.keys():
            call = function.calls[callee_id]
            if ((callee_id not in self.functions) or ((call.weight is not None) and (call.weight < edge_thres))):
                del function.calls[callee_id]
