Monday 2 February 2009

Borg call graph

I would just like to publicly thank darke who has made an excessive number of bug fixes on the SVN version of Unangband in the last few weeks - including picking up some golden oldie bugs.

This is yet another example of why making your source code easily available is a great idea.

A number of these bugs were identified by using the so-called dumb borg, an automated Angband player developed by Leon Marrick. The dumb borg is different from other Angband borg implementations because it cheats, and in the Unangband version, is prone to jump rapidly from level to level.

Darke's just sent me a call graph for a 1000 turns of borg, which I'd like to share with you. The borg is heavily biased towards spending time in dungeon generation, but it's still interesting to see which code is the most heavily used. (Click on the picture for a higher resolution version).

Many of the remaining bugs were identified by darke porting the Angband source code to C++ (by renaming every .c file to .cpp and recompiling). C++ picks up a lot more warnings than the venerable gcc compiler I've been using - and most of the warnings have identified logic and syntactic errors in the code that he's gone on to fix.


Jotaf said...

How do you generate a spiffy call graph like that? My "call graph generation" currently consists of a macro at the top of each function, declaring an auxiliary object that signals function entry upon construction, and function exit upon destruction. It's kinda ok, but it generates an immense tree on the console that is kinda hard to read.

wlievens said...

This appears to be using Valgrind.

Darke said...

Correct. Just using the "callgrind" tool in valgrind, rather then the "memcheck" one people usually associated with it. :)

The KCacheGrind UI ( is what ends up making it look pretty.

There is more detail available then in that particular graph, I just cut it down a little to minimise the noise. For example anything using less then 1% of runtime of the "main" function is cut off, and I also believe it only shows the most heavily weighted path between functions. It makes for a very pretty diagram to include everything, but it doesn't really make it easy to understand. :)

Andi said...

Here are the warning flags I use for V:

WARNINGS = -W -Wall -Wextra -Wno-unused-parameter -Wold-style-definition -Wdeclaration-after-statement -Wmissing-declarations -Wredundant-decls -Wpointer-arith -Wcast-align -Wwrite-strings -Winline -Wformat-security -Winit-self -Wmissing-include-dirs -Wundef -Wmissing-format-attribute -Wnested-externs -Wunreachable-code

I don't know what makefile you use, but you may find it helpful to keep those around (though your taste may differ and you might want to keep some of them off).

Jotaf said...

Thanks, I'll check it out! ;)

Jotaf said...

Meh, I forgot, Valgrind is for Linux. I'm stuck with VS so no deal. =|

Darke said...

takkaria: Thanks, I'll go through and check what I've current got in my local copy and see if there's any useful ones I'm missing.

jotaf: If you grab a copy of the free vmware player, you can get download a pre-installed ubuntu (or whatever) vmware image, then just install valgrind and you're good to go. Assuming your variant/whatever will compile under linux of course.