<s> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> from dump import * <EOL> from math import log <EOL> from hilbert import hilbert <EOL> import remote , sys , png , struct , time <EOL> def categorize_block ( d , address , size , addr_space = '<STR_LIT>' ) : <EOL> t1 = time . time ( ) <EOL> try : <EOL> head = read_block ( d , address , size , max_round_trips = <NUM_LIT:1> , addr_space = addr_space ) <EOL> except IOError , e : <EOL> print e <EOL> head = None <EOL> t2 = time . time ( ) <EOL> if head is None : <EOL> return [ <NUM_LIT> , <NUM_LIT> , t2 - t1 ] <EOL> red = <NUM_LIT:0> <EOL> green = <NUM_LIT:0> <EOL> prev = '<STR_LIT:\x00>' <EOL> for b in head : <EOL> signed_diff = struct . unpack ( '<STR_LIT:b>' , struct . pack ( '<STR_LIT:B>' , <NUM_LIT> & ( ord ( b ) - ord ( prev ) ) ) ) [ <NUM_LIT:0> ] <EOL> red += ord ( b ) <EOL> green += signed_diff * signed_diff <EOL> prev = b <EOL> return [ <EOL> min ( <NUM_LIT> , max ( <NUM_LIT:0> , int ( red / len ( head ) ) ) ) , <EOL> green & <NUM_LIT> , <EOL> t2 - t1 <EOL> ] <EOL> def categorize_block_array ( d , base_address , blocksize , pixelsize , addr_space = '<STR_LIT>' ) : <EOL> print '<STR_LIT>' <EOL> a = [ ] <EOL> timestamp = time . time ( ) <EOL> first_time = timestamp <EOL> for y in xrange ( pixelsize ) : <EOL> row = [ ] <EOL> for x in xrange ( pixelsize ) : <EOL> addr = base_address + blocksize * hilbert ( x , y , pixelsize ) <EOL> row . extend ( categorize_block ( d , addr , blocksize , addr_space = addr_space ) ) <EOL> now = time . time ( ) <EOL> if now > timestamp + <NUM_LIT:0.5> : <EOL> completion = ( x + y * pixelsize ) / float ( pixelsize * pixelsize ) <EOL> elapsed = now - first_time <EOL> remaining = <NUM_LIT:0> <EOL> if completion > <NUM_LIT> : <EOL> total = elapsed / completion <EOL> if total > elapsed : <EOL> remaining = total - elapsed <EOL> print '<STR_LIT>' % ( <EOL> addr , x , y , pixelsize , <NUM_LIT:100> * completion , <EOL> elapsed / ( <NUM_LIT> * <NUM_LIT> ) , ( elapsed / <NUM_LIT> ) % <NUM_LIT> , elapsed % <NUM_LIT> , <EOL> remaining / ( <NUM_LIT> * <NUM_LIT> ) , ( remaining / <NUM_LIT> ) % <NUM_LIT> , remaining % <NUM_LIT> ) <EOL> timestamp = now <EOL> a . append ( row ) <EOL> print '<STR_LIT>' <EOL> times = [ ] <EOL> for row in a : <EOL> for x in xrange ( pixelsize ) : <EOL> times . append ( row [ <NUM_LIT:2> + <NUM_LIT:3> * x ] ) <EOL> times . sort ( ) <EOL> percentile_low = log ( times [ int ( len ( times ) * <NUM_LIT> ) ] ) <EOL> percentile_high = log ( times [ int ( len ( times ) * <NUM_LIT> ) ] ) <EOL> percentile_s = <NUM_LIT> / ( percentile_high - percentile_low ) <EOL> for row in a : <EOL> for x in xrange ( pixelsize ) : <EOL> row [ <NUM_LIT:2> + <NUM_LIT:3> * x ] = min ( <NUM_LIT:255> , max ( <NUM_LIT:0> , int ( <NUM_LIT:0.5> + ( log ( row [ <NUM_LIT:2> + <NUM_LIT:3> * x ] ) - percentile_low ) * percentile_s ) ) ) <EOL> print '<STR_LIT>' <EOL> return a <EOL> def memsquare ( d , filename , base_address , blocksize , pixelsize = <NUM_LIT> , addr_space = '<STR_LIT>' ) : <EOL> b = categorize_block_array ( d , base_address , blocksize , pixelsize , addr_space = addr_space ) <EOL> w = png . Writer ( len ( b [ <NUM_LIT:0> ] ) / <NUM_LIT:3> , len ( b ) ) <EOL> f = open ( filename , '<STR_LIT:wb>' ) <EOL> w . write ( f , b ) <EOL> f . close ( ) <EOL> print '<STR_LIT>' % filename <EOL> def survey ( ) : <EOL> memsquare ( remote . Device ( ) , '<STR_LIT>' , <NUM_LIT:0> , <NUM_LIT> ) <EOL> def low64 ( ) : <EOL> memsquare ( remote . Device ( ) , '<STR_LIT>' , <NUM_LIT:0> , <NUM_LIT:4> ) <EOL> def mmio ( ) : <EOL> memsquare ( remote . Device ( ) , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT> ) <EOL> def dram ( ) : <EOL> memsquare ( remote . Device ( ) , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT:16> , <NUM_LIT> ) <EOL> def sram ( ) : <EOL> memsquare ( remote . Device ( ) , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:64> ) <EOL> def dma ( ) : <EOL> memsquare ( remote . Device ( ) , '<STR_LIT>' , <NUM_LIT:0> , <NUM_LIT:16> , <NUM_LIT> , '<STR_LIT>' ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> modes = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if len ( sys . argv ) == <NUM_LIT:2> and sys . argv [ <NUM_LIT:1> ] in modes : <EOL> globals ( ) [ sys . argv [ <NUM_LIT:1> ] ] ( ) <EOL> else : <EOL> print '<STR_LIT>' % ( sys . argv [ <NUM_LIT:0> ] , '<STR_LIT>' . join ( modes ) ) </s>
