lib: Write depgraph counters to file

The same summary stats that are displayed in stdout can be written to a
file for consumption. Portage telemetry code could feasibly insert this
data to its own spans, but it may be useful to consume elsewhere, such
as on bots or elsewhere in chromite.

This patchset does not account for log rotation or cleaning; at time of
writing, it is recommended that clients that intend to consume this data
clean or rotate the log before running any `emerge` commands.

Other things to consider adding are:
* metadata (e.g. adding sys.argv as a field? timestamp?)
* writing flattened depgraph CPVRs
* omitting re-evaluated depgraphs that don't actually kick off `ebuild`
  phases
* saving the log file to ${PORTAGE_LOGDIR}/elog

Uploading this to see if it's a palatable idea. More thoughts are
available at
https://docs.google.com/document/d/1Gq6u4-2TS4QrN3WvND2rCkVdiEeuaXVW5E7b3EmeLrU/edit?usp=sharing.

BUG=none
TEST=cros build-packages, then looking at
/var/log/portage/depgraph_counters.log

Change-Id: I8e3522c518f33d9abb03cacdfc0ead268ff7dac0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/portage_tool/+/5021019
Tested-by: Lee Presland <zland@google.com>
Commit-Queue: Lee Presland <zland@google.com>
Reviewed-by: Alex Klein <saklein@chromium.org>
2 files changed