/* Makes a stack profile on file stackFile. */ void MakeStackProfile(void) { int i, no, sampleNo; TickList *newTick; int *sampleNoTab; float sampleTime; char idStr[100]; GraphReset(); if ((outfp = fopen((char *) &stackName, "w")) == NULL) { printf("Can not open stackfile: %s.\n", stackName); exit(-1); } sprintf(idStr, "%s - Stack profiling", name); jobstring = MallocString(idStr); sprintf(idStr, "%s", timeStr); datestring = MallocString(idStr); sampleNoTab = xmalloc(noOfSamples * sizeof(int)); no = sortSamples(sortOpt, sampleNoTab); i = 0; sampleNo = 0; for (newTick=firstTick;newTick!=NULL;newTick=newTick->nTick,i++) { if ((sampleNo < no) && (sampleNoTab[sampleNo] == i)) { if (useTickNo) { sampleTime = (float)i; } else { sampleTime = (float)newTick->time/(float)CLOCKS_PER_SEC; } /*printf("sampleNo %3d SampleTime %5.2f\n", sampleNo, sampleTime);*/ allocNewSample(sampleNo, sampleTime); storeSampleEntry(sampleNo, sampleTime, "stack", ((float)(newTick->stackUse))*4.0); storeSampleEntry(sampleNo, sampleTime, "rDesc", ((float)(newTick->regionDescUse))*4.0); sampleNo++; } } if (sampleNo != nsamples) /* These two variables have to follow each other. */ Disaster("sampleNo <> nsamples"); if ((noOfSamples >= SampleMax) && (SampleMax != nsamples)) /* If we have more than SampleMax samples, */ Disaster("noOfSamples >= SampleMax and SampleMax <> nsamples."); /* then we keep exactly SampleMax samples. */ showMax = 0; /* Do not show a maximum line. */ yLab = MallocString("bytes"); PutFile(); return; }
floatish MaxCombinedHeight() { intish i; intish j; floatish mx; int bucket; floatish value; struct chunk* ch; floatish *maxima; maxima = (floatish*) xmalloc(nsamples * sizeof(floatish)); for (i = 0; i < nsamples; i++) { maxima[ i ] = 0.0; } for (i = 0; i < nidents; i++) { for (ch = identtable[i]->chk; ch; ch = ch->next) { for (j = 0; j < ch->nd; j++) { bucket = ch->d[j].bucket; value = ch->d[j].value; if (bucket >= nsamples) Disaster("bucket out of range"); maxima[ bucket ] += value; } } } for (mx = maxima[ 0 ], i = 0; i < nsamples; i++) { if (maxima[ i ] > mx) mx = maxima[ i ]; } free(maxima); return mx; }
floatish AreaBelow(void) { intish i; intish j; intish bucket; floatish value; struct chunk *ch; floatish area; floatish trap; floatish base; floatish *maxima; maxima = (floatish *) xmalloc(nsamples * sizeof(floatish)); for (i = 0; i < nsamples; i++) { maxima[i] = 0.0; } for (i = 0; i < nidents; i++) { for (ch = identtable[i]->chk; ch; ch = ch->next) { for (j = 0; j < ch->nd; j++) { bucket = ch->d[j].bucket; value = ch->d[j].value; if (bucket >= nsamples) Disaster("bucket out of range"); maxima[ bucket ] += value; } } } area = 0.0; for (i = 1; i < nsamples; i++) { base = samplemap[i] - samplemap[i-1]; if (maxima[i] > maxima[i-1]) { trap = base * maxima[i-1] + ((base * (maxima[i] - maxima[i-1]))/ 2.0); } else { trap = base * maxima[i] + ((base * (maxima[i-1] - maxima[i]))/ 2.0); } area += trap; } free(maxima); return area; }
void OrderFor(char *ident, int order) { if (! ordermap) { ordermapmax = (nidents > TWENTY ? nidents : TWENTY) * 2; /* Assume nidents read is indication of the No of idents in the .aux file (*2 for good luck !) */ ordermap = xmalloc(ordermapmax * sizeof(struct order)); } if (ordermapindex < ordermapmax) { ordermap[ ordermapindex ].ident = copystring(ident); ordermap[ ordermapindex ].order = order; ordermapindex++; } else { Disaster("order map overflow"); } }
/* and sampleNoTab have range [0, ..., noOfSamples-1]. */ static void sortOutBin(int min, int max, int no, int *sampleNoTab) { int mid, no1, no2; mid = (min+max)/2; if (no == 1) { if (sampleNoTab[mid-1] == -1) Disaster("sortOutBin: sampleNoTab already -1."); sampleNoTab[mid-1] = -1; } else if (no > 1) { no1 = no / 2; no2 = no-no1; sortOutBin(min, mid, no2, sampleNoTab); sortOutBin(mid+1, max, no1, sampleNoTab); } return; }
/* Makes a region profile. */ void MakeObjectProfile(int region) { int i, sampleNo, no; TickList *newTick; ObjectList *newObj; RegionList *newRegion; int *sampleNoTab; float sampleTime; char idStr[100]; int success = 0; GraphReset(); if ((outfp = fopen((char *) &objName, "w")) == NULL) { printf("Cannot open output file %s.\n", objName); exit(-1); } sprintf(idStr, "%s - Object profiling on region %d", name, region); jobstring = MallocString(idStr); sprintf(idStr, "%s", timeStr); datestring = MallocString(idStr); sampleNoTab = xmalloc(noOfSamples * sizeof(int)); no = sortSamples(sortOpt, sampleNoTab); i = 0; sampleNo = 0; for (newTick=firstTick;newTick!=NULL;newTick=newTick->nTick,i++) { if ((sampleNo < no) && (sampleNoTab[sampleNo] == i)) { if (useTickNo) { sampleTime = (float)i; } else { sampleTime = (float)newTick->time/(float)CLOCKS_PER_SEC; } /*printf("sampleNo %3d SampleTime %5.2f\n", sampleNo, sampleTime);*/ allocNewSample(sampleNo, sampleTime); for (newRegion=newTick->fRegion;newRegion!=NULL;newRegion=newRegion->nRegion) { if (newRegion->regionId == region) for (newObj=newRegion->fObj;newObj!=NULL;newObj=newObj->nObj) { success = 1; sprintf(idStr, "pp%d", newObj->atId); storeSampleEntry(sampleNo, sampleTime, idStr, ((float)(newObj->size))*4.0); } } sampleNo++; } } if (success == 0) { printf("There is no profiling information for region r%d, so I could not \ncreate a PostScript file for you.\n", region); exit(-1); } if (sampleNo != nsamples) /* These two variables have to follow each other. */ Disaster("sampleNo <> nsamples"); if ((noOfSamples >= SampleMax) && (SampleMax != nsamples)) /* If we have more than SampleMax samples, */ Disaster("noOfSamples >= SampleMax and SampleMax <> nsamples."); /* then we keep exactly SampleMax samples. */ showMax = 1; maxValue = profTabGetMaxAlloc(region)*4; sprintf(maxValueStr, "Maximum allocated bytes in this region: %2.0f.", maxValue); yLab = MallocString("bytes"); PutFile(); return; }
/* Makes a region profile. */ void MakeRegionProfile(void) { int i, sampleNo, no; TickList *newTick; RegionList *newRegion; int *sampleNoTab; float sampleTime; float maxStack = 0.0; char idStr[100]; GraphReset(); if ((outfp = fopen((char *) &rpName, "w")) == NULL) { printf("Can not open output file %s.\n", rpName); exit(-1); } sprintf(idStr, "%s - Region profiling", name); jobstring = MallocString(idStr); sprintf(idStr, "%s", timeStr); datestring = MallocString(idStr); sampleNoTab = xmalloc(noOfSamples * sizeof(int)); no = sortSamples(sortOpt, sampleNoTab); i = 0; sampleNo = 0; for (newTick=firstTick;newTick!=NULL;newTick=newTick->nTick,i++) { if ((sampleNo < no) && (sampleNoTab[sampleNo] == i)) { if (useTickNo) { sampleTime = (float)i; } else { sampleTime = (float)newTick->time/(float)CLOCKS_PER_SEC; } /*printf("sampleNo %3d SampleTime %5.2f\n", sampleNo, sampleTime);*/ allocNewSample(sampleNo, sampleTime); storeSampleEntry(sampleNo, sampleTime, "stack", ((float)(newTick->stackUse))*4.0); storeSampleEntry(sampleNo, sampleTime, "rDesc", ((float)(newTick->regionDescUse))*4.0); if (((((float)(newTick->stackUse))+((float)(newTick->regionDescUse)))*4.0) > maxStack) /* To ajust the max. */ maxStack = (((float)(newTick->stackUse))+((float)(newTick->regionDescUse)))*4.0; /* allocation line. */ for (newRegion=newTick->fRegion;newRegion!=NULL;newRegion=newRegion->nRegion) { if (newRegion->infinite) sprintf(idStr, "r%dinf", newRegion->regionId); else sprintf(idStr, "r%dfin", newRegion->regionId); storeSampleEntry(sampleNo, sampleTime, idStr, ((float)(newRegion->used))*4.0); } sampleNo++; } } if (sampleNo != nsamples) /* These two variables have to follow each other. */ Disaster("sampleNo <> nsamples"); if ((noOfSamples >= SampleMax) && (SampleMax != nsamples)) /* If we have more than SampleMax samples, */ Disaster("noOfSamples >= SampleMax and SampleMax <> nsamples."); /* then we keep exactly SampleMax samples. */ showMax = 1; maxValue = maxRegions*4; /* The total memory used is often lower than what the line suggests * because the time the stack is maximal may not be the same time * that allocation in regions is maximal! mael 2001-05-22 */ sprintf(maxValueStr, "Maximum allocated bytes in regions (%2.0f) and on stack (%2.0f)", maxValue, maxStack); maxValue += maxStack; /* Ajusting the max. allocation line. */ yLab = MallocString("bytes"); PutFile(); return; }
/* Returns number of samples in sampleNoTab. */ static int sortSamples(int sortType, int *sampleNoTab) { int i, j, m; /* Counters */ int *sampleSizeTab ; /* Table holding size of each sample. */ TickList *newTick; /* Used to walk through the samples. */ RegionList *newRegion; /* Used to walk through the regions in each sample. */ int total, temp; /* Temporary variables. */ int sampleNo; if (sortType == TAKE_BY_SAMPLE_NO) { /* We keep min(MaxSamples, noOfSamples) samples in sampleNoTab sorted */ /* by sampleNo, and equally distributed in the range of sample numbers. */ /* If noOfSamples <= SampleMax then all samples are returned. */ /* If noOfSamples > SampleMax, then sortOutBin is used to sort out */ /* noOfSamples-SampleMax samples by divide and conquer. */ for (i=0;i<noOfSamples;i++) sampleNoTab[i] = i; if (noOfSamples <= SampleMax) /* Return all samples. */ return noOfSamples; else { /* After sortOutBin all samples which have to be sorted out have the */ /* value -1. */ sortOutBin(1, noOfSamples, noOfSamples-SampleMax, sampleNoTab); i = 0; sampleNo=0; for (i=0;i<noOfSamples;i++) { #if DEBUG_SORT_SAMPLES printf("SortSamples (SORT_BY_SAMPLE_NO): sampleNoTab[%3d] = %3d\n", i, sampleNoTab[i]); #endif if (sampleNoTab[i] >= 0) { sampleNoTab[sampleNo] = sampleNoTab[i]; sampleNo++; } } if (sampleNo != SampleMax) /* These two variables have to be equal. */ Disaster("SortSamples: SampleMax <> sampleNo"); return sampleNo; } } else { /* sortType == TAKE_BY_SIZE. */ /* We keep the SampleMax largest samples. */ /* First make a sampleSizeTab holding the size of each sample, and */ /* a sampleNoTab holding the sampleNo w.r.t. the sampleSizeTab. */ sampleSizeTab = xmalloc(noOfSamples * sizeof(int)); i=0; for (newTick=firstTick;newTick!=NULL;newTick=newTick->nTick) { total = 0; for (newRegion=newTick->fRegion;newRegion!=NULL;newRegion=newRegion->nRegion) total += newRegion->used; sampleSizeTab[i] = total; sampleNoTab[i] = i; i++; } /* Then sort the two tables w.r.t. the size of each sample. */ for (i=0; i<noOfSamples-1;i++) { m = i; for (j=i+1; j<noOfSamples;j++) { if (sampleSizeTab[j] > sampleSizeTab[m]) m = j; } temp = sampleSizeTab[m]; sampleSizeTab[m] = sampleSizeTab[i]; sampleSizeTab[i]=temp; temp = sampleNoTab[m]; sampleNoTab[m]=sampleNoTab[i]; sampleNoTab[i]=temp; } for (i=0; i<(min(SampleMax,noOfSamples)-1);i++) { m = i; for (j=i+1; j<min(SampleMax,noOfSamples);j++) { if (sampleNoTab[j] < sampleNoTab[m]) m = j; } temp = sampleSizeTab[m]; sampleSizeTab[m] = sampleSizeTab[i]; sampleSizeTab[i]=temp; temp = sampleNoTab[m]; sampleNoTab[m]=sampleNoTab[i]; sampleNoTab[i]=temp; } return min(SampleMax, noOfSamples); } }