def gen_decl(op): sig = '{}{} {{}}({});'.format( 'template <typename T> ' \ if 'v' not in op.params[1:] and \ 'l' not in op.params[1:] else '', get_type(op.params[0], True), ', '.join(['{} {}'.format( get_type(op.params[i + 1]), common.get_arg(i)) \ for i in range(len(op.params[1:]))]) ) ret = 'namespace nsimd {\n' \ 'namespace fixed_point {\n\n' + sig.format(op.name) + '\n\n' if op.cxx_operator != None: ret += sig.format('operator' + op.cxx_operator) + '\n\n' ret += '} // namespace fixed_point\n' \ '} // namespace nsimd' return ret
def get_impl(operator, totyp, typ): global fmtspec fmtspec = { 'in0': common.in0, 'in1': common.in1, 'in2': common.in2, 'typ': typ, 'totyp': totyp, 'typnbits': typ[1:] } if operator.name == 'trunc': if typ in common.iutypes: return 'return {in0};'.format(**fmtspec) elif typ == 'f16': c89_code = \ '''f32 buf = nsimd_f16_to_f32({in0}); return nsimd_f32_to_f16(buf >= 0.0f ? nsimd_scalar_floor_f32(buf) : nsimd_scalar_ceil_f32(buf));'''. \ format(**fmtspec) else: c89_code = \ '''return {in0} >= 0.0{f} ? nsimd_scalar_floor_{typ}({in0}) : nsimd_scalar_ceil_{typ}({in0});'''. \ format(f='f' if typ == 'f32' else '', **fmtspec) return libm_opn('trunc', 1, typ, True, c89_code) if operator.name == 'abs': if typ == 'f16': return '''f32 tmp = nsimd_f16_to_f32({in0}); return nsimd_f32_to_f16(tmp >= 0.0f ? tmp : -tmp);'''. \ format(**fmtspec) elif typ in common.utypes: return 'return {in0};'.format(**fmtspec) else: return 'return ({typ})({in0} >= ({typ})0 ? {in0} : -{in0});'. \ format(**fmtspec) if operator.name in ['min', 'max']: op = '<' if operator.name == 'min' else '>' if typ == 'f16': return '''f32 in0 = nsimd_f16_to_f32({in0}); f32 in1 = nsimd_f16_to_f32({in1}); return nsimd_f32_to_f16(in0 {op} in1 ? in0 : in1);'''. \ format(op=op, **fmtspec) else: return 'return {in0} {op} {in1} ? {in0} : {in1};'. \ format(op=op, **fmtspec) if operator.name == 'to_logical': if typ in common.iutypes: return 'return {in0} != ({typ})0;'.format(**fmtspec) else: return '''return nsimd_scalar_reinterpret_u{typnbits}_{typ}( {in0}) != (u{typnbits})0;'''.format(**fmtspec) if operator.name == 'to_mask': if typ in common.utypes: return 'return ({typ})({in0} ? -1 : 0);'.format(**fmtspec) else: return '''return nsimd_scalar_reinterpret_{typ}_u{typnbits}(( u{typnbits})({in0} ? -1 : 0));'''. \ format(**fmtspec) if operator.name == 'round_to_even': return round_to_even(typ) if operator.name in ['floor', 'ceil', 'sqrt']: if typ in common.iutypes and operator.name != 'sqrt': return 'return {in0};'.format(**fmtspec) return libm_opn(operator.name, 1, typ, False, '') if operator.name == 'fma': if typ in common.iutypes: return 'return ({typ})({in0} * {in1} + {in2});'.format(**fmtspec) else: if typ == 'f16': c89_code = 'return nsimd_f32_to_f16(nsimd_f16_to_f32({in0}) ' \ '* nsimd_f16_to_f32({in1}) ' \ '+ nsimd_f16_to_f32({in2}));'.format(**fmtspec) else: c89_code = 'return {in0} * {in1} + {in2};'.format(**fmtspec) return libm_opn(operator.name, 3, typ, False, c89_code) if operator.name in ['fnma', 'fms', 'fnms']: neg = '-' if operator.name in ['fnms', 'fnma'] else '' op = '-' if operator.name in ['fms', 'fnms'] else '+' if typ in common.iutypes: return 'return ({typ})(({neg}{in0}) * {in1} {op} {in2});'. \ format(neg=neg, op=op, **fmtspec) else: typ2 = 'f32' if typ == 'f16' else typ return opnum( 'nsimd_scalar_fma_{typ2}({neg}{{in0}}, {{in1}}, {op}{{in2}})'. \ format(typ2=typ2, neg=neg, op=op, **fmtspec), typ) f = 'f' if typ in ['f16', 'f32'] else '' typ2 = 'f32' if typ == 'f16' else typ if operator.src: if typ == 'f16': return \ '''return nsimd_f32_to_f16( nsimd_sleef_{op_name}_scalar_f32({vas}));'''. \ format(op_name=operator.name, vas=', '.join(['nsimd_f16_to_f32({})'. \ format(common.get_arg(i)) \ for i in range(len(operator.params[1:]))]), **fmtspec) else: return 'return nsimd_sleef_{op_name}_scalar_{typ}({vas});'. \ format(op_name=operator.name, vas=common.get_args(len(operator.params[1:])), **fmtspec) func = { 'orb': lambda: opbit('{in0} | {in1}', typ), 'andb': lambda: opbit('{in0} & {in1}', typ), 'andnotb': lambda: opbit('{in0} & (~{in1})', typ), 'notb': lambda: opbit('~{in0}', typ), 'xorb': lambda: opbit('{in0} ^ {in1}', typ), 'add': lambda: opnum('{in0} + {in1}', typ), 'sub': lambda: opnum('{in0} - {in1}', typ), 'mul': lambda: opnum('{in0} * {in1}', typ), 'div': lambda: opnum('{in0} / {in1}', typ), 'neg': lambda: opnum('-{in0}', typ), 'lt': lambda: cmp('{in0} < {in1}', typ), 'gt': lambda: cmp('{in0} > {in1}', typ), 'le': lambda: cmp('{in0} <= {in1}', typ), 'ge': lambda: cmp('{in0} >= {in1}', typ), 'ne': lambda: cmp('{in0} != {in1}', typ), 'eq': lambda: cmp('{in0} == {in1}', typ), 'andl': lambda: 'return {in0} && {in1};'.format(**fmtspec), 'orl': lambda: 'return {in0} || {in1};'.format(**fmtspec), 'xorl': lambda: 'return {in0} ^ {in1};'.format(**fmtspec), 'andnotl': lambda: 'return {in0} && (!{in1});'.format(**fmtspec), 'notl': lambda: 'return !{in0};'.format(**fmtspec), 'shl': lambda: shift('shl', typ), 'shr': lambda: shift('shr', typ), 'shra': lambda: shift('shra', typ), 'reinterpret': lambda: reinterpret(totyp, typ), 'cvt': lambda: cvt(totyp, typ), 'adds': lambda: adds(typ), 'subs': lambda: subs(typ), 'rec': lambda: opnum('1.0{f} / {{in0}}'.format(f=f), typ), 'rec8': lambda: opnum('1.0{f} / {{in0}}'.format(f=f), typ), 'rec11': lambda: opnum('1.0{f} / {{in0}}'.format(f=f), typ), 'rsqrt': lambda: opnum('1.0{f} / nsimd_scalar_sqrt_{typ2}({{in0}})'. \ format(f=f, typ2=typ2), typ), 'rsqrt8': lambda: opnum('1.0{f} / nsimd_scalar_sqrt_{typ2}({{in0}})'. \ format(f=f, typ2=typ2), typ), 'rsqrt11': lambda: opnum('1.0{f} / nsimd_scalar_sqrt_{typ2}({{in0}})'. \ format(f=f, typ2=typ2), typ) } return func[operator.name]()
def cleanup(csv_in): """return all ether from accounts csv to funder""" conn = get_env_connection() funder = get_env_funder(conn) gas_price = get_gas_price_low() gas_limit = 21000 log(f"using gas price: {gas_price}, gas limit: {gas_limit}") account_results = csv_reader(csv_in, AccountResult) for i, account_result in enumerate(account_results): account = conn.get_account(account_result.private_key) log(f"cleaning up {account.address} ({i}/{len(account_results)})") balance = conn.get_balance(account.address) if balance >= gas_limit * gas_price: tx_hash = conn.send_ether(account, funder.address, balance - gas_limit * gas_price, gas_price, gas_limit) log(f"{account.address}, {balance}, {tx_hash}") else: log(f"balance too low: {balance}") time.sleep(INTERVAL) if __name__ == "__main__": cleanup(get_arg())
"""re-fetch stats and fill-in missing blocks""" conn = get_env_connection() block_results = csv_reader(block_csv_path, OldBlockResult) block_results_mem = {block_result.block_number: block_result for block_result in block_results} new_results = [] latest = None for i in range(int(block_results[-1].block_number), int(block_results[0].block_number) - 1, -1): k = str(i) if k in block_results_mem: latest = block_results_mem[k] my_timestamp = latest.my_timestamp block = conn.get_block(i) block_stats = conn.get_block_stats(block) row = BlockResult( block_number=block.number, block_timestamp=block.timestamp, my_timestamp=my_timestamp, timestamp_delta=int(my_timestamp) - int(block.timestamp), tx_count=block_stats.tx_count, avg_gas_price=block_stats.avg_gas_price, median_gas_price=block_stats.median_gas_price, q5_gas_price=block_stats.q5_gas_price, q95_gas_price=block_stats.q95_gas_price) log(row) new_results.append(row) writer.append_all(reversed(new_results)) if __name__ == "__main__": block_fixer(get_arg(), CSVWriter(f"{get_arg()}.fixed", BlockResult._fields))
from collections import namedtuple from block_monitor import BlockResult from common import get_arg, csv_reader, log, CSVWriter from load_test import TxResult OldTxResult = namedtuple("TxResult", "frm to tx_hash timestamp gas_price") if __name__ == "__main__": """add block_submitted_at to transactions that did not originally have it""" old_tx_results = csv_reader(get_arg(0), OldTxResult) block_results = csv_reader(get_arg(1), BlockResult) block_index = 0 tx_results = [] for i, old_tx in enumerate(old_tx_results): while block_results[block_index + 1].my_timestamp < old_tx.timestamp: block_index += 1 tx_result = TxResult( frm=old_tx.frm, to=old_tx.to, tx_hash=old_tx.tx_hash, timestamp=old_tx.timestamp, gas_price=old_tx.gas_price, block_at_submit=block_results[block_index].block_number) tx_results.append(tx_result) log(f"writing to {get_arg(2)}") CSVWriter(get_arg(2), TxResult._fields).append_all(tx_results)
def get_simd_implementation_src(operator, simd_ext, from_typ, fmtspec): if simd_ext == 'cpu': vlen = common.CPU_NBITS // int(from_typ[1:]) vasi = [] params = operator.params[1:] for i in range(len(params)): if params[i] in ['v', 'l', 'vi']: vasi.append('a{}.v{{i}}'.format(i)) else: vasi.append('a{}'.format(i)) vasi = ', '.join(vasi) typ2 = 'f32' if from_typ == 'f16' else from_typ if operator.params[0] == '_': body = '\n'.join( ['nsimd_scalar_{op_name}_{typ2}({vasi});'. \ format(op_name=operator.name, typ2=typ2, vasi=vasi.format(i=i)) for i in range(vlen)]) else: body = 'nsimd_cpu_v{} ret;\n'.format(from_typ) body += '\n'.join( ['ret.v{i} = nsimd_scalar_{op_name}_{typ2}({vasi});'. \ format(i=i, op_name=operator.name, typ2=typ2, vasi=vasi.format(i=i)) for i in range(vlen)]) body += '\nreturn ret;\n' return \ '''{hbar} NSIMD_INLINE {return_typ} NSIMD_VECTORCALL nsimd_{name}_{simd_ext}_{suf}({c_args}) {{ {body} }} #if NSIMD_CXX > 0 namespace nsimd {{ NSIMD_INLINE {return_typ} NSIMD_VECTORCALL {name}({cxx_args}) {{ {body} }} }} // namespace nsimd #endif '''.format(body=body, **fmtspec) if from_typ == 'f16': n = len(operator.params[1:]) f16_to_f32 = '\n'.join( ['nsimd_{simd_ext}_vf32x2 buf{i}' \ ' = nsimd_upcvt_{simd_ext}_f32_f16({args});'. \ format(i=i, args=common.get_arg(i), **fmtspec) \ for i in range(n)]) bufsv0 = ', '.join(['buf{}.v0'.format(i) for i in range(n)]) bufsv1 = ', '.join(['buf{}.v1'.format(i) for i in range(n)]) if operator.params[0] != '_': retv0 = 'nsimd_{simd_ext}_vf32 retv0 = '.format(**fmtspec) retv1 = 'nsimd_{simd_ext}_vf32 retv1 = '.format(**fmtspec) f32_to_f16 = \ 'return nsimd_downcvt_{simd_ext}_f16_f32(retv0, retv1);'. \ format(**fmtspec) else: retv0 = '' retv1 = '' f32_to_f16 = '' retv0 += '{sleef_symbol_prefix}_{simd_ext}_f32({bufsv0});'. \ format(bufsv0=bufsv0, **fmtspec) retv1 += '{sleef_symbol_prefix}_{simd_ext}_f32({bufsv1});'. \ format(bufsv1=bufsv1, **fmtspec) return \ '''{hbar} NSIMD_INLINE {return_typ} NSIMD_VECTORCALL nsimd_{name}_{simd_ext}_{suf}({c_args}) {{ {f16_to_f32} {retv0} {retv1} {f32_to_f16}}} #if NSIMD_CXX > 0 namespace nsimd {{ NSIMD_INLINE {return_typ} NSIMD_VECTORCALL {name}({cxx_args}) {{ {f16_to_f32} {retv0} {retv1} {f32_to_f16}}} }} // namespace nsimd #endif '''.format(f16_to_f32=f16_to_f32, retv0=retv0, retv1=retv1, f32_to_f16=f32_to_f16, **fmtspec) else: return \ '''{hbar} #if NSIMD_CXX > 0 extern "C" {{ #endif NSIMD_DLLSPEC {return_typ} NSIMD_VECTORCALL {sleef_symbol_prefix}_{simd_ext}_{suf}({c_args}); #if NSIMD_CXX > 0 }} // extern "C" #endif NSIMD_INLINE {return_typ} NSIMD_VECTORCALL nsimd_{name}_{simd_ext}_{suf}({c_args}) {{ {returns}{sleef_symbol_prefix}_{simd_ext}_{suf}({vas}); }} #if NSIMD_CXX > 0 namespace nsimd {{ NSIMD_INLINE {return_typ} NSIMD_VECTORCALL {name}({cxx_args}) {{ {returns}{sleef_symbol_prefix}_{simd_ext}_{suf}({vas}); }} }} // namespace nsimd #endif '''.format(**fmtspec)
import time from common import AccountResult, TxPlannedResult, csv_reader, get_arg, CSVWriter, now_str, Connection, \ get_env_connection, log if __name__ == "__main__": now = now_str() account_results = csv_reader(get_arg(0), AccountResult) env_connection = get_env_connection() offset = 28000 for i in range(offset, len(account_results)): account_result = account_results[i] balance = env_connection.get_balance(account_result.address) while balance == 0: time.sleep(1) balance = env_connection.get_balance(account_result.address) log(f"({i}/{len(account_results)}){account_result.address}: {balance}")
def get_impl(operator, totyp, typ): global fmtspec fmtspec = { 'in0': common.in0, 'in1': common.in1, 'in2': common.in2, 'typ': typ, 'totyp': totyp, 'typnbits': typ[1:] } # src operators if operator.src: cuda_ops = { 'sin_u35': 'sin', 'cos_u35': 'cos', 'tan_u35': 'tan', 'asin_u35': 'asin', 'acos_u35': 'acos', 'atan_u35': 'atan', 'atan2_u35': 'atan2', 'log_u35': 'log', 'cbrt_u35': 'cbrt', 'sin_u10': 'sin', 'cos_u10': 'cos', 'tan_u10': 'tan', 'asin_u10': 'asin', 'acos_u10': 'acos', 'atan_u10': 'atan', 'atan2_u10': 'atan2', 'log_u10': 'log', 'cbrt_u10': 'cbrt', 'exp_u10': 'exp', 'pow_u10': 'pow', 'sinh_u10': 'sinh', 'cosh_u10': 'cosh', 'tanh_u10': 'tanh', 'sinh_u35': 'sinh', 'cosh_u35': 'cosh', 'tanh_u35': 'tanh', 'asinh_u10': 'asinh', 'acosh_u10': 'acosh', 'atanh_u10': 'atanh', 'exp2_u10': 'exp2', 'exp2_u35': 'exp2', 'exp10_u10': 'exp10', 'exp10_u35': 'exp10', 'expm1_u10': 'expm1', 'log10_u10': 'log10', 'log2_u10': 'log2', 'log2_u35': 'log2', 'log1p_u10': 'log1p', 'sinpi_u05': 'sinpi', 'cospi_u05': 'cospi', 'hypot_u05': 'hypot', 'hypot_u35': 'hypot', 'remainder': 'remainder', 'fmod': 'fmod', 'lgamma_u10': 'lgamma', 'tgamma_u10': 'tgamma', 'erf_u10': 'erf', 'erfc_u15': 'erfc' } args = common.get_args(len(operator.params[1:])) cuda_op = cuda_ops[operator.name] if typ == 'f16': # For f16 CUDA offers only a few operator if cuda_op in [ 'cos', 'exp', 'exp10', 'exp2', 'log', 'log10', 'log2', 'sin' ]: return '''#if __CUDA_ARCH__ >= 530 return h{}({}); #else return __float2half(gpu_{}(__half2float({}))); #endif'''.format(cuda_op, args, operator.name, args) else: args = ', '.join('__half2float({})'.format(common.get_arg(i)) \ for i in range(len(operator.params[1:]))) return 'return __float2half(gpu_{}({}));'. \ format(operator.name, args) elif typ == 'f32': return 'return {}f({});'.format(cuda_op, args) else: return 'return {}({});'.format(cuda_op, args) # bool first, no special treatment for f16's bool_operators = { 'andl': 'return {in0} && {in1};', 'orl': 'return {in0} || {in1};', 'xorl': 'return {in0} ^ {in1};', 'andnotl': 'return {in0} && (!{in1});', 'notl': 'return !{in0};', } if operator.name in bool_operators: return bool_operators[operator.name].format(**fmtspec) # infix operators that needs type punning, no special treatment for f16's def pun_code(code, arity, typ): if typ in common.utypes: return 'return ' + code.format(**fmtspec) + ';' utyp = common.bitfield_type[typ] to_utyp = '\n'.join( ['''{utyp} buf{i}; memcpy(&buf{i}, &{{in{i}}}, sizeof({{in{i}}}));'''. \ format(i=i, utyp=utyp).format(**fmtspec) \ for i in range(arity)]) return '''{to_utyp} {utyp} tmp = {code}; {typ} ret; memcpy(&ret, &tmp, sizeof(tmp)); return ret;'''.format(to_utyp=to_utyp, utyp=utyp, typ=typ, code=code.format(in0='buf0', in1='buf1')) pun_operators = { 'orb': lambda: pun_code('{in0} | {in1}', 2, typ), 'andb': lambda: pun_code('{in0} & {in1}', 2, typ), 'andnotb': lambda: pun_code('{in0} & (~{in1})', 2, typ), 'notb': lambda: pun_code('~{in0}', 1, typ), 'xorb': lambda: pun_code('{in0} ^ {in1}', 2, typ), } if operator.name in pun_operators: return pun_operators[operator.name]() # reinterpret if operator.name == 'reinterpret': return reinterpret(totyp, typ) # cvt if operator.name == 'cvt': return 'return ({totyp}){in0};'.format(**fmtspec) # to_mask if operator.name == 'to_mask': if typ in common.utypes: return 'return ({typ})({in0} ? -1 : 0);'.format(**fmtspec) return 'return gpu_reinterpret({typ}(), ({utyp})({in0} ? -1 : 0));'. \ format(utyp=common.bitfield_type[typ], **fmtspec) # to_logical if operator.name == 'to_logical': if typ in common.iutypes: return 'return {in0} == ({typ})0 ? false : true;'.format(**fmtspec) return '''return gpu_reinterpret({utyp}(), {in0}) == ({utyp})0 ? false : true ;'''. \ format(utyp=common.bitfield_type[typ], **fmtspec) # for all other operators, f16 has a special treatment if typ == 'f16': return get_impl_f16(operator, totyp, typ) # then deal with f32's operators # first infix operators c_operators = { 'add': 'return ({typ})({in0} + {in1});', 'sub': 'return ({typ})({in0} - {in1});', 'mul': 'return ({typ})({in0} * {in1});', 'div': 'return ({typ})({in0} / {in1});', 'neg': 'return ({typ})(-{in0});', 'rec': 'return 1.0{f} / {in0};', 'rec8': 'return 1.0{f} / {in0};', 'rec11': 'return 1.0{f} / {in0};', 'lt': 'return {in0} < {in1};', 'gt': 'return {in0} > {in1};', 'le': 'return {in0} <= {in1};', 'ge': 'return {in0} >= {in1};', 'ne': 'return {in0} != {in1};', 'eq': 'return {in0} == {in1};', 'shl': 'return ({typ})({in0} << {in1});', } if operator.name in c_operators: return c_operators[operator.name]. \ format(f='f' if typ == 'f32' else '', **fmtspec) # right shifts if operator.name in ['shr', 'shra']: if typ in common.utypes: return 'return ({typ})({in0} >> {in1});'.format(**fmtspec) if operator.name == 'shr': return \ '''return gpu_reinterpret({typ}(), ({utyp})( gpu_reinterpret({utyp}(), {in0}) >> {in1}));'''. \ format(utyp=common.bitfield_type[typ], **fmtspec) # getting here means shra on signed types return \ '''if ({in1} == 0) {{ return {in0}; }} if ({in0} >= 0) {{ return gpu_reinterpret({typ}(), ({utyp})( gpu_reinterpret({utyp}(), {in0}) >> {in1})); }} else {{ {utyp} mask = ({utyp})((({utyp})-1) << ({typnbits} - {in1})); return gpu_reinterpret({typ}(), (({utyp})(mask | ({utyp})(gpu_reinterpret({utyp}(), {in0}) >> {in1})))); }}'''.format(utyp=common.bitfield_type[typ], **fmtspec) # adds if operator.name == 'adds': if typ in common.ftypes: return c_operators['add'].format(**fmtspec) else: return scalar.get_impl(operator, totyp, typ) # subs if operator.name == 'subs': if typ in common.ftypes: return c_operators['sub'].format(**fmtspec) elif typ in common.utypes: return scalar.get_impl(operator, totyp, typ) else: return 'return nsimd::gpu_adds({in0}, ({typ})(-{in1}));'. \ format(**fmtspec) # fma's if operator.name in ['fma', 'fms', 'fnma', 'fnms']: neg = '-' if operator.name in ['fnma, fnms'] else '' op = '-' if operator.name in ['fnms, fms'] else '' if typ in common.ftypes: return 'return fma{f}({neg}{in0}, {in1}, {op}{in2});'. \ format(f='f' if typ == 'f32' else '', neg=neg, op=op, **fmtspec) else: return 'return {neg}{in0} * {in1} + ({op}{in2});'. \ format(neg=neg, op=op, **fmtspec) # other operators if typ in common.iutypes: if operator.name in ['round_to_even', 'ceil', 'floor', 'trunc']: return 'return {in0};'.format(**fmtspec) elif operator.name == 'min': return 'return ({typ})({in0} < {in1} ? {in0} : {in1});'. \ format(**fmtspec) elif operator.name == 'max': return 'return ({typ})({in0} > {in1} ? {in0} : {in1});'. \ format(**fmtspec) elif operator.name == 'abs': return 'return ({typ})({in0} > 0 ? {in0} : -{in0});'. \ format(**fmtspec) else: cuda_name = { 'round_to_even': 'rint', 'min': 'fmin', 'max': 'fmax', 'abs': 'fabs', 'ceil': 'ceil', 'floor': 'floor', 'trunc': 'trunc', 'rsqrt8': 'rsqrt', 'rsqrt11': 'rsqrt' } args = ', '.join(['{{in{}}}'.format(i).format(**fmtspec) \ for i in range(len(operator.args))]) return 'return {name}{f}({args});'. \ format(name=cuda_name[operator.name] \ if operator.name in cuda_name else operator.name, f='f' if typ == 'f32' else '', args=args)
TxResult = namedtuple("TxResult", "frm to tx_hash timestamp gas_price block_at_submit") if __name__ == "__main__": now = now_str() tx_writer = CSVWriter(f"results/txs.{now}.csv", TxResult._fields) block_writer = CSVWriter(f"results/blocks.{now_str()}.csv", BlockResult._fields) env_connection = get_env_connection() env_config = get_env_config() log(f"load configuration is {env_config}") if has_args(): log("skipping preparations") accounts = [ AccountWrapper(account_result.private_key, 0) for account_result in csv_reader(get_arg(0), AccountResult) ] planned_tx = csv_reader(get_arg(1), TxPlannedResult) else: log("initiating preparations") env_funder = get_env_funder(env_connection) tx_plan_writer = CSVWriter(f"results/txs.planned.{now}.csv", TxPlannedResult._fields) account_writer = CSVWriter(f"results/accounts.{now}.csv", AccountResult._fields) accounts, planned_tx = prepare(env_connection, env_funder, env_config, account_writer, tx_plan_writer) load_test(env_connection, env_config, accounts, planned_tx, tx_writer, block_writer)
def collect_stats(tx_results, block_results, tx_plus_writer): conn = get_env_connection() block_cache = BlockCache(conn, block_results) for tx_result in tx_results: result = [] result.extend(tx_result) tx_hash = tx_result.tx_hash tx = conn.get_transaction_receipt(tx_hash) if tx and tx.blockNumber: result.append(str(tx.gasUsed)) result.append(str(tx.blockNumber)) for block_number in range(tx.blockNumber, tx.blockNumber + NUM_OF_BLOCKS): result.extend(block_cache.get(block_number)) tx_plus = TxPlusResult(*result) log(tx_plus) tx_plus_writer.append(tx_plus) if __name__ == "__main__": tx_plus_fields = [] tx_plus_fields.extend(TxResult._fields) tx_plus_fields.extend(['gas_used', 'block_number']) for i in range(1, 1 + NUM_OF_BLOCKS): tx_plus_fields.extend([f'timestamp_{i}', f'self_timestamp_{i}']) TxPlusResult = namedtuple("TxPlusResult", " ".join(tx_plus_fields)) collect_stats(csv_reader(get_arg(0), TxResult), csv_reader(get_arg(1), BlockResult), CSVWriter(get_arg(2), TxPlusResult._fields))