Skip to content

Commit

Permalink
add cache debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Vukicevic committed Feb 27, 2013
1 parent bafdc88 commit d08b1ad
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
2 changes: 2 additions & 0 deletions emar
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import os, subprocess, sys
from tools import shared

DEBUG = os.environ.get('EMCC_DEBUG')
if DEBUG == "0":
DEBUG = None

newargs = [shared.LLVM_AR] + sys.argv[1:]

Expand Down
8 changes: 7 additions & 1 deletion emcc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ LLVM_OPT_LEVEL = {
3: 3,
}

DEBUG = int(os.environ.get('EMCC_DEBUG') or 0)
DEBUG = os.environ.get('EMCC_DEBUG')
if DEBUG == "0":
DEBUG = None

TEMP_DIR = os.environ.get('EMCC_TEMP_DIR')
LEAVE_INPUTS_RAW = os.environ.get('EMCC_LEAVE_INPUTS_RAW') # Do not compile .ll files into .bc, just compile them with emscripten directly
# Not recommended, this is mainly for the test runner, or if you have some other
Expand Down Expand Up @@ -1120,7 +1123,10 @@ try:
(not LEAVE_INPUTS_RAW and not (suffix(temp_files[0]) in BITCODE_SUFFIXES or suffix(temp_files[0]) in DYNAMICLIB_SUFFIXES) and shared.Building.is_ar(temp_files[0])):
linker_inputs = temp_files + extra_files_to_link
if DEBUG: print >> sys.stderr, 'emcc: linking: ', linker_inputs
t0 = time.time()
shared.Building.link(linker_inputs, in_temp(target_basename + '.bc'))
t1 = time.time()
if DEBUG: print >> sys.stderr, 'emcc: linking took %.2f seconds' % (t1 - t0)
final = in_temp(target_basename + '.bc')
else:
if not LEAVE_INPUTS_RAW:
Expand Down
17 changes: 17 additions & 0 deletions emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
from tools import shared

DEBUG = os.environ.get('EMCC_DEBUG')
if DEBUG == "0":
DEBUG = None
DEBUG_CACHE = DEBUG and "cache" in DEBUG

__rootpath__ = os.path.abspath(os.path.dirname(__file__))
def path_from_root(*pathelems):
Expand Down Expand Up @@ -145,7 +148,21 @@ def save_settings():
if jcache:
keys = [pre_input, settings_text, ','.join(libraries)]
shortkey = shared.JCache.get_shortkey(keys)
if DEBUG_CACHE: print >>sys.stderr, 'shortkey', shortkey

out = shared.JCache.get(shortkey, keys)

if (not out) and DEBUG_CACHE:
dfpath = os.path.join(shared.TEMP_DIR, "ems_" + shortkey)
dfp = open(dfpath, 'w')
dfp.write(pre_input);
dfp.write("\n\n========================== settings_text\n\n");
dfp.write(settings_text);
dfp.write("\n\n========================== libraries\n\n");
dfp.write("\n".join(libraries))
dfp.close()
print >>sys.stderr, ' cache miss, key data dumped to %s' % dfpath

if out and DEBUG: print >> sys.stderr, ' loading pre from jcache'
if not out:
open(pre_file, 'w').write(pre_input)
Expand Down
19 changes: 12 additions & 7 deletions tools/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,11 @@ def build_llvm_tool_path(tool):
CANONICAL_TEMP_DIR = os.path.join(TEMP_DIR, 'emscripten_temp')
EMSCRIPTEN_TEMP_DIR = None

DEBUG = int(os.environ.get('EMCC_DEBUG') or 0)
DEBUG = os.environ.get('EMCC_DEBUG')
if DEBUG == "0":
DEBUG = None
DEBUG_CACHE = DEBUG and "cache" in DEBUG

if DEBUG:
try:
EMSCRIPTEN_TEMP_DIR = CANONICAL_TEMP_DIR
Expand Down Expand Up @@ -1240,29 +1244,30 @@ def get_cachename(shortkey):
# Returns a cached value, if it exists. Make sure the full key matches
@staticmethod
def get(shortkey, keys):
#if DEBUG: print >> sys.stderr, 'jcache get?', shortkey
if DEBUG_CACHE: print >> sys.stderr, 'jcache get?', shortkey
cachename = JCache.get_cachename(shortkey)
if not os.path.exists(cachename):
#if DEBUG: print >> sys.stderr, 'jcache none at all'
if DEBUG_CACHE: print >> sys.stderr, 'jcache none at all'
return
data = cPickle.Unpickler(open(cachename, 'rb')).load()
if len(data) != 2:
#if DEBUG: print >> sys.stderr, 'jcache error in get'
if DEBUG_CACHE: print >> sys.stderr, 'jcache error in get'
return
oldkeys = data[0]
if len(oldkeys) != len(keys):
#if DEBUG: print >> sys.stderr, 'jcache collision (a)'
if DEBUG_CACHE: print >> sys.stderr, 'jcache collision (a)'
return
for i in range(len(oldkeys)):
if oldkeys[i] != keys[i]:
#if DEBUG: print >> sys.stderr, 'jcache collision (b)'
if DEBUG_CACHE: print >> sys.stderr, 'jcache collision (b)'
return
#if DEBUG: print >> sys.stderr, 'jcache win'
if DEBUG_CACHE: print >> sys.stderr, 'jcache win'
return data[1]

# Sets the cached value for a key (from get_key)
@staticmethod
def set(shortkey, keys, value):
if DEBUG_CACHE: print >> sys.stderr, 'save to cache', shortkey
cachename = JCache.get_cachename(shortkey)
cPickle.Pickler(open(cachename, 'wb')).dump([keys, value])
#if DEBUG:
Expand Down

0 comments on commit d08b1ad

Please sign in to comment.