#! /usr/bin/env python3"""Transform gprof(1) output into useful HTML."""import htmlimport osimport reimport sysimport webbrowserheader = """\<html><head><title>gprof output (%s)</title></head><body><pre>"""trailer = """\</pre></body></html>"""def add_escapes(filename):with open(filename) as fp:for line in fp:yield html.escape(line)def main():filename = "gprof.out"if sys.argv[1:]:filename = sys.argv[1]outputfilename = filename + ".html"input = add_escapes(filename)output = open(outputfilename, "w")output.write(header % filename)for line in input:output.write(line)if line.startswith(" time"):breaklabels = {}for line in input:m = re.match(r"(.* )(\w+)\n", line)if not m:output.write(line)breakstuff, fname = m.group(1, 2)labels[fname] = fnameoutput.write('%s<a name="flat:%s" href="#call:%s">%s</a>\n' %(stuff, fname, fname, fname))for line in input:output.write(line)if line.startswith("index % time"):breakfor line in input:m = re.match(r"(.* )(\w+)(( <cycle.*>)? \[\d+\])\n", line)if not m:output.write(line)if line.startswith("Index by function name"):breakcontinueprefix, fname, suffix = m.group(1, 2, 3)if fname not in labels:output.write(line)continueif line.startswith("["):output.write('%s<a name="call:%s" href="#flat:%s">%s</a>%s\n' %(prefix, fname, fname, fname, suffix))else:output.write('%s<a href="#call:%s">%s</a>%s\n' %(prefix, fname, fname, suffix))for line in input:for part in re.findall(r"(\w+(?:\.c)?|\W+)", line):if part in labels:part = '<a href="#call:%s">%s</a>' % (part, part)output.write(part)output.write(trailer)output.close()webbrowser.open("file:" + os.path.abspath(outputfilename))if __name__ == '__main__':main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。