'Prune the profile'

def prune(self, node_thres, edge_thres, colour_nodes_by_selftime):

    for function in compat_itervalues(self.functions):
        try:
            function.weight = function[TOTAL_TIME_RATIO]
        except UndefinedEvent:
            pass
        for call in compat_itervalues(function.calls):
            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 compat_keys(self.functions):
        function = self.functions[function_id]
        if (function.weight is not None):
            if (function.weight < node_thres):
                del self.functions[function_id]
    for function in compat_itervalues(self.functions):
        for callee_id in compat_keys(function.calls):
            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]
    if colour_nodes_by_selftime:
        weights = []
        for function in compat_itervalues(self.functions):
            try:
                weights.append(function[TIME_RATIO])
            except UndefinedEvent:
                pass
        max_ratio = max((weights or [1]))
        for function in compat_itervalues(self.functions):
            try:
                function.weight = (function[TIME_RATIO] / max_ratio)
            except (ZeroDivisionError, UndefinedEvent):
                pass
