changeset 18777:be0978e94806

Add column with time percentage to profshow output. * profshow.m: Also output a column with percent of total time.
author Daniel Kraft <d@domob.eu>
date Fri, 07 Mar 2014 09:10:46 +0100
parents bd334b6af257
children b5b73959907f
files scripts/general/profshow.m
diffstat 1 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/general/profshow.m	Thu May 08 14:04:35 2014 -0700
+++ b/scripts/general/profshow.m	Fri Mar 07 09:10:46 2014 +0100
@@ -1,4 +1,4 @@
-## Copyright (C) 2012-2013 Daniel Kraft
+## Copyright (C) 2012-2014 Daniel Kraft
 ##
 ## This file is part of Octave.
 ##
@@ -54,6 +54,7 @@
   ## times to an array, then sort this, and use the resulting index permutation
   ## to print out our table.
   times = -[ data.FunctionTable.TotalTime ];
+  totalTime = -sum (times);
 
   [~, p] = sort (times);
 
@@ -64,19 +65,21 @@
   for i = 1 : n
     nameLen = max (nameLen, length (data.FunctionTable(p(i)).FunctionName));
   endfor
-  headerFormat = sprintf ("%%4s %%%ds %%4s %%12s %%12s\n", nameLen);
-  rowFormat = sprintf ("%%4d %%%ds %%4s %%12.3f %%12d\n", nameLen);
+  headerFormat = sprintf ("%%4s %%%ds %%4s %%12s %%10s %%12s\n", nameLen);
+  rowFormat = sprintf ("%%4d %%%ds %%4s %%12.3f %%10.2f %%12d\n", nameLen);
 
-  printf (headerFormat, "#", "Function", "Attr", "Time (s)", "Calls");
-  printf ("%s\n", repmat ("-", 1, nameLen + 2 * 5 + 2 * 13));
+  printf (headerFormat, ...
+          "#", "Function", "Attr", "Time (s)", "Time (%)", "Calls");
+  printf ("%s\n", repmat ("-", 1, nameLen + 2 * 5 + 11 + 2 * 13));
   for i = 1 : n
     row = data.FunctionTable(p(i));
+    timePercent = 100 * row.TotalTime / totalTime;
     attr = "";
     if (row.IsRecursive)
       attr = "R";
     endif
     printf (rowFormat, p(i), row.FunctionName, attr, ...
-            row.TotalTime, row.NumCalls);
+            row.TotalTime, timePercent, row.NumCalls);
   endfor
 
 endfunction