public VoltTable sortByAverage ( String tableName ) { List < ProcProfRow > sorted = new ArrayList < ProcProfRow > ( m_table ) ; Collections . sort ( sorted , new Comparator < ProcProfRow > ( ) { @ Override public int compare ( ProcProfRow lhs , ProcProfRow rhs ) { return compareByAvg ( rhs , lhs ) ; // sort desc } } ) ; long sumOfAverage = 0L ; for ( ProcProfRow row : sorted ) { sumOfAverage += ( row . avg * row . invocations ) ; } VoltTable result = TableShorthand . tableFromShorthand ( tableName + "(TIMESTAMP:BIGINT, PROCEDURE:VARCHAR, WEIGHTED_PERC:BIGINT, INVOCATIONS:BIGINT," + "AVG:BIGINT, MIN:BIGINT, MAX:BIGINT, ABORTS:BIGINT, FAILURES:BIGINT)" ) ; for ( ProcProfRow row : sorted ) { result . addRow ( row . timestamp , row . procedure , calculatePercent ( row . avg * row . invocations , sumOfAverage ) , row . invocations , row . avg , row . min , row . max , row . aborts , row . failures ) ; } return result ; }
Return table sorted by weighted avg