void GraphReset() { sampletable = (float *) xmalloc(SampleMax * sizeof(float)); jobstring = MallocString("Jobstring"); datestring = MallocString("Datestring"); programname = MallocString("Programname"); output = &PsOutput; return; }
static Variable NewVariableType(char *name,char *type) { Variable var=(Variable)Calloc(1,sizeof(struct _Variable)); /* clear unused pointers */ var->name =MallocString(name); var->type =MallocString(type); var->visible=NewStringList2(); var->used =NewStringList2(); return(var); }
/* 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; }
void SeenVariableDefinition(char* name,char* type,int scope) { Variable var; int seen=0; #if DEBUG printf("#Var.c# Variable definition for '%s'\n",name); #endif for(var=CurFile->variables;var;var=var->next) if(!strcmp(var->name,name)) { var->scope|=scope; seen=1; if(!in_header && var->scope&EXTERN_H) { if(var->comment) Free(var->comment); var->comment=MallocString(GetCurrentComment()); var->lineno=parse_line; } break; } if(!seen) { var=NewVariableType(name,type); var->comment=MallocString(GetCurrentComment()); var->scope=scope; var->lineno=parse_line; if(in_header && !(scope&EXTERN_H)) var->incfrom=MallocString(parse_file); AddToLinkedList(CurFile->variables,Variable,var); } }
/* 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; }