]> git.proxmox.com Git - mirror_edk2.git/blobdiff - AppPkg/Applications/Python/Python-2.7.2/Tools/scripts/analyze_dxp.py
edk2: Remove AppPkg, StdLib, StdLibPrivateInternalFiles
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Tools / scripts / analyze_dxp.py
diff --git a/AppPkg/Applications/Python/Python-2.7.2/Tools/scripts/analyze_dxp.py b/AppPkg/Applications/Python/Python-2.7.2/Tools/scripts/analyze_dxp.py
deleted file mode 100644 (file)
index 7800011..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-"""\r
-Some helper functions to analyze the output of sys.getdxp() (which is\r
-only available if Python was built with -DDYNAMIC_EXECUTION_PROFILE).\r
-These will tell you which opcodes have been executed most frequently\r
-in the current process, and, if Python was also built with -DDXPAIRS,\r
-will tell you which instruction _pairs_ were executed most frequently,\r
-which may help in choosing new instructions.\r
-\r
-If Python was built without -DDYNAMIC_EXECUTION_PROFILE, importing\r
-this module will raise a RuntimeError.\r
-\r
-If you're running a script you want to profile, a simple way to get\r
-the common pairs is:\r
-\r
-$ PYTHONPATH=$PYTHONPATH:<python_srcdir>/Tools/scripts \\r
-./python -i -O the_script.py --args\r
-...\r
-> from analyze_dxp import *\r
-> s = render_common_pairs()\r
-> open('/tmp/some_file', 'w').write(s)\r
-"""\r
-\r
-import copy\r
-import opcode\r
-import operator\r
-import sys\r
-import threading\r
-\r
-if not hasattr(sys, "getdxp"):\r
-    raise RuntimeError("Can't import analyze_dxp: Python built without"\r
-                       " -DDYNAMIC_EXECUTION_PROFILE.")\r
-\r
-\r
-_profile_lock = threading.RLock()\r
-_cumulative_profile = sys.getdxp()\r
-\r
-# If Python was built with -DDXPAIRS, sys.getdxp() returns a list of\r
-# lists of ints.  Otherwise it returns just a list of ints.\r
-def has_pairs(profile):\r
-    """Returns True if the Python that produced the argument profile\r
-    was built with -DDXPAIRS."""\r
-\r
-    return len(profile) > 0 and isinstance(profile[0], list)\r
-\r
-\r
-def reset_profile():\r
-    """Forgets any execution profile that has been gathered so far."""\r
-    with _profile_lock:\r
-        sys.getdxp()  # Resets the internal profile\r
-        global _cumulative_profile\r
-        _cumulative_profile = sys.getdxp()  # 0s out our copy.\r
-\r
-\r
-def merge_profile():\r
-    """Reads sys.getdxp() and merges it into this module's cached copy.\r
-\r
-    We need this because sys.getdxp() 0s itself every time it's called."""\r
-\r
-    with _profile_lock:\r
-        new_profile = sys.getdxp()\r
-        if has_pairs(new_profile):\r
-            for first_inst in range(len(_cumulative_profile)):\r
-                for second_inst in range(len(_cumulative_profile[first_inst])):\r
-                    _cumulative_profile[first_inst][second_inst] += (\r
-                        new_profile[first_inst][second_inst])\r
-        else:\r
-            for inst in range(len(_cumulative_profile)):\r
-                _cumulative_profile[inst] += new_profile[inst]\r
-\r
-\r
-def snapshot_profile():\r
-    """Returns the cumulative execution profile until this call."""\r
-    with _profile_lock:\r
-        merge_profile()\r
-        return copy.deepcopy(_cumulative_profile)\r
-\r
-\r
-def common_instructions(profile):\r
-    """Returns the most common opcodes in order of descending frequency.\r
-\r
-    The result is a list of tuples of the form\r
-      (opcode, opname, # of occurrences)\r
-\r
-    """\r
-    if has_pairs(profile) and profile:\r
-        inst_list = profile[-1]\r
-    else:\r
-        inst_list = profile\r
-    result = [(op, opcode.opname[op], count)\r
-              for op, count in enumerate(inst_list)\r
-              if count > 0]\r
-    result.sort(key=operator.itemgetter(2), reverse=True)\r
-    return result\r
-\r
-\r
-def common_pairs(profile):\r
-    """Returns the most common opcode pairs in order of descending frequency.\r
-\r
-    The result is a list of tuples of the form\r
-      ((1st opcode, 2nd opcode),\r
-       (1st opname, 2nd opname),\r
-       # of occurrences of the pair)\r
-\r
-    """\r
-    if not has_pairs(profile):\r
-        return []\r
-    result = [((op1, op2), (opcode.opname[op1], opcode.opname[op2]), count)\r
-              # Drop the row of single-op profiles with [:-1]\r
-              for op1, op1profile in enumerate(profile[:-1])\r
-              for op2, count in enumerate(op1profile)\r
-              if count > 0]\r
-    result.sort(key=operator.itemgetter(2), reverse=True)\r
-    return result\r
-\r
-\r
-def render_common_pairs(profile=None):\r
-    """Renders the most common opcode pairs to a string in order of\r
-    descending frequency.\r
-\r
-    The result is a series of lines of the form:\r
-      # of occurrences: ('1st opname', '2nd opname')\r
-\r
-    """\r
-    if profile is None:\r
-        profile = snapshot_profile()\r
-    def seq():\r
-        for _, ops, count in common_pairs(profile):\r
-            yield "%s: %s\n" % (count, ops)\r
-    return ''.join(seq())\r