From 5b6c5ea50d3d2720863f9024c3ab5559ed93701f Mon Sep 17 00:00:00 2001 From: nifi Date: Mon, 5 Nov 2007 09:35:29 +0000 Subject: [PATCH] changed to not count active calls after clear profile + only show functions called at least once in printProfile git-svn-id: https://mspsim.svn.sourceforge.net/svnroot/mspsim/mspsim@24 23d1a52b-0c3c-0410-b72d-8f29ab48fe35 --- se/sics/mspsim/core/MSP430.java | 59 ++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/se/sics/mspsim/core/MSP430.java b/se/sics/mspsim/core/MSP430.java index f65d317..00f37c0 100644 --- a/se/sics/mspsim/core/MSP430.java +++ b/se/sics/mspsim/core/MSP430.java @@ -140,6 +140,7 @@ public class MSP430 extends MSP430Core { function = "fkn at $" + Utils.hex16(reg[PC]); } callStack[cSP].function = function; + callStack[cSP].calls = 0; callStack[cSP++].cycles = cycles; } @@ -148,21 +149,31 @@ public class MSP430 extends MSP430Core { // System.out.println("Profiler: return / call stack: " + cSP + ", " + fkn); long elapsed = cycles - callStack[cSP].cycles; - CallEntry ce = profileData.get(fkn); - if (ce == null) { - profileData.put(fkn, ce = new CallEntry()); - ce.function = fkn; + if (callStack[cSP].calls >= 0) { + CallEntry ce = profileData.get(fkn); + if (ce == null) { + profileData.put(fkn, ce = new CallEntry()); + ce.function = fkn; + } + ce.cycles += elapsed; + ce.calls++; } - ce.cycles += elapsed; - ce.calls++; } public void clearProfile() { - CallEntry[] entries = - profileData.values().toArray(new CallEntry[0]); - for (int i = 0, n = entries.length; i < n; i++) { - entries[i].cycles = 0; - entries[i].calls = 0; + if (profileData != null) { + CallEntry[] entries = + profileData.values().toArray(new CallEntry[0]); + for (int i = 0, n = entries.length; i < n; i++) { + entries[i].cycles = 0; + entries[i].calls = 0; + } + for (int i = 0, n = callStack.length; i < n; i++) { + CallEntry e = callStack[i]; + if (e != null) { + e.calls = -1; + } + } } } @@ -171,19 +182,21 @@ public class MSP430 extends MSP430Core { profileData.values().toArray(new CallEntry[0]); Arrays.sort(entries); for (int i = 0, n = entries.length; i < n; i++) { - String cyclesS = "" + entries[i].cycles; int c = entries[i].calls; - String callS = "" + c; - String avgS = "" + (c > 0 ? (entries[i].cycles / c) : 0); - System.out.print(entries[i].function); - printSpace(56 - entries[i].function.length() - avgS.length()); - System.out.print(avgS); - System.out.print(' '); - printSpace(8 - callS.length()); - System.out.print(callS); - System.out.print(' '); - printSpace(10 - cyclesS.length()); - System.out.println(cyclesS); + if (c > 0) { + String cyclesS = "" + entries[i].cycles; + String callS = "" + c; + String avgS = "" + (c > 0 ? (entries[i].cycles / c) : 0); + System.out.print(entries[i].function); + printSpace(56 - entries[i].function.length() - avgS.length()); + System.out.print(avgS); + System.out.print(' '); + printSpace(8 - callS.length()); + System.out.print(callS); + System.out.print(' '); + printSpace(10 - cyclesS.length()); + System.out.println(cyclesS); + } } }