Skip to content

Commit 92d98eb

Browse files
Also flag dup/idup uses
1 parent 26b6921 commit 92d98eb

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

dub.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "gchunt",
33
"description": "A tool to post-process D compiler's GC usage log",
4-
"copyright": "Copyright © 2014, Dmitry Olshansky",
4+
"copyright": "Copyright © 2014-2016, Dmitry Olshansky",
55
"authors": ["Dmitry Olshansky"],
66
"dependencies": {
7-
"libdparse": ">=0.1.1"
7+
"libdparse": ">=0.1.1"
88
},
9-
"targetType" : "executable",
10-
"mainSourceFile" : "source/gchunt.d",
11-
"targetName" : "gchunt"
9+
"targetType" : "executable",
10+
"mainSourceFile" : "source/gchunt.d",
11+
"targetName" : "gchunt"
1212
}

source/gchunt.d

+21-6
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ version(unittest) void main(){}
240240
else void main(string[] args){
241241
bool graphMode = false;
242242

243-
auto re = regex(`(.*[\\/]\w+)\.d\((\d+)\):\s*vgc:\s*(.*)`);
243+
auto re = regex(`(.*[\\/]\w+)\.d\((\d+),\d+\):\s*vgc:\s*(.*)`);
244244
auto opts = getopt(args, "graph", &graphMode);
245245
if(opts.helpWanted){
246246
defaultGetoptPrinter("gchunt - pinpoint GC usage in D apps", opts.options);
@@ -252,18 +252,33 @@ else void main(string[] args){
252252
results ~= Result(m[1].replace("\\", "/"), m[2], m[3]);
253253
}
254254
}
255-
sort!((a,b) => a.file < b.file || (a.file == b.file && a.line < b.line))
256-
(results);
257-
258-
results = uniq(results).array; // deduplicate
255+
auto deduplicate(Result[] arr){
256+
// deduplicate
257+
sort!((a,b) => a.file < b.file || (a.file == b.file && a.line < b.line))
258+
(arr);
259+
return uniq(arr).array;
260+
}
261+
results = deduplicate(results).dup;
259262
// Tokenize modules in question
260263
auto interned = StringCache(4096);
261264
foreach(mod;results.map!(x => x.file).uniq){
262265
auto config = LexerConfig(mod~".d", StringBehavior.compiler);
263266
auto data = cast(ubyte[])std.file.read(mod ~ ".d");
264267
tokenStreams[mod] = getTokensForParser(data, config, &interned).dup;
265-
//TODO: generate new "vgc" records for each .(i)dup
266268
}
269+
// generate new "vgc" records for each .(i)dup
270+
foreach(mod, toks; tokenStreams){
271+
for(auto r = toks;!r.empty;){
272+
r = r.findAdjacent!((a,b) => a.type == tok!"."
273+
&& b.type == tok!"identifier" && (b.text == "dup" || b.text == "idup"));
274+
if(!r.empty){
275+
results ~= Result(mod, to!string(r[0].line), "(i)dup allocates on GC heap");
276+
r.popFront();
277+
}
278+
}
279+
280+
}
281+
results = deduplicate(results);
267282
try{
268283
auto f = File("blacklist.gchunt");
269284
stderr.writeln("Found blacklist.gchunt ...");

0 commit comments

Comments
 (0)