From d08b1ad1ec7500fe600a075c69ec72350ec89152 Mon Sep 17 00:00:00 2001 From: Vladimir Vukicevic Date: Tue, 26 Feb 2013 19:39:14 -0500 Subject: [PATCH] add cache debugging --- emar | 2 ++ emcc | 8 +++++++- emscripten.py | 17 +++++++++++++++++ tools/shared.py | 19 ++++++++++++------- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/emar b/emar index 60498b8f24ff9..5646f444cf676 100755 --- a/emar +++ b/emar @@ -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:] diff --git a/emcc b/emcc index 03b18242b1e4b..a6f0c12d396ae 100755 --- a/emcc +++ b/emcc @@ -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 @@ -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: diff --git a/emscripten.py b/emscripten.py index dc5d5f5babd70..4447833173367 100755 --- a/emscripten.py +++ b/emscripten.py @@ -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): @@ -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) diff --git a/tools/shared.py b/tools/shared.py index 1d189cc6dfb90..6f97737eeaa04 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -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 @@ -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: