[PATCH 4 of 5 v2] statprof: allow rendering in the Chrome trace viewer format

Augie Fackler raf at durin42.com
Mon Feb 13 18:13:55 EST 2017


On Sun, Feb 12, 2017 at 10:39:56PM -0800, Bryan O'Sullivan wrote:
> # HG changeset patch
> # User Bryan O'Sullivan <bryano at fb.com>
> # Date 1486966820 28800
> #      Sun Feb 12 22:20:20 2017 -0800
> # Node ID 9c4ac8a20bd95c4069a20cf03a84b2c5c7b58def
> # Parent  857b6377296f47a9504e482981c90303986108b6
> statprof: allow rendering in the Chrome trace viewer format
>
> diff --git a/mercurial/statprof.py b/mercurial/statprof.py
> --- a/mercurial/statprof.py
> +++ b/mercurial/statprof.py
> @@ -433,6 +433,7 @@ class DisplayFormats:
>      Hotpath = 3
>      FlameGraph = 4
>      Json = 5
> +    Chrome = 6
>
>  def display(fp=None, format=3, data=None, **kwargs):
>      '''Print statistics, either to stdout or the given file object.'''
> @@ -457,10 +458,12 @@ def display(fp=None, format=3, data=None
>          write_to_flame(data, fp, **kwargs)
>      elif format == DisplayFormats.Json:
>          write_to_json(data, fp)
> +    elif format == DisplayFormats.Chrome:
> +        write_to_chrome(data, fp, **kwargs)

My Rust brain was reading this code and was about to get puzzled that you
didn't use an enum and have these just be
fn write(&self, data, fp) -> Result<(), Error>. And then I got sad.

>      else:
>          raise Exception("Invalid display format")
>
> -    if format != DisplayFormats.Json:
> +    if format not in (DisplayFormats.Json, DisplayFormats.Chrome):
>          print('---', file=fp)
>          print('Sample count: %d' % len(data.samples), file=fp)
>          print('Total time: %f seconds' % data.accumulated_time, file=fp)


More information about the Mercurial-devel mailing list