profileKiss print macro, special form, and other statistics
This commit is contained in:
@@ -322,7 +322,7 @@ class Kiss {
|
|||||||
}
|
}
|
||||||
//trace('kiss build $kissFile');
|
//trace('kiss build $kissFile');
|
||||||
|
|
||||||
return _try(() -> {
|
var result = _try(() -> {
|
||||||
#if profileKiss
|
#if profileKiss
|
||||||
Kiss.measure('Compiling kiss: $kissFile', () -> {
|
Kiss.measure('Compiling kiss: $kissFile', () -> {
|
||||||
#end
|
#end
|
||||||
@@ -357,12 +357,22 @@ class Kiss {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
k.fieldList;
|
|
||||||
#if profileKiss
|
#if profileKiss
|
||||||
});
|
});
|
||||||
#end
|
for (label => timeSpent in profileAggregates) {
|
||||||
});
|
var usageCount = profileUsageCounts[label];
|
||||||
|
if (timeSpent >= SIGNIFICANT_TIME_SPENT) {
|
||||||
|
Sys.println('${label} (x${usageCount}): ${timeSpent}');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#end
|
||||||
|
k.fieldList;
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static final SIGNIFICANT_TIME_SPENT = 0.05;
|
||||||
|
|
||||||
public static function load(kissFile:String, k:KissState, ?loadingDirectory:String, loadAllExps = false, ?fromExp:ReaderExp):Null<ReaderExp> {
|
public static function load(kissFile:String, k:KissState, ?loadingDirectory:String, loadAllExps = false, ?fromExp:ReaderExp):Null<ReaderExp> {
|
||||||
if (loadingDirectory == null)
|
if (loadingDirectory == null)
|
||||||
@@ -556,7 +566,7 @@ class Kiss {
|
|||||||
checkNumArgs(mac);
|
checkNumArgs(mac);
|
||||||
macroUsed = true;
|
macroUsed = true;
|
||||||
var expanded = try {
|
var expanded = try {
|
||||||
macros[mac](exp, args.copy(), k);
|
Kiss.measure(mac, ()->macros[mac](exp, args.copy(), k), true);
|
||||||
} catch (error:KissError) {
|
} catch (error:KissError) {
|
||||||
throw error;
|
throw error;
|
||||||
} catch (error:Dynamic) {
|
} catch (error:Dynamic) {
|
||||||
@@ -572,7 +582,7 @@ class Kiss {
|
|||||||
};
|
};
|
||||||
case CallExp({pos: _, def: Symbol(specialForm)}, args) if (specialForms.exists(specialForm) && !macroExpandOnly):
|
case CallExp({pos: _, def: Symbol(specialForm)}, args) if (specialForms.exists(specialForm) && !macroExpandOnly):
|
||||||
checkNumArgs(specialForm);
|
checkNumArgs(specialForm);
|
||||||
Right(specialForms[specialForm](exp, args.copy(), k));
|
Right(Kiss.measure(specialForm, ()->specialForms[specialForm](exp, args.copy(), k), true));
|
||||||
case CallExp({pos: _, def: Symbol(alias)}, args) if (k.callAliases.exists(alias)):
|
case CallExp({pos: _, def: Symbol(alias)}, args) if (k.callAliases.exists(alias)):
|
||||||
convert(CallExp(k.callAliases[alias].withPosOf(exp), args).withPosOf(exp));
|
convert(CallExp(k.callAliases[alias].withPosOf(exp), args).withPosOf(exp));
|
||||||
case CallExp(func, args):
|
case CallExp(func, args):
|
||||||
@@ -771,12 +781,27 @@ class Kiss {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function measure<T>(processLabel:String, process:Void->T) {
|
static var profileAggregates:Map<String,Float> = [];
|
||||||
|
static var profileUsageCounts:Map<String,Int> = [];
|
||||||
|
|
||||||
|
public static function measure<T>(processLabel:String, process:Void->T, aggregate=false) {
|
||||||
var start = Sys.time();
|
var start = Sys.time();
|
||||||
|
if (aggregate) {
|
||||||
|
if (!profileAggregates.exists(processLabel)) {
|
||||||
|
profileAggregates[processLabel] = 0.0;
|
||||||
|
profileUsageCounts[processLabel] = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
Sys.print('${processLabel}... ');
|
Sys.print('${processLabel}... ');
|
||||||
|
}
|
||||||
var result = process();
|
var result = process();
|
||||||
var end = Sys.time();
|
var end = Sys.time();
|
||||||
|
if (aggregate) {
|
||||||
|
profileAggregates[processLabel] += (end - start);
|
||||||
|
profileUsageCounts[processLabel] += 1;
|
||||||
|
} else {
|
||||||
Sys.println('${end-start}s');
|
Sys.println('${end-start}s');
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -584,6 +584,9 @@ class Prelude {
|
|||||||
* So don't use raw string literals in Kiss you want parsed and evaluated at runtime.
|
* So don't use raw string literals in Kiss you want parsed and evaluated at runtime.
|
||||||
*/
|
*/
|
||||||
public static function convertToHScript(kissStr:String):String {
|
public static function convertToHScript(kissStr:String):String {
|
||||||
|
#if macro
|
||||||
|
return Kiss.measure("Prelude.convertToHScript", () -> {
|
||||||
|
#end
|
||||||
#if (!macro && hxnodejs)
|
#if (!macro && hxnodejs)
|
||||||
var hscript = try {
|
var hscript = try {
|
||||||
assertProcess("haxelib", ["run", "kiss", "convert", "--all", "--hscript"], kissStr.split('\n'));
|
assertProcess("haxelib", ["run", "kiss", "convert", "--all", "--hscript"], kissStr.split('\n'));
|
||||||
@@ -623,6 +626,9 @@ class Prelude {
|
|||||||
#else
|
#else
|
||||||
throw "Can't convert Kiss to HScript on this target.";
|
throw "Can't convert Kiss to HScript on this target.";
|
||||||
#end
|
#end
|
||||||
|
#if macro
|
||||||
|
}, true);
|
||||||
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (sys || hxnodejs)
|
#if (sys || hxnodejs)
|
||||||
|
@@ -139,6 +139,9 @@ class Stream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function putBackString(s:String) {
|
public function putBackString(s:String) {
|
||||||
|
#if macro
|
||||||
|
Kiss.measure("Stream.putBackString", () -> {
|
||||||
|
#end
|
||||||
var idx = s.length - 1;
|
var idx = s.length - 1;
|
||||||
while (idx >= 0) {
|
while (idx >= 0) {
|
||||||
absoluteChar -= 1;
|
absoluteChar -= 1;
|
||||||
@@ -152,6 +155,9 @@ class Stream {
|
|||||||
--idx;
|
--idx;
|
||||||
}
|
}
|
||||||
content = s + content;
|
content = s + content;
|
||||||
|
#if macro
|
||||||
|
}, true);
|
||||||
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
public function takeChars(count:Int):Option<String> {
|
public function takeChars(count:Int):Option<String> {
|
||||||
|
Reference in New Issue
Block a user