Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Unified Diff: tools/telemetry/third_party/coverage/lab/show_pyc.py

Issue 1366913004: Add coverage Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/third_party/coverage/lab/show_pyc.py
diff --git a/tools/telemetry/third_party/coverage/lab/show_pyc.py b/tools/telemetry/third_party/coverage/lab/show_pyc.py
new file mode 100644
index 0000000000000000000000000000000000000000..147c6ff847a846e4deae3d93c4670845e6dd0060
--- /dev/null
+++ b/tools/telemetry/third_party/coverage/lab/show_pyc.py
@@ -0,0 +1,73 @@
+# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
+
+import dis, marshal, struct, sys, time, types
+
+def show_pyc_file(fname):
+ f = open(fname, "rb")
+ magic = f.read(4)
+ moddate = f.read(4)
+ modtime = time.asctime(time.localtime(struct.unpack('<L', moddate)[0]))
+ print "magic %s" % (magic.encode('hex'))
+ print "moddate %s (%s)" % (moddate.encode('hex'), modtime)
+ code = marshal.load(f)
+ show_code(code)
+
+def show_py_file(fname):
+ text = open(fname).read().replace('\r\n', '\n')
+ show_py_text(text, fname=fname)
+
+def show_py_text(text, fname="<string>"):
+ code = compile(text, fname, "exec")
+ show_code(code)
+
+def show_code(code, indent=''):
+ print "%scode" % indent
+ indent += ' '
+ print "%sargcount %d" % (indent, code.co_argcount)
+ print "%snlocals %d" % (indent, code.co_nlocals)
+ print "%sstacksize %d" % (indent, code.co_stacksize)
+ print "%sflags %04x" % (indent, code.co_flags)
+ show_hex("code", code.co_code, indent=indent)
+ dis.disassemble(code)
+ print "%sconsts" % indent
+ for const in code.co_consts:
+ if type(const) == types.CodeType:
+ show_code(const, indent+' ')
+ else:
+ print " %s%r" % (indent, const)
+ print "%snames %r" % (indent, code.co_names)
+ print "%svarnames %r" % (indent, code.co_varnames)
+ print "%sfreevars %r" % (indent, code.co_freevars)
+ print "%scellvars %r" % (indent, code.co_cellvars)
+ print "%sfilename %r" % (indent, code.co_filename)
+ print "%sname %r" % (indent, code.co_name)
+ print "%sfirstlineno %d" % (indent, code.co_firstlineno)
+ show_hex("lnotab", code.co_lnotab, indent=indent)
+
+def show_hex(label, h, indent):
+ h = h.encode('hex')
+ if len(h) < 60:
+ print "%s%s %s" % (indent, label, h)
+ else:
+ print "%s%s" % (indent, label)
+ for i in range(0, len(h), 60):
+ print "%s %s" % (indent, h[i:i+60])
+
+def show_file(fname):
+ if fname.endswith('pyc'):
+ show_pyc_file(fname)
+ elif fname.endswith('py'):
+ show_py_file(fname)
+ else:
+ print "Odd file:", fname
+
+def main(args):
+ if args[0] == '-c':
+ show_py_text(" ".join(args[1:]).replace(";", "\n"))
+ else:
+ for a in args:
+ show_file(a)
+
+if __name__ == '__main__':
+ main(sys.argv[1:])
« no previous file with comments | « tools/telemetry/third_party/coverage/lab/show_platform.py ('k') | tools/telemetry/third_party/coverage/metacov.ini » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698