[PATCH 1 of 3 V2] perf: use formatter more appropriately

Matt Mackall mpm at selenic.com
Tue Dec 8 17:57:19 CST 2015


On Sun, 2015-12-06 at 21:35 -0800, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc at gmail.com>
> # Date 1449458949 28800
> #      Sun Dec 06 19:29:09 2015 -0800
> # Node ID 5631b16093b4fa86a81eb4f26c22e0d660801e61
> # Parent  529a175577509223848f66f99a8dd8deb02cb304
> perf: use formatter more appropriately
> 
> Timer output is logically the same entity. Represent this by calling
> write() on the formatter exactly once. This will enable us to have
> more flexibility for timer output formatting.
> 
> With this patch, we can now do things like
> `hg perfstatus -T '{wall}\n'` to print just the wall time of output.

It's not at all clear to me why this should make a difference. The
formatter doesn't (or at least shouldn't!) separate "records" with
write() calls. It should work like this:

fm = formatter()
fm.startitem()
 <any number of write/plain/condwrite/data calls>
fm.startitem()
 <any number of write/plain/condwrite/data calls>
fm.start
item()
 <any number of write/plain/condwrite/data calls>
fm.end()

When using a templating formatter, the actual formatting occurs between
each record, via the showitem call in the startitem and end methods.

Also, the perfstatus command you mention seems to work perfectly fine
without this change.. so I'm utterly mystified:

$ hg perfstatus -T"{wall}\n"
0.00305891036987

$ hg perfstatus -Tjson
[
 {
  "comb": 0.01,
  "count": 951,
  "sys": 0.01,
  "user": 0.0,
  "wall": 0.00306510925293
 }
]

While unifying most of the output to a single write is good just on
general grounds, this patch also removes the title and result fields
from non-plain output by changing them from writes() to plains(). They
should arguably be condwrites().

-- 
Mathematics is the supreme nostalgia of our time.



More information about the Mercurial-devel mailing list