From fa6f545558f0deb2f9b184baeb88073600f087a2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?=
 <grubba@grubba.org>
Date: Fri, 5 Nov 2021 10:48:52 +0100
Subject: [PATCH] EFUNs: describe_backtrace() now reports cpu time
 --with-profiling.

---
 lib/master.pike.in | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/lib/master.pike.in b/lib/master.pike.in
index 386f616e7b..6b5ce1e62e 100644
--- a/lib/master.pike.in
+++ b/lib/master.pike.in
@@ -4548,23 +4548,23 @@ string describe_backtrace(mixed trace, void|int linewidth)
 
     for(e = sizeof(trace)-1; e>=end; e--)
     {
-      mixed tmp;
+      mixed frame;
       string row;
       if (array err=[array]catch {
-	tmp = trace[e];
-	if(stringp(tmp))
+	frame = trace[e];
+	if(stringp(frame))
 	{
-	  row=[string]tmp;
+	  row = [string]frame;
 	}
-	else if(arrayp(tmp))
+	else if(arrayp(frame))
 	{
-	  if(sprintf("%t",tmp)=="object") {
+	  if(objectp(frame)) {
 	    // tmp is backtrace_frame
-	    desc->identify_parts( tmp->args );
+	    desc->identify_parts( frame->args );
 	  }
 	  else
-	    desc->identify_parts( tmp );
-	  array tmp = [array]tmp;
+	    desc->identify_parts( frame );
+	  array tmp = [array]frame;
 	  string pos;
 	  if(sizeof(tmp)>=2 && stringp(tmp[0])) {
 	    if (intp(tmp[1])) {
@@ -4589,6 +4589,11 @@ string describe_backtrace(mixed trace, void|int linewidth)
 	    pos=desc;
 	  }
 
+	  if (objectp(frame) && !undefinedp(frame->total_time)) {
+	    // Profiling.
+	    pos += sprintf(": %dns", frame->total_time);
+	  }
+
 	  string data;
 
 	  if(sizeof(tmp)>=3)
@@ -4619,9 +4624,9 @@ string describe_backtrace(mixed trace, void|int linewidth)
 	}
 	else
 	{
-	  if (tmp) {
-	    if (catch (row = sprintf("%O", tmp)))
-	      row = describe_program(object_program(tmp)) + " with broken _sprintf()";
+	  if (frame) {
+	    if (catch (row = sprintf("%O", frame)))
+	      row = describe_program(object_program(frame)) + " with broken _sprintf()";
 	  } else {
 	    row = "Destructed object";
 	  }
-- 
GitLab