istanbuljs / nyc

the Istanbul command line interface
https://istanbul.js.org/
ISC License
5.55k stars 353 forks source link

How to get the lines sorted with the maximum execution count? #1502

Open glk-web opened 1 year ago

glk-web commented 1 year ago

I have the html report and it shows how many times each line of the code was executed. I also have .nyc_output/out.json

The code base has over 100 files. I want to find the most executed lines of the code base.

image

So in the above image I want to run something from the command line that will create a table like this:

Line location Execution count
Line 502 3434
Line 515 3434
... ....
Line 551 12

The most executed lines of the code base will allow me to do performance optimizations.

I am able to use grep on command line to get closer to the results I need:

> grep count coverage/clover.xml
<line num="12" count="10" type="stmt"/>
<line num="76" count="10" type="stmt"/>
<line num="4" count="10" type="stmt"/>
<line num="6" count="10" type="stmt"/>
<line num="11" count="9" type="stmt"/>
<line num="14" count="6404" type="stmt"/>
<line num="19" count="6401" type="stmt"/>
<line num="20" count="6401" type="stmt"/>
<line num="21" count="6401" type="stmt"/>
<line num="24" count="6388" type="stmt"/>

In 2nd step I cut and then sorted

> grep count cc-report-archives//ui-focus/2023-01-01/clover.xml | awk -F"\"" '{print $2","$4}'
12,10
76,10
4,10
6,10
11,9
14,6404
19,6401
20,6401
21,6401
24,6388

In the 3rd step I sort it on the 2nd field

> grep count cc-report-archives//ui-focus/2023-01-01/clover.xml | awk -F"\"" '{print $2","$4}' | sort -t, -nk2
835,6394
19,6401
20,6401
21,6401
14,6404
616,6475
904,6506
687,6605
810,6755
501,32992

I need to find the file the line number is referring to.

Is there a pre-existing tool that does this?

doublethefish commented 1 year ago

Have a look at .nyc_output/out.json.