|
13 | 13 | import rlp
|
14 | 14 | from rlp.utils import decode_hex, encode_hex, ascii_chr
|
15 | 15 |
|
| 16 | + |
| 17 | +TRACE_LVL_MAP = [ |
| 18 | + ':info', |
| 19 | + 'eth.vm.log:trace', |
| 20 | + ':info,eth.vm.log:trace,eth.vm.exit:trace', |
| 21 | + ':info,eth.vm.log:trace,eth.vm.op:trace,eth.vm.stack:trace', |
| 22 | + ':info,eth.vm.log:trace,eth.vm.op:trace,eth.vm.stack:trace,' + |
| 23 | + 'eth.vm.storage:trace,eth.vm.memory:trace' |
| 24 | +] |
| 25 | + |
| 26 | + |
16 | 27 | serpent = None
|
17 | 28 |
|
18 | 29 | u = ethereum.utils
|
@@ -199,31 +210,35 @@ def _send(self, sender, to, value, evmdata='', output=None,
|
199 | 210 | tx = t.Transaction(sendnonce, gas_price, gas_limit, to, value, evmdata)
|
200 | 211 | self.last_tx = tx
|
201 | 212 | tx.sign(sender)
|
| 213 | + recorder = None |
202 | 214 | if profiling > 1:
|
203 |
| - set_logging_level(3) |
204 |
| - recorder = LogRecorder() |
205 |
| - (s, o) = pb.apply_transaction(self.block, tx) |
206 |
| - if not s: |
207 |
| - raise TransactionFailed() |
208 |
| - out = {"output": o} |
209 |
| - if profiling > 0: |
210 |
| - zero_bytes = tx.data.count(ascii_chr(0)) |
211 |
| - non_zero_bytes = len(tx.data) - zero_bytes |
212 |
| - intrinsic_gas_used = opcodes.GTXCOST + \ |
213 |
| - opcodes.GTXDATAZERO * zero_bytes + \ |
214 |
| - opcodes.GTXDATANONZERO * non_zero_bytes |
215 |
| - ntm, ng = time.time(), self.block.gas_used |
216 |
| - out["time"] = ntm - tm |
217 |
| - out["gas"] = ng - g - intrinsic_gas_used |
218 |
| - if profiling > 1: |
219 |
| - trace = recorder.pop_records() |
220 |
| - set_logging_level(0) |
221 |
| - ops = [x['op'] for x in trace if x['event'] == 'vm'] |
222 |
| - opdict = {} |
223 |
| - for op in ops: |
224 |
| - opdict[op] = opdict.get(op, 0) + 1 |
225 |
| - out["ops"] = opdict |
226 |
| - return out |
| 215 | + recorder = LogRecorder(disable_other_handlers=True, log_config=TRACE_LVL_MAP[3]) |
| 216 | + try: |
| 217 | + (s, o) = pb.apply_transaction(self.block, tx) |
| 218 | + if not s: |
| 219 | + raise TransactionFailed() |
| 220 | + out = {"output": o} |
| 221 | + if profiling > 0: |
| 222 | + zero_bytes = tx.data.count(ascii_chr(0)) |
| 223 | + non_zero_bytes = len(tx.data) - zero_bytes |
| 224 | + intrinsic_gas_used = opcodes.GTXCOST + \ |
| 225 | + opcodes.GTXDATAZERO * zero_bytes + \ |
| 226 | + opcodes.GTXDATANONZERO * non_zero_bytes |
| 227 | + ntm, ng = time.time(), self.block.gas_used |
| 228 | + out["time"] = ntm - tm |
| 229 | + out["gas"] = ng - g - intrinsic_gas_used |
| 230 | + if profiling > 1: |
| 231 | + trace = recorder.pop_records() |
| 232 | + ops = [x['op'] for x in trace if x['event'] == 'vm'] |
| 233 | + opdict = {} |
| 234 | + for op in ops: |
| 235 | + opdict[op] = opdict.get(op, 0) + 1 |
| 236 | + out["ops"] = opdict |
| 237 | + return out |
| 238 | + finally: |
| 239 | + # ensure LogRecorder has been disabled |
| 240 | + if recorder: |
| 241 | + recorder.pop_records() |
227 | 242 |
|
228 | 243 | def profile(self, *args, **kwargs):
|
229 | 244 | kwargs['profiling'] = True
|
@@ -281,41 +296,6 @@ def revert(self, data):
|
281 | 296 | self.block._cached_rlp = None
|
282 | 297 | self.block.header._cached_rlp = None
|
283 | 298 |
|
284 |
| -# logging |
285 |
| - |
286 |
| - |
287 |
| -def set_logging_level(lvl=0): |
288 |
| - trace_lvl_map = [ |
289 |
| - ':info', |
290 |
| - 'eth.vm.log:trace', |
291 |
| - ':info,eth.vm.log:trace,eth.vm.exit:trace', |
292 |
| - ':info,eth.vm.log:trace,eth.vm.op:trace,eth.vm.stack:trace', |
293 |
| - ':info,eth.vm.log:trace,eth.vm.op:trace,eth.vm.stack:trace,' + |
294 |
| - 'eth.vm.storage:trace,eth.vm.memory:trace' |
295 |
| - ] |
296 |
| - configure_logging(config_string=trace_lvl_map[lvl]) |
297 |
| - if lvl == 0: |
298 |
| - set_level(None, 'info') |
299 |
| - print('Set logging level: %d' % lvl) |
300 |
| - |
301 |
| - |
302 |
| -def set_log_trace(logger_names=[]): |
303 |
| - """ |
304 |
| - sets all named loggers to level 'trace' |
305 |
| - attention: vm.op.* are only active if vm.op is active |
306 |
| - """ |
307 |
| - for name in logger_names: |
308 |
| - assert name in slogging.get_logger_names() |
309 |
| - slogging.set_level(name, 'trace') |
310 |
| - |
311 |
| - |
312 |
| -def enable_logging(): |
313 |
| - set_logging_level(1) |
314 |
| - |
315 |
| - |
316 |
| -def disable_logging(): |
317 |
| - set_logging_level(0) |
318 |
| - |
319 | 299 |
|
320 | 300 | gas_limit = 3141592
|
321 | 301 | gas_price = 1
|
0 commit comments