All About Performance

and other stuff by Taras Glek

Recipe: How Many Classes Are Instantiated in Mozilla?

I got this question in the mail today.

Seems like a simple enough question, but grep won’t provide that answer :) It also happens to be an excellent usecase for Dehydra.

My script:

1
2
3
4
5
6

var classes = []
function process_type (c) {
if (!/class|struct/(c.kind)) return
classes.push (c.name)
}
1
2
3
4
5
6

function input_end() {
var f = this.aux_base_name + ".counter"
print(f)
write_file (f, classes.join ("\n"))
}

process_type is called every time GCC hits a class declaration or a template is instantiated(also for enums and unions, but those get ignored with the .kind check). Then input_end is called when GCC is done processing the file. this.aux_base_name is the input filename.

I hooked up this script to the mozilla build by adding the following to .mozconfig:

1
2
3

export CXX=$HOME/gcc/bin/g++
export CXXFLAGS="-fplugin=$HOME/work/gccplugin/gcc_dehydra.so -fplugin-arg=$HOME/work/gccplugin/test/count_classes.js"

Then I built:

1
2

make -f client.mk build WARNINGS_AS_ERRORS=

Count:

1
2
3

find -name \*.counter|xargs cat |sort |uniq > /tmp/classes.txt
wc /tmp/classes.txt

Answer: 15001

There are a million other trivial queries that could be accomplished in a similar manner that weren’t easy or possible before.

Update: Fixed typo, had an extra zero in the answer

Comments