DMD trace file parser - prepare sorted lists of functions - #344

This commit is contained in:
Vadim Lopatin 2017-10-09 09:28:58 +03:00
parent f620e3e286
commit f36056d37e
1 changed files with 49 additions and 5 deletions

View File

@ -27,16 +27,45 @@ import dlangide.builders.extprocess;
import dlangui.widgets.appframe; import dlangui.widgets.appframe;
import core.thread; import core.thread;
enum TraceSortOrder {
BY_FUNCTION_TIME,
BY_TOTAL_TIME,
BY_CALL_COUNT,
BY_NAME,
}
void sortFunctionNodes(FunctionNode[] nodes, TraceSortOrder sortOrder) {
import std.algorithm.sorting : sort;
final switch(sortOrder) {
case TraceSortOrder.BY_FUNCTION_TIME:
sort!((a,b) => a.function_time < b.function_time)(nodes);
break;
case TraceSortOrder.BY_TOTAL_TIME:
sort!((a,b) => a.function_and_descendant_time < b.function_and_descendant_time)(nodes);
break;
case TraceSortOrder.BY_CALL_COUNT:
sort!((a,b) => a.number_of_calls < b.number_of_calls)(nodes);
break;
case TraceSortOrder.BY_NAME:
sort!((a,b) => a.name < b.name)(nodes);
break;
}
}
class DMDTraceLogParser { class DMDTraceLogParser {
string filename; private string filename;
string content; private string content;
string[] lines; private string[] lines;
bool _cancelRequested; private bool _cancelRequested;
FunctionNode[string] nodes; FunctionNode[string] nodes;
FunctionNode[] nodesByFunctionTime;
FunctionNode[] nodesByTotalTime;
FunctionNode[] nodesByCallCount;
FunctionNode[] nodesByName;
//FunctionEdge[string] caller_graph; //FunctionEdge[string] caller_graph;
//FunctionEdge[string] called_graph; //FunctionEdge[string] called_graph;
ulong ticks_per_second; private ulong ticks_per_second;
this(string fname) { this(string fname) {
filename = fname; filename = fname;
@ -158,8 +187,23 @@ class DMDTraceLogParser {
caller = false; caller = false;
} }
} }
makeSorted();
return true; return true;
} }
void makeSorted() {
nodesByFunctionTime.reserve(nodes.length);
foreach(key, value; nodes) {
nodesByFunctionTime ~= value;
}
nodesByTotalTime = nodesByFunctionTime.dup;
nodesByCallCount = nodesByFunctionTime.dup;
nodesByName = nodesByFunctionTime.dup;
sortFunctionNodes(nodesByFunctionTime, TraceSortOrder.BY_FUNCTION_TIME);
sortFunctionNodes(nodesByTotalTime, TraceSortOrder.BY_TOTAL_TIME);
sortFunctionNodes(nodesByCallCount, TraceSortOrder.BY_CALL_COUNT);
sortFunctionNodes(nodesByName, TraceSortOrder.BY_NAME);
}
} }
private __gshared static char[] demangleBuffer; private __gshared static char[] demangleBuffer;