Difference between revisions of "Other Dev Tools"

From D Wiki
Jump to: navigation, search
(Moved "Interactive D Compiler" to main page with other similar tools)
(Have valgrind helper replace double quotes in demangled names with two single quotes, because double quotes cause dot to fail and escaping them shows the backslash in kcachegrind.)
Line 5: Line 5:
 
dcallgrind.d
 
dcallgrind.d
 
<syntaxhighlight lang="D">
 
<syntaxhighlight lang="D">
 +
import std.array;
 
import std.stdio;
 
import std.stdio;
 
import std.demangle;
 
import std.demangle;
Line 18: Line 19:
 
     auto outFile = isStdin ? stdout : File(args[1] ~ ".demangled", "w");
 
     auto outFile = isStdin ? stdout : File(args[1] ~ ".demangled", "w");
 
     foreach (l; inFile.byLine(KeepTerminator.yes))
 
     foreach (l; inFile.byLine(KeepTerminator.yes))
         outFile.write(replace!(a => demangle(to!string(a.hit)))(l, re));
+
         outFile.write(replace!(a => demangle(to!string(a.hit)).replace("\"", "''"))(l, re));
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 25: Line 26:
  
 
This will create a file called '''callgrind.out.27497.demangled''' that you can then view using KCachegrind.
 
This will create a file called '''callgrind.out.27497.demangled''' that you can then view using KCachegrind.
 
  
 
== MiniLibD - Embedded D usage ==
 
== MiniLibD - Embedded D usage ==

Revision as of 14:15, 30 January 2016

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.array;
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)).replace("\"", "''"))(l, re));
}

Usage

./dcallgrind callgrind.out.27497

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

MiniLibD - Embedded D usage

This collection has libraries and tools to compile D language programs for embedded systems with the gdc compiler.

The original D runtime library uses libraries from the operating system. It can not be used in embedded systems when there is no operating system.

Get the source.