Difference between revisions of "Other Dev Tools"

From D Wiki
Jump to: navigation, search
(Created page with "== Valgrind helper == The Valgrind plugin Callgrind can be used to profile D code, but it does not know how to handle D's mangled names. This program can be used to clean up t...")
 
Line 1: Line 1:
 
== Valgrind helper ==
 
== Valgrind helper ==
The Valgrind plugin Callgrind can be used to profile D code, but it does not know how to handle D's mangled names. This program can be used to clean up the callgrind.out.nnnnn file so that tools like KCachegrind can display them more legibly.
+
The Valgrind plugin Callgrind can be used to profile D code, but it does not know how to handle D's mangled names. This program can be used to clean up the callgrind.out.nnnnn file so that tools like [http://kcachegrind.sourceforge.net/html/Home.html KCachegrind] can display them more legibly.
  
 
===Code===
 
===Code===
Line 14: Line 14:
 
void main(string[] args)
 
void main(string[] args)
 
{
 
{
     auto f = args.length > 1 ? File(args[1]) : stdin;
+
     auto isStdin = args.length == 1;
     foreach (l; f.byLine(KeepTerminator.yes))
+
    auto inFile = isStdin ? stdin : File(args[1]);
         write(replace!(a => demangle(to!string(a.hit)))(l, re));
+
    auto outFile = isStdin ? stdout : File(args[1] ~ ".demangled", "w");
 +
     foreach (l; inFile.byLine(KeepTerminator.yes))
 +
         outFile.write(replace!(a => demangle(to!string(a.hit)))(l, re));
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 
===Usage===
 
===Usage===
./dcallgrind callgrind.out.27497 > callgrind.out.27497.cleaned
+
'''./dcallgrind callgrind.out.27497'''
 +
 
 +
This will create a file called '''callgrind.out.27497.demangled''' that you can then view using KCachegrind.

Revision as of 10:07, 30 January 2013

Valgrind helper

The Valgrind plugin Callgrind can be used to profile D code, but it does not know how to handle D's mangled names. This program can be used to clean up the callgrind.out.nnnnn file so that tools like KCachegrind can display them more legibly.

Code

dcallgrind.d

import std.stdio;
import std.demangle;
import std.regex;
import std.conv;

auto re = ctRegex!(`(_D\d[\w_]+)`);

void main(string[] args)
{
    auto isStdin = args.length == 1;
    auto inFile = isStdin ? stdin : File(args[1]);
    auto outFile = isStdin ? stdout : File(args[1] ~ ".demangled", "w");
    foreach (l; inFile.byLine(KeepTerminator.yes))
        outFile.write(replace!(a => demangle(to!string(a.hit)))(l, re));
}

Usage

./dcallgrind callgrind.out.27497

This will create a file called callgrind.out.27497.demangled that you can then view using KCachegrind.