def prune(self, node_thres, edge_thres, paths, color_nodes_by_selftime):
<EOL>for function in compat_itervalues(self.functions):<EOL><INDENT>try:<EOL><INDENT>function.weight = function[TOTAL_TIME_RATIO]<EOL><DEDENT>except UndefinedEvent:<EOL><INDENT>pass<EOL><DEDENT>for call in compat_itervalues(function.calls):<EOL><INDENT>callee = self.functions[call.callee_id]<EOL>if TOTAL_TIME_RATIO in call:<EOL><INDENT>call.weight = call[TOTAL_TIME_RATIO] <EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>call.weight = min(function[TOTAL_TIME_RATIO], callee[TOTAL_TIME_RATIO]) <EOL><DEDENT>except UndefinedEvent:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT><DEDENT>for function_id in compat_keys(self.functions):<EOL><INDENT>function = self.functions[function_id]<EOL>if function.weight is not None:<EOL><INDENT>if function.weight < node_thres:<EOL><INDENT>del self.functions[function_id]<EOL><DEDENT><DEDENT><DEDENT>for function_id in compat_keys(self.functions):<EOL><INDENT>function = self.functions[function_id]<EOL>if paths and function.filename and not any(function.filename.startswith(path) for path in paths):<EOL><INDENT>del self.functions[function_id]<EOL><DEDENT>elif paths and function.module and not any((function.module.find(path)>-<NUM_LIT:1>) for path in paths):<EOL><INDENT>del self.functions[function_id]<EOL><DEDENT><DEDENT>for function in compat_itervalues(self.functions):<EOL><INDENT>for callee_id in compat_keys(function.calls):<EOL><INDENT>call = function.calls[callee_id]<EOL>if callee_id not in self.functions or call.weight is not None and call.weight < edge_thres:<EOL><INDENT>del function.calls[callee_id]<EOL><DEDENT><DEDENT><DEDENT>if color_nodes_by_selftime:<EOL><INDENT>weights = []<EOL>for function in compat_itervalues(self.functions):<EOL><INDENT>try:<EOL><INDENT>weights.append(function[TIME_RATIO])<EOL><DEDENT>except UndefinedEvent:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>max_ratio = max(weights or [<NUM_LIT:1>])<EOL>for function in compat_itervalues(self.functions):<EOL><INDENT>try:<EOL><INDENT>function.weight = function[TIME_RATIO] / max_ratio<EOL><DEDENT>except (ZeroDivisionError, UndefinedEvent):<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>
Prune the profile