Skip to content

Commit

Permalink
fixed missing profiler exitFunction calls, fixes #21
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexHaxe committed Jun 2, 2024
1 parent 97ee1c6 commit 821dbf7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- fixed @:implicitReturn handling
- fixed handling of empty blocks
- fixed ifs without else branch
- fixed missing profiler exitFunction calls, fixes [#21](https://github.com/AlexHaxe/haxe-instrument/issues/21)
- refactored call hierarchy data collection
- reduced number of blocks in blocks when instrumenting

Expand Down
23 changes: 11 additions & 12 deletions src/instrument/Instrumentation.hx
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ class Instrumentation {
static function coverBoolCondition(expr:Expr, branchesInfo:BranchesInfo):Expr {
switch (context.level) {
case None | Profiling:
var exprs:Array<Expr> = exprsFromBlock(expr);
var exprs:Array<Expr> = exprsFromBlock(instrumentExpr(expr));
return {expr: EBlock(exprs), pos: expr.pos};
case Coverage:
case Both:
Expand All @@ -832,8 +832,8 @@ class Instrumentation {
static function coverWhileCondition(cond:Expr, bodyExpr:Expr, normalWhile:Bool, branchesInfo:BranchesInfo):Expr {
switch (context.level) {
case None | Profiling:
cond = {expr: EBlock(exprsFromBlock(cond)), pos: cond.pos};
bodyExpr = {expr: EBlock(exprsFromBlock(bodyExpr)), pos: bodyExpr.pos};
cond = instrumentExpr(ensureBlockExpr(cond));
bodyExpr = instrumentExpr(ensureBlockExpr(bodyExpr));
return {expr: EWhile(cond, bodyExpr, normalWhile), pos: cond.pos};
case Coverage:
case Both:
Expand Down Expand Up @@ -874,12 +874,11 @@ class Instrumentation {
static function coverIfCondition(cond:Expr, ifExpr:Expr, elseExpr:Null<Expr>, branchesInfo:BranchesInfo):Expr {
switch (context.level) {
case None | Profiling:
cond = {expr: EBlock(exprsFromBlock(cond)), pos: cond.pos};
ifExpr = {expr: EBlock(exprsFromBlock(ifExpr)), pos: ifExpr.pos};
cond = {expr: EBlock(exprsFromBlock(instrumentExpr(cond))), pos: cond.pos};
ifExpr = {expr: EBlock(exprsFromBlock(instrumentExpr(ifExpr))), pos: ifExpr.pos};
if (elseExpr != null) {
elseExpr = {expr: EBlock(exprsFromBlock(elseExpr)), pos: elseExpr.pos};
elseExpr = {expr: EBlock(exprsFromBlock(instrumentExpr(elseExpr))), pos: elseExpr.pos};
}

return {expr: EIf(cond, ifExpr, elseExpr), pos: cond.pos};
case Coverage:
case Both:
Expand Down Expand Up @@ -931,9 +930,9 @@ class Instrumentation {
static function coverTernaryCondition(cond:Expr, ifExpr:Expr, elseExpr:Expr, branchesInfo:BranchesInfo):Expr {
switch (context.level) {
case None | Profiling:
cond = {expr: EBlock(exprsFromBlock(cond)), pos: cond.pos};
ifExpr = {expr: EBlock(exprsFromBlock(ifExpr)), pos: ifExpr.pos};
elseExpr = {expr: EBlock(exprsFromBlock(elseExpr)), pos: elseExpr.pos};
cond = {expr: EBlock(exprsFromBlock(instrumentExpr(cond))), pos: cond.pos};
ifExpr = {expr: EBlock(exprsFromBlock(instrumentExpr(ifExpr))), pos: ifExpr.pos};
elseExpr = {expr: EBlock(exprsFromBlock(instrumentExpr(elseExpr))), pos: elseExpr.pos};

return {expr: ETernary(cond, ifExpr, elseExpr), pos: cond.pos};
case Coverage:
Expand Down Expand Up @@ -990,8 +989,8 @@ class Instrumentation {
static function coverNullCoal(exprLeft:Expr, exprRight:Expr, branchesInfo:BranchesInfo):Expr {
switch (context.level) {
case None | Profiling:
exprLeft = {expr: EBlock(exprsFromBlock(exprLeft)), pos: exprLeft.pos};
exprRight = {expr: EBlock(exprsFromBlock(exprRight)), pos: exprRight.pos};
exprLeft = {expr: EBlock(exprsFromBlock(instrumentExpr(exprLeft))), pos: exprLeft.pos};
exprRight = {expr: EBlock(exprsFromBlock(instrumentExpr(exprRight))), pos: exprRight.pos};
return {expr: EBinop(OpNullCoal, exprLeft, exprRight), pos: exprLeft.pos};
case Coverage:
case Both:
Expand Down
4 changes: 4 additions & 0 deletions src/instrument/profiler/reporter/ConsoleHierarchyReporter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class ConsoleHierarchyReporter implements IProfilerReporter {
if (tree == null) {
return;
}
if (indent.length > 1000) {
output(indent + " …………tree truncated");
return;
}
if ((tree.functionName == null) || (tree.functionName.length <= 0)) {
output(indent + "+ " + tree.className + " " + (tree.duration * 1000) + "ms");
} else {
Expand Down

0 comments on commit 821dbf7

Please sign in to comment.