[MLton-commit] r4759
Stephen Weeks
sweeks at mlton.org
Mon Oct 23 16:41:07 PDT 2006
Fixed bug in removeFromStackForProfiling. The bug would only show up
with DEBUG_PROFILE true. getSourceName was used on a master index,
which is of course beyond the array of sources. This (correctly)
triggered the assert in getSourceName.
Added a new function, profileIndexSourceName, that tests whether the
index is a source index or a master index, and does the right thing in
each case.
----------------------------------------------------------------------
U mlton/branches/on-20050822-x86_64-branch/runtime/gc/profiling.c
U mlton/branches/on-20050822-x86_64-branch/runtime/gc/profiling.h
----------------------------------------------------------------------
Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/profiling.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/profiling.c 2006-10-23 18:12:01 UTC (rev 4758)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/profiling.c 2006-10-23 23:41:06 UTC (rev 4759)
@@ -9,7 +9,11 @@
GC_profileMasterIndex sourceIndexToProfileMasterIndex (GC_state s,
GC_sourceIndex i)
{
- return s->sourceMaps.sources[i].sourceNameIndex + s->sourceMaps.sourcesLength;
+ GC_profileMasterIndex pmi;
+ pmi = s->sourceMaps.sources[i].sourceNameIndex + s->sourceMaps.sourcesLength;
+ if (DEBUG_PROFILE)
+ fprintf (stderr, "%"PRIu32" = sourceIndexToProfileMasterIndex ("FMTSI")\n", pmi, i);
+ return pmi;
}
GC_sourceNameIndex profileMasterIndexToSourceNameIndex (GC_state s,
@@ -18,12 +22,21 @@
return i - s->sourceMaps.sourcesLength;
}
+char* profileIndexSourceName (GC_state s, GC_sourceIndex i) {
+ char* res;
+
+ if (i < s->sourceMaps.sourcesLength)
+ res = getSourceName (s, i);
+ else
+ res = s->sourceMaps.sourceNames[profileMasterIndexToSourceNameIndex (s, i)];
+ return res;
+}
+
GC_profileStack getProfileStackInfo (GC_state s, GC_profileMasterIndex i) {
assert (s->profiling.data != NULL);
return &(s->profiling.data->stack[i]);
}
-
static int profileDepth = 0;
static void profileIndent (void) {
@@ -33,7 +46,6 @@
fprintf (stderr, " ");
}
-
void addToStackForProfiling (GC_state s, GC_profileMasterIndex i) {
GC_profileData p;
GC_profileStack ps;
@@ -103,7 +115,7 @@
ps = getProfileStackInfo (s, i);
if (DEBUG_PROFILE)
fprintf (stderr, "removing %s from stack ticksInc = %"PRIuMAX" ticksGCInc = %"PRIuMAX"\n",
- getSourceName (s, i),
+ profileIndexSourceName (s, i),
p->total - ps->lastTotal,
p->totalGC - ps->lastTotalGC);
ps->ticks += p->total - ps->lastTotal;
@@ -129,7 +141,7 @@
uint32_t *sourceSeq;
if (DEBUG_PROFILE)
- fprintf (stderr, "profileLeave ("FMTSSI")\n", sourceSeqIndex);
+ fprintf (stderr, "leaveForProfiling ("FMTSSI")\n", sourceSeqIndex);
assert (s->profiling.stack);
assert (sourceSeqIndex < s->sourceMaps.sourceSeqsLength);
p = s->profiling.data;
@@ -457,11 +469,8 @@
profileMasterIndex++) {
if (p->stack[profileMasterIndex].numOccurrences > 0) {
if (DEBUG_PROFILE)
- fprintf (stderr, "done leaving %s\n",
- (profileMasterIndex < s->sourceMaps.sourcesLength)
- ? getSourceName (s, (GC_sourceIndex)profileMasterIndex)
- : s->sourceMaps.sourceNames[
- profileMasterIndexToSourceNameIndex (s, profileMasterIndex)]);
+ fprintf (stderr, "done leaving %s\n",
+ profileIndexSourceName (s, profileMasterIndex));
removeFromStackForProfiling (s, profileMasterIndex);
}
}
Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/profiling.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/profiling.h 2006-10-23 18:12:01 UTC (rev 4758)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/profiling.h 2006-10-23 23:41:06 UTC (rev 4759)
@@ -96,6 +96,8 @@
static inline void incForProfiling (GC_state s, size_t amount, GC_sourceSeqIndex sourceSeqIndex);
+static inline char* profileIndexSourceName (GC_state s, GC_sourceIndex i);
+
static void writeProfileCount (GC_state s, FILE *f, GC_profileData p, GC_profileMasterIndex i);
GC_profileData profileMalloc (GC_state s);
More information about the MLton-commit
mailing list