Mercurial > hg-stable
changeset 30948:be3a4fde38eb
statprof: add a path simplification function
author | Bryan O'Sullivan <bryano@fb.com> |
---|---|
date | Sun, 12 Feb 2017 22:16:58 -0800 |
parents | 8fa3ab6221b9 |
children | cb440e7af05d |
files | mercurial/statprof.py |
diffstat | 1 files changed, 17 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/statprof.py Sun Feb 12 21:44:55 2017 -0800 +++ b/mercurial/statprof.py Sun Feb 12 22:16:58 2017 -0800 @@ -713,6 +713,23 @@ 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 = []