Skip to content

Send timing/cache report to stderr#4946

Merged
stuhood merged 2 commits into
pantsbuild:masterfrom
twitter:stuhood/time-to-stderr
Oct 6, 2017
Merged

Send timing/cache report to stderr#4946
stuhood merged 2 commits into
pantsbuild:masterfrom
twitter:stuhood/time-to-stderr

Conversation

@stuhood

@stuhood stuhood commented Oct 5, 2017

Copy link
Copy Markdown
Member

Problem

--time is very useful to have enabled by default in automated environments, but currently renders to stdout.

Solution

Add errfile to PlainTextReporter, and render the timing and cache hit report ("epilog") to it.

Result

--time can safely be used in more cases.

@stuhood stuhood requested review from benjyw, ericzundel and kwlzn October 5, 2017 22:23
buffered_output = f.getvalue()
f.close()
return buffered_output

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider:

from contextlib import closing

@staticmethod
def _consume_stringio(f):
  with closing(f):
    f.flush()
    return f.getvalue()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this has much value unless the creation of f is part of the idiom. Here f is created far away, and there already so many other opportunities for it to leak that I suspect that this will be more misleading than helpful.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its really just a way to eliminate the buffered_output variable in this case by being able to directly return the output of f.getvalue().

indent=True, timing=True, cache_stats=True,
errfile = open(os.path.join(global_options.logdir, '{}.err.log'.format(run_id)), 'w')
settings = PlainTextReporter.Settings(log_level=log_level, outfile=outfile, errfile=errfile,
color=False, indent=True, timing=True, cache_stats=True,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make more sense to interleave (e.g. errfile=outfile) in the case of writing to logs vs stdio?

@stuhood stuhood Oct 6, 2017

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, probably.

EDIT: Eh... there are two issues here. 1) there is a convention of preserving the stdout/stderr split when executing processes, to make it meaningful, 2) since we've captured them as split during the bootstrap process, we can't usefully re-interleave those initial messages.

Will leave as is. Easy enough to change later.

class ReporterDestination(object):
OUT = 'out'
ERR = 'err'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not int constants vs strings?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was thinking debuggability, but I guess there would actually be a slight performance difference here, huh? Will switch.

buffered_output = f.getvalue()
f.close()
return buffered_output

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this has much value unless the creation of f is part of the idiom. Here f is created far away, and there already so many other opportunities for it to leak that I suspect that this will be more misleading than helpful.

@stuhood stuhood merged commit c94409d into pantsbuild:master Oct 6, 2017
@stuhood stuhood deleted the stuhood/time-to-stderr branch October 6, 2017 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants