Skip to content

Commit fac3361

Browse files
committed
[Statistic] Show analysis statistic on request.
1 parent 7d3dda2 commit fac3361

File tree

5 files changed

+64
-25
lines changed

5 files changed

+64
-25
lines changed

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@
109109
"title": "TSAR Close session",
110110
"icon": "icons/close.svg"
111111
},
112+
{
113+
"command": "tsar.statistic",
114+
"title": "Show project statistic",
115+
"icon": "icons/analyze.svg"
116+
},
112117
{
113118
"command": "tsar.analysis.check",
114119
"title": "TSAR Check User-defined Properties"
@@ -211,6 +216,11 @@
211216
"when": "view == tsar.loopTree && viewItem == project",
212217
"group": "inline"
213218
},
219+
{
220+
"command": "tsar.statistic",
221+
"when": "view == tsar.loopTree && viewItem == project",
222+
"group": "inline"
223+
},
214224
{
215225
"command": "tsar.func.analyze",
216226
"when": "view == tsar.loopTree && viewItem == function",

src/calleeFunc.ts

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ export class CalleeFuncProvider extends ProjectWebviewProvider {
205205
let nodes = '';
206206
let edges = '';
207207
let edgeNumber = 0; // use to set id of a new edge
208+
let numberOfCallees = 0, numberOfCalls = 0;
208209
let stmtNodes = []; // nodes for statements like goto, break, etc.
209210
info.CallGraph.forEach((callees, caller) => {
210211
let callerID = `${caller.ID}`;
@@ -217,6 +218,7 @@ export class CalleeFuncProvider extends ProjectWebviewProvider {
217218
}
218219
nodes += ',color: "darkorange"';
219220
} else {
221+
++numberOfCallees;
220222
let f = caller as msg.Function;
221223
nodes += `{id: '${callerID}', label: '${f.Name}'`;
222224
if (!f.User)
@@ -238,26 +240,31 @@ export class CalleeFuncProvider extends ProjectWebviewProvider {
238240
}
239241
edges += `{id: ${edgeNumber}, from: '${callerID}', to: '${calleeID}'`;
240242
// Add property to Go To a corresponding statement in a source code from webview.
241-
if (callee.StartLocation.length > 0 &&
242-
(!isFunction(caller) || caller.User)) {
243-
edges += `,location: [`;
244-
for (let loc of callee.StartLocation) {
245-
let resolvedLoc = resolveLocation(project, loc);
246-
let goto = encodeURI('command:tsar.open-project?' +
247-
JSON.stringify(project.uri.with({
248-
query: JSON.stringify(resolvedLoc)
249-
})));
250-
edges += `
251-
{
252-
Goto: '${goto}',
253-
Filename: '${path.basename(resolvedLoc.Path)}',
254-
Line: ${loc.Line},
255-
Column: ${loc.Column}
256-
},`;
257-
}
258-
// Remove last comma.
259-
edges = edges.substr(0, edges.length - 1);
260-
edges += ']';
243+
if (!isFunction(caller) || caller.User) {
244+
if (callee.StartLocation.length > 0) {
245+
edges += `,location: [`;
246+
for (let loc of callee.StartLocation) {
247+
if (numberOfCalls >= 0)
248+
++numberOfCalls;
249+
let resolvedLoc = resolveLocation(project, loc);
250+
let goto = encodeURI('command:tsar.open-project?' +
251+
JSON.stringify(project.uri.with({
252+
query: JSON.stringify(resolvedLoc)
253+
})));
254+
edges += `
255+
{
256+
Goto: '${goto}',
257+
Filename: '${path.basename(resolvedLoc.Path)}',
258+
Line: ${loc.Line},
259+
Column: ${loc.Column}
260+
},`;
261+
}
262+
// Remove last comma.
263+
edges = edges.substr(0, edges.length - 1);
264+
edges += ']';
265+
} else {
266+
numberOfCalls = -1;
267+
}
261268
}
262269
edges += '},';
263270
}
@@ -294,6 +301,9 @@ export class CalleeFuncProvider extends ProjectWebviewProvider {
294301
<div class="container-fluid pt-4" style="height:100%">
295302
<h3>${this._title().replace('{0}', gotoTarget)}</h3>
296303
<h5>${subtitle}</h5>
304+
<p>A total number of callees is ${numberOfCallees}.</p>
305+
<p>A total number of calls from user-defined functions is
306+
${numberOfCalls < 0 ? 'unknown' : numberOfCalls}.</p>
297307
<div class="row" style="height:100%">
298308
<div class="col-9" style="height:100%">
299309
<div id="callGraph" style="height:90%"}></div>

src/extension.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import * as lt from './loopTree';
1616
import * as at from './aliasTree';
1717
import * as msg from './messages';
1818
import {onReject} from './functions';
19-
import {ProjectEngine } from './project';
19+
import {ProjectEngine, Project } from './project';
2020
import {ProjectProvider} from './general';
2121
import {CalleeFuncProvider, CalleeFuncProviderState} from './calleeFunc';
2222
import * as t from './transformProvider';
@@ -141,6 +141,18 @@ export function activate(context: vscode.ExtensionContext) {
141141
],engine, context.subscriptions);
142142
let stop = vscode.commands.registerCommand(
143143
'tsar.stop', (uri:vscode.Uri) => engine.stop(uri));
144+
let statistic = vscode.commands.registerCommand(
145+
'tsar.statistic', (data: vscode.Uri|Project) => {
146+
let project = (data as Project).prjname !== undefined
147+
? data as Project
148+
: engine.project(data as vscode.Uri);
149+
let state = project.providerState(ProjectProvider.scheme);
150+
let request = new msg.Statistic;
151+
state.active = true;
152+
project.focus = state;
153+
project.send(request);
154+
}
155+
);
144156
let openProject = vscode.commands.registerCommand('tsar.open-project',
145157
(uri: vscode.Uri) => {
146158
let [docUri, query] = [uri, undefined];
@@ -186,5 +198,5 @@ export function activate(context: vscode.ExtensionContext) {
186198
project.focus = state;
187199
project.send(request);
188200
});
189-
context.subscriptions.push(start, stop, openProject, showCalleeFunc);
201+
context.subscriptions.push(start, stop, statistic, openProject, showCalleeFunc);
190202
}

src/general.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,23 @@ export class ProjectProvider extends ProjectWebviewProvider {
5454
<h3> ${this._title().replace('{0}', projectLink(project))} </h3>
5555
${this._listOfFiles(stat.Files)}
5656
<p>
57-
Analyzed files comprise ${numberHtml(stat.Functions)}
57+
Analyzed files comprise
58+
${numberHtml(stat.UserFunctions)}
5859
${commandLink(
5960
{
6061
command: 'tsar.function.list',
6162
project,
6263
title: log.FunctionList.title.replace('{0}',path.basename(project.prjname)),
63-
body: stat.Functions !== 1 ? 'functions' : 'function',
64+
body: stat.Functions !== 1 ? 'user functions' : 'user function',
6465
query: ''
6566
}
6667
)}
68+
(${numberHtml(stat.Functions)} ${stat.Functions !== 1 ? 'functions' : 'function'} in total)
6769
with
6870
${numberHtml(varCount)} ${varCount !== 1 ? 'variables' : 'variable'}${htmlVarNotAnalyzed}
6971
and
70-
${numberHtml(loopCount)} ${loopCount !== 1 ? 'loops' : 'loop'}${htmlLpNotAnalyzed}.
72+
${numberHtml(loopCount)} ${loopCount !== 1 ? 'loops' : 'loop'}${htmlLpNotAnalyzed}
73+
including ${numberHtml(stat.ParallelLoops)} ${stat.ParallelLoops !== 1 ? 'loops' : 'loop'} without parallelization issues.
7174
</p>
7275
${this._listOfTraits(stat)}
7376
<p>

src/messages.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ export interface TraitStatistic {
171171
export class Statistic {
172172
Files: {string:number};
173173
Functions: number;
174+
UserFunctions: number;
175+
ParallelLoops: number;
174176
Loops: [number, number];
175177
Variables: [number, number];
176178
Traits: TraitStatistic;
@@ -477,6 +479,8 @@ export interface DiagnosticJSON extends MessageJSON {
477479
*/
478480
export interface StatisticJSON extends MessageJSON {
479481
Functions: number;
482+
UserFunctions: number;
483+
ParallelLoops: number;
480484
Loops: {string:number};
481485
Variables: {string: number};
482486
Traits: TraitStatistic;

0 commit comments

Comments
 (0)