# HG changeset patch # User Bryan O'Sullivan # Date 2017-02-13 06:16:58 # Node ID be3a4fde38eb48f4f4c2bca27fc1523123b611b4 # Parent 8fa3ab6221b99562b00f9a6a05518ce58746442b statprof: add a path simplification function diff --git a/mercurial/statprof.py b/mercurial/statprof.py --- a/mercurial/statprof.py +++ b/mercurial/statprof.py @@ -713,6 +713,23 @@ def write_to_flame(data, fp, scriptpath= os.system("perl ~/flamegraph.pl %s > %s" % (path, outputfile)) print("Written to %s" % outputfile, file=fp) +_pathcache = {} +def simplifypath(path): + '''Attempt to make the path to a Python module easier to read by + removing whatever part of the Python search path it was found + on.''' + + if path in _pathcache: + return _pathcache[path] + hgpath = encoding.__file__.rsplit(os.sep, 2)[0] + for p in [hgpath] + sys.path: + prefix = p + os.sep + if path.startswith(prefix): + path = path[len(prefix):] + break + _pathcache[path] = path + return path + def write_to_json(data, fp): samples = []