def get_top_n_locks(data, field, n, **kwargs): """Get top n locks according to the statistic on a field @param data the data from parse_lockstat_data @param field specify one field to sort (e.g. waittime-total, acquisitions and etc.) @param n only return the top N values Optional arguments @param percentage if set to True, returns the percentage of the specified field. @param in_second if set to True, returns the value in seconds. TODO: add support for sorting values per acquisition """ percentage = kwargs.get('percentage', False) in_second = kwargs.get('in_second', False) assert not (percentage and in_second) temp = {} for lockname, values in data.items(): temp[lockname] = values[field] if percentage: total_value = sum(temp.values()) for lockname, value in temp.items(): temp[lockname] = 1.0 * value / total_value elif in_second: # Returns values in second for lockname, value in temp.items(): temp[lockname] = value / (10.0 ** 6) return dict(sorted_by_value(temp, reverse=True)[:n])
def get_top_n_funcs_in_oprofile(data, event, topn): """Extract top N results of oprofile data @param data the oprofile parsed data @param event event name @param n top N """ temp = {} for func_name in data.keys(): temp[func_name] = data[func_name][event]['%'] return dict(sorted_by_value(temp, reverse=True)[:topn])