mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 16:57:49 +03:00
statprof: do no use colors if output is not stderr
Summary: statprof hardcodes colors. When outputting to blackbox or other files, colors should be disabled. Note: since fp is buffered, we cannot get the information from `isatty` reliably. Reviewed By: markbt Differential Revision: D9828546 fbshipit-source-id: 2c0ab839850ab213c2dc5cf4e2754dd6e357545c
This commit is contained in:
parent
1a9c73c079
commit
69fa3893cb
@ -156,6 +156,9 @@ def statprofile(ui, fp):
|
||||
limit = ui.configwith(fraction, "profiling", "showmin", 0.05)
|
||||
kwargs["limit"] = limit
|
||||
|
||||
if ui.config("profiling", "output"):
|
||||
kwargs["color"] = False
|
||||
|
||||
statprof.display(fp, data=data, format=displayformat, **kwargs)
|
||||
|
||||
|
||||
|
@ -693,6 +693,15 @@ def display_hotpath(data, fp, limit=0.05, **kwargs):
|
||||
root.add(sample.stack[::-1], sample.time - lasttime)
|
||||
lasttime = sample.time
|
||||
|
||||
if kwargs.get("color", True):
|
||||
redformat = "\033[91m%s\033[0m"
|
||||
greyformat = "\033[90m%s\033[0m"
|
||||
whiteformat = "%s"
|
||||
else:
|
||||
redformat = "* %s"
|
||||
greyformat = " %s"
|
||||
whiteformat = " %s"
|
||||
|
||||
def _write(node, depth, multiple_siblings):
|
||||
site = node.site
|
||||
visiblechildren = [
|
||||
@ -725,10 +734,12 @@ def display_hotpath(data, fp, limit=0.05, **kwargs):
|
||||
childrensamples = sum([c.count for c in node.children.itervalues()])
|
||||
# Make frames that performed more than 10% of the operation red
|
||||
if node.count - childrensamples > (0.1 * root.count):
|
||||
finalstring = "\033[91m" + finalstring + "\033[0m"
|
||||
finalstring = redformat % finalstring
|
||||
# Make frames that didn't actually perform work dark grey
|
||||
elif node.count - childrensamples == 0:
|
||||
finalstring = "\033[90m" + finalstring + "\033[0m"
|
||||
finalstring = greyformat % finalstring
|
||||
else:
|
||||
finalstring = whiteformat % finalstring
|
||||
print(finalstring, file=fp)
|
||||
|
||||
newdepth = depth
|
||||
|
Loading…
Reference in New Issue
Block a user