Mercurial > hg
comparison mercurial/statprof.py @ 45942:89a2afe31e82
formating: upgrade to black 20.8b1
This required a couple of small tweaks to un-confuse black, but now it
works. Big formatting changes come from:
* Dramatically improved collection-splitting logic upstream
* Black having a strong (correct IMO) opinion that """ is better than '''
Differential Revision: https://phab.mercurial-scm.org/D9430
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Fri, 27 Nov 2020 17:03:29 -0500 |
parents | 9f70512ae2cf |
children | 068307b638f4 |
comparison
equal
deleted
inserted
replaced
45941:346af7687c6f | 45942:89a2afe31e82 |
---|---|
409 | 409 |
410 state.samples.append(Sample(sites, time)) | 410 state.samples.append(Sample(sites, time)) |
411 | 411 |
412 | 412 |
413 def reset(frequency=None): | 413 def reset(frequency=None): |
414 '''Clear out the state of the profiler. Do not call while the | 414 """Clear out the state of the profiler. Do not call while the |
415 profiler is running. | 415 profiler is running. |
416 | 416 |
417 The optional frequency argument specifies the number of samples to | 417 The optional frequency argument specifies the number of samples to |
418 collect per second.''' | 418 collect per second.""" |
419 assert state.profile_level == 0, b"Can't reset() while statprof is running" | 419 assert state.profile_level == 0, b"Can't reset() while statprof is running" |
420 CodeSite.cache.clear() | 420 CodeSite.cache.clear() |
421 state.reset(frequency) | 421 state.reset(frequency) |
422 | 422 |
423 | 423 |
523 fp.write(b'Sample count: %d\n' % len(data.samples)) | 523 fp.write(b'Sample count: %d\n' % len(data.samples)) |
524 fp.write(b'Total time: %f seconds (%f wall)\n' % data.accumulated_time) | 524 fp.write(b'Total time: %f seconds (%f wall)\n' % data.accumulated_time) |
525 | 525 |
526 | 526 |
527 def display_by_line(data, fp): | 527 def display_by_line(data, fp): |
528 '''Print the profiler data with each sample line represented | 528 """Print the profiler data with each sample line represented |
529 as one row in a table. Sorted by self-time per line.''' | 529 as one row in a table. Sorted by self-time per line.""" |
530 stats = SiteStats.buildstats(data.samples) | 530 stats = SiteStats.buildstats(data.samples) |
531 stats.sort(reverse=True, key=lambda x: x.selfseconds()) | 531 stats.sort(reverse=True, key=lambda x: x.selfseconds()) |
532 | 532 |
533 fp.write( | 533 fp.write( |
534 b'%5.5s %10.10s %7.7s %-8.8s\n' | 534 b'%5.5s %10.10s %7.7s %-8.8s\n' |
552 ) | 552 ) |
553 ) | 553 ) |
554 | 554 |
555 | 555 |
556 def display_by_method(data, fp): | 556 def display_by_method(data, fp): |
557 '''Print the profiler data with each sample function represented | 557 """Print the profiler data with each sample function represented |
558 as one row in a table. Important lines within that function are | 558 as one row in a table. Important lines within that function are |
559 output as nested rows. Sorted by self-time per line.''' | 559 output as nested rows. Sorted by self-time per line.""" |
560 fp.write( | 560 fp.write( |
561 b'%5.5s %10.10s %7.7s %-8.8s\n' | 561 b'%5.5s %10.10s %7.7s %-8.8s\n' |
562 % (b'% ', b'cumulative', b'self', b'') | 562 % (b'% ', b'cumulative', b'self', b'') |
563 ) | 563 ) |
564 fp.write( | 564 fp.write( |
833 | 833 |
834 _pathcache = {} | 834 _pathcache = {} |
835 | 835 |
836 | 836 |
837 def simplifypath(path): | 837 def simplifypath(path): |
838 '''Attempt to make the path to a Python module easier to read by | 838 """Attempt to make the path to a Python module easier to read by |
839 removing whatever part of the Python search path it was found | 839 removing whatever part of the Python search path it was found |
840 on.''' | 840 on.""" |
841 | 841 |
842 if path in _pathcache: | 842 if path in _pathcache: |
843 return _pathcache[path] | 843 return _pathcache[path] |
844 hgpath = encoding.__file__.rsplit(os.sep, 2)[0] | 844 hgpath = encoding.__file__.rsplit(os.sep, 2)[0] |
845 for p in [hgpath] + sys.path: | 845 for p in [hgpath] + sys.path: |