Skip to content

Conversation

xiaoyun94
Copy link
Contributor

@xiaoyun94 xiaoyun94 commented Aug 29, 2020

It will display as format

int getX(int x) 1x [100.0%]
if ( x > 0) { 1x
    return 1; 1x
}
return 0; 1x

Signed-off-by: FANG.Ge [email protected]

Copy link
Owner

@JacquesLucke JacquesLucke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch. I added a couple of comments inline.

decorations.calledLineDecorations.push(createCalledLineDecoration(range, totalCalls, lineDataArray));
/* First line of function will be appended with coverage rate. */
const isFuncStart = isFirstLineOfFunction(funcsDataOfFile, funcName, lineNumber);
const coverageRate = isFuncStart ? Number(funcCoverages.get(funcName)) : NaN;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer using undefined instead of NaN here. NaN should really be avoided in general.

function createCalledLineDecoration(range: vscode.Range, totalCalls: number, lineDataArray: GcovLineData[], coverageRate: number) {
const lineDataByFunction = groupData(lineDataArray, x => x.function_name);
let tooltip = createTooltipForCalledLine(lineDataByFunction);
let displayText = isNaN(coverageRate) ? ` ${totalCalls.toLocaleString()}x` :
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const (the tooltip as well actually), but that can be changed separately

}

function createCalledLineDecoration(range: vscode.Range, totalCalls: number, lineDataArray: GcovLineData[]) {
function createCalledLineDecoration(range: vscode.Range, totalCalls: number, lineDataArray: GcovLineData[], coverageRate: number) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

functionCoverageRate


function createDecorationsForFile(linesDataOfFile: GcovLineData[]): LineDecorationsGroup {
const decorations = new LineDecorationsGroup();
function calculateCoverageRate(linesDataOfFile: GcovLineData[]): Map<string, number> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calculateFunctionCoverageRate

totalLineNum++;
calledLineNum += (lineData.count > 0 ? 1 : 0);
}
funcCoverages.set(funcName, 100 * calledLineNum / totalLineNum);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep values between 0 and 1 in general, only multiply with 100 right before drawing.

}

function isFirstLineOfFunction(funcsDataOfFile: GcovFunctionData[], funcName: string, lineNumber: number): boolean {
const funcData = funcsDataOfFile.find(x => x.name == funcName);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has quadratic runtime complexity afaik, because you are iterating over all function names for every line. This can be quite bad in large files (as the ones I'm working with quite often). Better create a map from function name to line number and do lookups in this map.

@GitMensch
Copy link

@xiaoyun94 Is there any chance for you to work on the requested changes?

@GitMensch
Copy link

@JacquesLucke Isn't that feature included in version 0.5.0 (the one still missing on open-vsx ;-) ? In this case the issue could be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants