Commit efd22ad0 authored by George Hotz's avatar George Hotz

profiling

parent 24f6ce5f
...@@ -7,11 +7,11 @@ export GOMIPS=softfloat ...@@ -7,11 +7,11 @@ export GOMIPS=softfloat
# brew install llvm # brew install llvm
# ...and struggle to build musl # ...and struggle to build musl
# for 0 gain # for 0 gain
export CGO_ENABLED=1 #export CGO_ENABLED=1
export CC="$PWD/../risc/clangwrap.sh" #export CC="$PWD/../risc/clangwrap.sh"
go build -v -ldflags "-linkmode external -extldflags -static" #go build -v -ldflags "-linkmode external -extldflags -static"
#go build go build
cp go-ethereum ../risc/go-ethereum cp go-ethereum ../risc/go-ethereum
cd ../risc cd ../risc
file go-ethereum file go-ethereum
......
...@@ -5,6 +5,7 @@ import math ...@@ -5,6 +5,7 @@ import math
import struct import struct
import binascii import binascii
import traceback import traceback
from collections import defaultdict
from elftools.elf.elffile import ELFFile from elftools.elf.elffile import ELFFile
from capstone import * from capstone import *
md = Cs(CS_ARCH_MIPS, CS_MODE_32 + CS_MODE_BIG_ENDIAN) md = Cs(CS_ARCH_MIPS, CS_MODE_32 + CS_MODE_BIG_ENDIAN)
...@@ -40,8 +41,10 @@ bcount = 0 ...@@ -40,8 +41,10 @@ bcount = 0
instrumenting = False instrumenting = False
instrumenting_all = False instrumenting_all = False
instructions_seen = set() instructions_seen = set()
profiler = defaultdict(int)
phit = 0
def hook_code_simple(uc, address, size, user_data): def hook_code_simple(uc, address, size, user_data):
global icount, bcount global icount, bcount, phit
#assert size == 4 #assert size == 4
try: try:
newicount = size//4 newicount = size//4
...@@ -52,7 +55,13 @@ def hook_code_simple(uc, address, size, user_data): ...@@ -52,7 +55,13 @@ def hook_code_simple(uc, address, size, user_data):
dat = "EMPTY BASIC BLOCK?!?" dat = "EMPTY BASIC BLOCK?!?"
#instructions_seen.add(dat.mnemonic) #instructions_seen.add(dat.mnemonic)
#print(sorted(list(instructions_seen))) #print(sorted(list(instructions_seen)))
print("%10d(%2d): %8x %-80s %s" % (icount, newicount, address, r[address] if address in r else "UNKNOWN", dat)) symbol = r[address] if address in r else "UNKNOWN"
profiler[symbol] += 1
phit += 1
print("%10d(%2d): %8x %-80s %s" % (icount, newicount, address, symbol, dat))
if bcount%1000000 == 0:
for k,v in sorted(profiler.items(), key=lambda x: -x[1])[:10]:
print("%-80s : %.2f%%" % (k, (v/phit)*100.))
icount += newicount icount += newicount
bcount += 1 bcount += 1
return True return True
...@@ -345,6 +354,7 @@ for section in elffile.iter_sections(): ...@@ -345,6 +354,7 @@ for section in elffile.iter_sections():
# nop gcenable # nop gcenable
mu.mem_write(symbol['st_value'], b"\x03\xe0\x00\x08\x00\x00\x00\x00") mu.mem_write(symbol['st_value'], b"\x03\xe0\x00\x08\x00\x00\x00\x00")
found += 1 found += 1
"""
if symbol.name == "runtime.load_g": if symbol.name == "runtime.load_g":
# hardware? # hardware?
mu.mem_write(symbol['st_value'], b"\x03\xe0\x00\x08\x00\x00\x00\x00") mu.mem_write(symbol['st_value'], b"\x03\xe0\x00\x08\x00\x00\x00\x00")
...@@ -355,6 +365,7 @@ for section in elffile.iter_sections(): ...@@ -355,6 +365,7 @@ for section in elffile.iter_sections():
found += 1 found += 1
if symbol.name == "_cgo_sys_thread_start": if symbol.name == "_cgo_sys_thread_start":
mu.mem_write(symbol['st_value'], b"\x03\xe0\x00\x08\x00\x00\x00\x00") mu.mem_write(symbol['st_value'], b"\x03\xe0\x00\x08\x00\x00\x00\x00")
"""
if symbol.name == "github.com/ethereum/go-ethereum/oracle.Halt": if symbol.name == "github.com/ethereum/go-ethereum/oracle.Halt":
#00400000: 2004dead ; <input:0> li $a0, 57005 #00400000: 2004dead ; <input:0> li $a0, 57005
# 00400004: 00042400 ; <input:1> sll $a0, $a0, 16 # 00400004: 00042400 ; <input:1> sll $a0, $a0, 16
...@@ -365,7 +376,7 @@ for section in elffile.iter_sections(): ...@@ -365,7 +376,7 @@ for section in elffile.iter_sections():
#traceback.print_exc() #traceback.print_exc()
pass pass
assert(found == 4) assert(found == 2)
#mu.hook_add(UC_HOOK_BLOCK, hook_code, user_data=mu) #mu.hook_add(UC_HOOK_BLOCK, hook_code, user_data=mu)
died_well = False died_well = False
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment