#NEWLINE# def ParseResults( ycsb_result_string , data_type = 'histogram' ) : #NEWLINE# #INDENT# "Parse YCSB results.\n\n  Example input:\n\n    YCSB Client 0.1\n    Command line: -db com.yahoo.ycsb.db.HBaseClient -P /tmp/pkb/workloada\n    [OVERALL], RunTime(ms), 1800413.0\n    [OVERALL], Throughput(ops/sec), 2740.503428935472\n    [UPDATE], Operations, 2468054\n    [UPDATE], AverageLatency(us), 2218.8513395574005\n    [UPDATE], MinLatency(us), 554\n    [UPDATE], MaxLatency(us), 352634\n    [UPDATE], 95thPercentileLatency(ms), 4\n    [UPDATE], 99thPercentileLatency(ms), 7\n    [UPDATE], Return=0, 2468054\n    [UPDATE], 0, 398998\n    [UPDATE], 1, 1015682\n    [UPDATE], 2, 532078\n    ...\n\n  Args:\n    ycsb_result_string: str. Text output from YCSB.\n    data_type: Either 'histogram' or 'timeseries'.\n\n  Returns:\n    A dictionary with keys:\n      client: containing YCSB version information.\n      command_line: Command line executed.\n      groups: list of operation group descriptions, each with schema:\n        group: group name (e.g., update, insert, overall)\n        statistics: dict mapping from statistic name to value\n        histogram: list of (ms_lower_bound, count) tuples, e.g.:\n          [(0, 530), (19, 1)]\n        indicates that 530 ops took between 0ms and 1ms, and 1 took between\n        19ms and 20ms. Empty bins are not reported.\n  " #NEWLINE# fp = io . BytesIO ( ycsb_result_string ) #NEWLINE# client_string = next ( fp ) . strip ( ) #NEWLINE# if ( not client_string . startswith ( 'YCSB Client 0.' ) ) : #NEWLINE# #INDENT# raise IOError ( 'Unexpected header: {0}' . format ( client_string ) ) #NEWLINE# #UNINDENT# command_line = next ( fp ) . strip ( ) #NEWLINE# if ( not command_line . startswith ( 'Command line:' ) ) : #NEWLINE# #INDENT# raise IOError ( 'Unexpected second line: {0}' . format ( command_line ) ) #NEWLINE# #UNINDENT# def LineFilter( line ) : #NEWLINE# #INDENT# return ( re . search ( '^\\[[A-Z]+\\]' , line ) is not None ) #NEWLINE# #UNINDENT# lines = itertools . ifilter ( LineFilter , fp ) #NEWLINE# r = csv . reader ( lines ) #NEWLINE# by_operation = itertools . groupby ( r , operator . itemgetter ( 0 ) ) #NEWLINE# result = collections . OrderedDict ( [ ( 'client' , client_string ) , ( 'command_line' , command_line ) , ( 'groups' , collections . OrderedDict ( ) ) ] ) #NEWLINE# for ( operation , lines ) in by_operation : #NEWLINE# #INDENT# operation = operation [ 1 : ( - 1 ) ] . lower ( ) #NEWLINE# op_result = { #NEWLINE# #INDENT# 'group' : operation , #NEWLINE# data_type : [ ] , #NEWLINE# 'statistics' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# for ( _ , name , val ) in lines : #NEWLINE# #INDENT# name = name . strip ( ) #NEWLINE# val = val . strip ( ) #NEWLINE# if name . startswith ( '>' ) : #NEWLINE# #INDENT# name = name [ 1 : ] #NEWLINE# #UNINDENT# val = ( float ( val ) if ( '.' in val ) else int ( val ) ) #NEWLINE# if name . isdigit ( ) : #NEWLINE# #INDENT# if val : #NEWLINE# #INDENT# op_result [ data_type ] . append ( ( int ( name ) , val ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( '(us)' in name ) : #NEWLINE# #INDENT# name = name . replace ( '(us)' , '(ms)' ) #NEWLINE# val /= 1000.0 #NEWLINE# #UNINDENT# op_result [ 'statistics' ] [ name ] = val #NEWLINE# #UNINDENT# #UNINDENT# result [ 'groups' ] [ operation ] = op_result #NEWLINE# #UNINDENT# return result