"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tools/timetrace2txt.d" between
ldc-1.32.1.tar.gz and ldc-1.32.2.tar.gz

About: LDC is a LLVM-based D compiler.

timetrace2txt.d  (ldc-1.32.1):timetrace2txt.d  (ldc-1.32.2)
skipping to change at line 26 skipping to change at line 26
import std.file; import std.file;
import std.json; import std.json;
import std.range; import std.range;
import std.conv; import std.conv;
import std.algorithm; import std.algorithm;
struct Config { struct Config {
string input_filename; string input_filename;
string output_filename = "timetrace.txt"; string output_filename = "timetrace.txt";
string output_TSV_filename; string output_TSV_filename;
bool indented = false;
} }
Config config; Config config;
File outputTextFile; File outputTextFile;
static string duration_format_string = "%13.3f "; static string duration_format_string = "%13.3f ";
JSONValue sourceFile; JSONValue sourceFile;
JSONValue[] metadata; // "M" JSONValue[] metadata; // "M"
JSONValue[] counterdata; // "C" JSONValue[] counterdata; // "C"
JSONValue[] processes; // "X" JSONValue[] processes; // "X"
ulong lineNumberCounter = 1; ulong lineNumberCounter = 1;
void parseCommandLine(string[] args) { void parseCommandLine(string[] args) {
import std.getopt : arraySep, getopt, defaultGetoptPrinter; import std.getopt : arraySep, getopt, defaultGetoptPrinter;
try { try {
arraySep = ";"; arraySep = ";";
auto helpInformation = getopt( auto helpInformation = getopt(
args, args,
"o", "Output filename (default: '" ~ config.output_filename.init ~ "indent", "Output items as simply indented list instead of the fancy
"'). Specify '-' to redirect output to stdout.", &config.output_filename, tree. This should go well with code-folding editors.", &config.indented,
"o", "Output filename (default: '" ~ config.output_filename ~ "').
Specify '-' to redirect output to stdout.", &config.output_filename,
"tsv", "Also output to this file in duration-sorted Tab-Separated Va lues (TSV) format", &config.output_TSV_filename, "tsv", "Also output to this file in duration-sorted Tab-Separated Va lues (TSV) format", &config.output_TSV_filename,
); );
if (args.length != 2) { if (args.length != 2) {
helpInformation.helpWanted = true; helpInformation.helpWanted = true;
writeln("No input file given!\n"); writeln("No input file given!\n");
} else { } else {
config.input_filename = args[1]; config.input_filename = args[1];
if (!exists(config.input_filename) || !isFile(config.input_filename) ) { if (!exists(config.input_filename) || !isFile(config.input_filename) ) {
writefln("Input file '%s' does not exist or is not a file.\n", c onfig.input_filename); writefln("Input file '%s' does not exist or is not a file.\n", c onfig.input_filename);
skipping to change at line 109 skipping to change at line 111
outputTextFile.write(" "); outputTextFile.write(" ");
outputTextFile.writeln(node); outputTextFile.writeln(node);
lineNumberCounter++; lineNumberCounter++;
} }
outputTextFile.writeln("Duration (ms)"); outputTextFile.writeln("Duration (ms)");
lineNumberCounter++; lineNumberCounter++;
} }
wchar[] indentstring; wchar[] indentstring;
foreach (i, ref child; Node.root.children) foreach (i, ref child; Node.root.children) {
child.print(indentstring, false); if (config.indented)
child.printIndented(indentstring);
else
child.printTree(indentstring);
}
if (config.output_TSV_filename.length != 0) { if (config.output_TSV_filename.length != 0) {
File outputTSVFile = (config.output_TSV_filename == "-") ? stdout : File (config.output_TSV_filename, "w"); File outputTSVFile = (config.output_TSV_filename == "-") ? stdout : File (config.output_TSV_filename, "w");
outputTSVFile.writeln("Duration\tText Line Number\tName\tLocation\tDetai l"); outputTSVFile.writeln("Duration\tText Line Number\tName\tLocation\tDetai l");
foreach (node; Node.all) foreach (node; Node.all)
outputTSVFile.writeln(node.duration, "\t", node.lineNumber, "\t", outputTSVFile.writeln(node.duration, "\t", node.lineNumber, "\t",
node.name, "\t", node.location, "\t", node.detail); node.name, "\t", node.location, "\t", node.detail);
} }
return 0; return 0;
skipping to change at line 227 skipping to change at line 233
this(JSONValue* json, long last_ts, bool root = false) this(JSONValue* json, long last_ts, bool root = false)
{ {
this.json = json; this.json = json;
this.last_ts = last_ts; this.last_ts = last_ts;
if (!root) if (!root)
{ {
this.duration = (*json)["dur"].integer; this.duration = (*json)["dur"].integer;
this.name = (*json)["name"].str; this.name = (*json)["name"].str;
this.location = (*json)["args"]["loc"].str; if (auto args = "args" in *json) {
this.detail = (*json)["args"]["detail"].str; if (auto value = "loc" in *args) {
this.location = value.str;
}
if (auto value = "detail" in *args) {
this.detail = value.str;
}
}
} }
} }
void print(wchar[] indentstring, bool last_child) { void printTree(wchar[] indentstring, bool last_child = false) {
this.lineNumber = lineNumberCounter; this.lineNumber = lineNumberCounter;
lineNumberCounter++; lineNumberCounter++;
// Output in milliseconds. // Output in milliseconds.
outputTextFile.writef(duration_format_string, cast(double)(this.duration ) / 1000); outputTextFile.writef(duration_format_string, cast(double)(this.duration ) / 1000);
if (last_child) if (last_child)
indentstring[$-1] = '└'; indentstring[$-1] = '└';
outputTextFile.write(indentstring); outputTextFile.write(indentstring);
outputTextFile.write("- ", this.name); outputTextFile.write("- ", this.name);
outputTextFile.write(", ", this.detail); outputTextFile.write(", ", this.detail);
outputTextFile.writeln(", ", this.location); outputTextFile.writeln(", ", this.location);
if (last_child) if (last_child)
indentstring[$-1] = ' '; indentstring[$-1] = ' ';
wchar[] child_indentstring = indentstring ~ " |"; wchar[] child_indentstring = indentstring ~ " |";
foreach (i, ref child; this.children) { foreach (i, ref child; this.children) {
child.print(child_indentstring, i == this.children.length-1); child.printTree(child_indentstring, i == this.children.length-1);
}
}
void printIndented(wchar[] indentstring) {
this.lineNumber = lineNumberCounter;
lineNumberCounter++;
// Output in milliseconds.
outputTextFile.write(indentstring);
outputTextFile.write("- ");
outputTextFile.writef(duration_format_string, cast(double)(this.duration
) / 1000);
outputTextFile.write("- ", this.name);
outputTextFile.write(", ", this.detail);
outputTextFile.writeln(", ", this.location);
wchar[] child_indentstring = indentstring ~ " ";
foreach (i, ref child; this.children) {
child.printIndented(child_indentstring);
} }
} }
} }
 End of changes. 6 change blocks. 
8 lines changed or deleted 40 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)