Re: [PATCH 1/5] perf stat: add perf stat -B to pretty print large numbers

From: Stephane Eranian
Date: Mon May 31 2010 - 15:42:26 EST


On Mon, May 31, 2010 at 9:11 PM, <Valdis.Kletnieks@xxxxxx> wrote:
> On Tue, 18 May 2010 23:08:16 -0300, Arnaldo Carvalho de Melo said:
>
> (Sorry for late reply)
>
>> instance LC_NUMERIC=en_US.UTF8. You need to pass -B to activate this
>> feature. This way existing scripts parsing the output do not need to be
>> changed. Here is an example.
>>
>> $ perf stat noploop 2
>> noploop for 2 seconds
>>
>> ÂPerformance counter stats for 'noploop 2':
>>
>>     1998.347031 Âtask-clock-msecs     #   Â0.998 CPUs
>>         Â61 Âcontext-switches     #   Â0.000 M/sec
>>          0 ÂCPU-migrations      #   Â0.000 M/sec
>>         118 Âpage-faults       Â#   Â0.000 M/sec
>>    4,138,410,900 Âcycles          #  2070.917 M/sec Â(scaled from 70.01%)
>>    2,062,650,268 Âinstructions       #   Â0.498 IPC  Â(scaled from 70.01%)
>>    2,057,653,466 Âbranches         #  1029.678 M/sec Â(scaled from 70.01%)
>>       Â40,267 Âbranch-misses      Â#   Â0.002 %   Â(scaled from 30.04%)
>>    2,055,961,348 Âcache-references     #  1028.831 M/sec Â(scaled from 30.03%)
>>       Â53,725 Âcache-misses       #   Â0.027 M/sec Â(scaled from 30.02%)
>>
>> Â Â Â Â 2.001393933 Âseconds time elapsed
>>
>> $ perf stat -B Ânoploop 2
>> noploop for 2 seconds
>>
>> ÂPerformance counter stats for 'noploop 2':
>>
>>     1998.297883 Âtask-clock-msecs     #   Â0.998 CPUs
>>         Â59 Âcontext-switches     #   Â0.000 M/sec
>>          0 ÂCPU-migrations      #   Â0.000 M/sec
>>         119 Âpage-faults       Â#   Â0.000 M/sec
>>    4,131,380,160 Âcycles          #  2067.450 M/sec Â(scaled from 70.01%)
>>    2,059,096,507 Âinstructions       #   Â0.498 IPC  Â(scaled from 70.01%)
>>    2,054,681,303 Âbranches         #  1028.216 M/sec Â(scaled from 70.01%)
>>       Â25,650 Âbranch-misses      Â#   Â0.001 %   Â(scaled from 30.05%)
>>    2,056,283,014 Âcache-references     #  1029.017 M/sec Â(scaled from 30.03%)
>>       Â47,097 Âcache-misses       #   Â0.024 M/sec Â(scaled from 30.02%)
>>
>> Â Â Â Â 2.001391016 Âseconds time elapsed
>
> Is it me, or did -B not make any difference for these two examples?
> I'm confused.
>
Did you set the LC_NUMERIC environement variable?

>> - Â Â fprintf(stderr, " %14.6f Â%-24s", msecs, event_name(counter));
>> + Â Â fprintf(stderr, " %18.6f Â%-24s", msecs, event_name(counter));
>
>> - Â Â fprintf(stderr, " %14.0f Â%-24s", avg, event_name(counter));
>> + Â Â if (big_num)
>> + Â Â Â Â Â Â fprintf(stderr, " %'18.0f Â%-24s", avg, event_name(counter));
>> + Â Â else
>> + Â Â Â Â Â Â fprintf(stderr, " %18.0f Â%-24s", avg, event_name(counter));
>
>> - Â Â Â Â Â Â fprintf(stderr, " %14s Â%-24s\n",
>> + Â Â Â Â Â Â fprintf(stderr, " %18s Â%-24s\n",
>> Â Â Â Â Â Â Â Â Â Â Â "<not counted>", event_name(counter));
>
>> - Â Â fprintf(stderr, " %14.9f Âseconds time elapsed",
>> + Â Â fprintf(stderr, " %18.9f Âseconds time elapsed",
>
> Why is the 'if (big_num)' applied to only one of the 4 sites, and the
> other 3 blindly expanded from 14 to 18 characters?

Because the units of the others don't make sense.
The expansion is to make things still appear aligned when the thousands
are separated.

>



--
Stephane Eranian | EMEA Software Engineering
Google France | 38 avenue de l'OpÃra | 75002 Paris
Tel : +33 (0) 1 42 68 53 00
This email may be confidential or privileged. If you received this
communication by mistake, please
don't forward it to anyone else, please erase all copies and
attachments, and please let me know that
it went to the wrong person. Thanks
N‹§²æìr¸›yúèšØb²X¬¶ÇvØ^–)Þ{.nÇ+‰·¥Š{±‘êçzX§¶›¡Ü}©ž²ÆzÚ&j:+v‰¨¾«‘êçzZ+€Ê+zf£¢·hšˆ§~†­†Ûiÿûàz¹®w¥¢¸?™¨è­Ú&¢)ßf”ù^jÇy§m…á@A«a¶Úÿ 0¶ìh®å’i