From: Spacy <sp...@us...> - 2006-08-25 14:13:41
|
Update of /cvsroot/vba/VisualBoyAdvance/src/prof In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv8786/src/prof Modified Files: prof.cpp prof.h Log Message: Applied patch [ 1044856 ] Enable profiling multiple regions of memory. by Rib Rdb - ribrdb Index: prof.cpp =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/prof/prof.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** prof.cpp 13 May 2004 15:06:47 -0000 1.5 --- prof.cpp 25 Aug 2006 14:13:38 -0000 1.6 *************** *** 58,75 **** #include "../NLS.h" /* * froms is actually a bunch of unsigned shorts indexing tos */ static int profiling = 3; - static unsigned short *froms; - static struct tostruct *tos = 0; - static long tolimit = 0; - static u32 s_lowpc = 0; - static u32 s_highpc = 0; - static unsigned long s_textsize = 0; ! static int ssiz; ! static char *sbuf; ! static int s_scale; static int hz = 0; --- 58,69 ---- #include "../NLS.h" + #include "prof.h" /* for struct profile_segment */ + /* * froms is actually a bunch of unsigned shorts indexing tos */ static int profiling = 3; ! static profile_segment *first_segment = NULL; static int hz = 0; *************** *** 128,132 **** /* start */ #ifdef PROFILING ! cpuProfil(sbuf, ssiz, (u32)s_lowpc, s_scale); #endif profiling = 0; --- 122,126 ---- /* start */ #ifdef PROFILING ! cpuProfil(first_segment); #endif profiling = 0; *************** *** 134,138 **** /* stop */ #ifdef PROFILING ! cpuProfil(NULL, 0, 0, 0); #endif profiling = 3; --- 128,132 ---- /* stop */ #ifdef PROFILING ! cpuProfil(NULL); #endif profiling = 3; *************** *** 148,152 **** --- 142,154 ---- char *buffer; int o; + profile_segment *newseg = (profile_segment*)calloc(1,sizeof(profile_segment)); + if (newseg) { + newseg->next = first_segment; + first_segment = newseg; + } else { + systemMessage(0, MSG); + return; + } /* * round lowpc and highpc to multiples of the density we're using *************** *** 154,162 **** */ lowpc = ROUNDDOWN(lowpc, HISTFRACTION*sizeof(HISTCOUNTER)); ! s_lowpc = lowpc; highpc = ROUNDUP(highpc, HISTFRACTION*sizeof(HISTCOUNTER)); ! s_highpc = highpc; ! s_textsize = highpc - lowpc; ! monsize = (s_textsize / HISTFRACTION); buffer = (char *)calloc(1, 2*monsize ); if ( buffer == NULL ) { --- 156,164 ---- */ lowpc = ROUNDDOWN(lowpc, HISTFRACTION*sizeof(HISTCOUNTER)); ! newseg->s_lowpc = lowpc; highpc = ROUNDUP(highpc, HISTFRACTION*sizeof(HISTCOUNTER)); ! newseg->s_highpc = highpc; ! newseg->s_textsize = highpc - lowpc; ! monsize = (newseg->s_textsize / HISTFRACTION); buffer = (char *)calloc(1, 2*monsize ); if ( buffer == NULL ) { *************** *** 164,169 **** return; } ! froms = (unsigned short *) calloc(1, 4*s_textsize / HASHFRACTION ); ! if ( froms == NULL ) { systemMessage(0, MSG); free(buffer); --- 166,171 ---- return; } ! newseg->froms = (unsigned short *) calloc(1, 4*newseg->s_textsize / HASHFRACTION ); ! if ( newseg->froms == NULL ) { systemMessage(0, MSG); free(buffer); *************** *** 171,182 **** return; } ! tolimit = s_textsize * ARCDENSITY / 100; ! if ( tolimit < MINARCS ) { ! tolimit = MINARCS; ! } else if ( tolimit > 65534 ) { ! tolimit = 65534; } ! tos = (struct tostruct *) calloc(1, tolimit * sizeof( struct tostruct ) ); ! if ( tos == NULL ) { systemMessage(0, MSG); --- 173,184 ---- return; } ! newseg->tolimit = newseg->s_textsize * ARCDENSITY / 100; ! if ( newseg->tolimit < MINARCS ) { ! newseg->tolimit = MINARCS; ! } else if ( newseg->tolimit > 65534 ) { ! newseg->tolimit = 65534; } ! newseg->tos = (struct tostruct *) calloc(1, newseg->tolimit * sizeof( struct tostruct ) ); ! if ( newseg->tos == NULL ) { systemMessage(0, MSG); *************** *** 184,202 **** buffer = NULL; ! free(froms); ! froms = NULL; return; } ! tos[0].link = 0; ! sbuf = buffer; ! ssiz = monsize; if ( monsize <= 0 ) return; o = highpc - lowpc; if( monsize < o ) ! s_scale = (int)(( (float) monsize / o ) * SCALE_1_TO_1); else ! s_scale = SCALE_1_TO_1; profControl(1); } --- 186,204 ---- buffer = NULL; ! free(newseg->froms); ! newseg->froms = NULL; return; } ! newseg->tos[0].link = 0; ! newseg->sbuf = buffer; ! newseg->ssiz = monsize; if ( monsize <= 0 ) return; o = highpc - lowpc; if( monsize < o ) ! newseg->s_scale = (int)(( (float) monsize / o ) * SCALE_1_TO_1); else ! newseg->s_scale = SCALE_1_TO_1; profControl(1); } *************** *** 210,213 **** --- 212,216 ---- int toindex; struct gmon_hdr ghdr; + profile_segment *seg = first_segment; profControl(0); *************** *** 230,238 **** hz = 100; ! hist_num_bins = ssiz; if(profWrite8(fd, GMON_TAG_TIME_HIST) || ! profWrite32(fd, (u32)s_lowpc) || ! profWrite32(fd, (u32)s_highpc) || profWrite32(fd, hist_num_bins) || profWrite32(fd, hz) || --- 233,243 ---- hz = 100; ! while(seg) { ! ! hist_num_bins = seg->ssiz; if(profWrite8(fd, GMON_TAG_TIME_HIST) || ! profWrite32(fd, (u32)seg->s_lowpc) || ! profWrite32(fd, (u32)seg->s_highpc) || profWrite32(fd, hist_num_bins) || profWrite32(fd, hz) || *************** *** 243,247 **** return; } ! u16 *hist_sample = (u16 *)sbuf; u16 count; --- 248,252 ---- return; } ! u16 *hist_sample = (u16 *)seg->sbuf; u16 count; *************** *** 258,272 **** } ! endfrom = s_textsize / (HASHFRACTION * sizeof(*froms)); for ( fromindex = 0 ; fromindex < endfrom ; fromindex++ ) { ! if ( froms[fromindex] == 0 ) { continue; } ! frompc = s_lowpc + (fromindex * HASHFRACTION * sizeof(*froms)); ! for (toindex=froms[fromindex]; toindex!=0; toindex=tos[toindex].link) { if(profWrite8(fd, GMON_TAG_CG_ARC) || profWrite32(fd, (u32)frompc) || ! profWrite32(fd, (u32)tos[toindex].selfpc) || ! profWrite32(fd, tos[toindex].count)) { systemMessage(0, "mcount: arc"); fclose(fd); --- 263,277 ---- } ! endfrom = seg->s_textsize / (HASHFRACTION * sizeof(*seg->froms)); for ( fromindex = 0 ; fromindex < endfrom ; fromindex++ ) { ! if ( seg->froms[fromindex] == 0 ) { continue; } ! frompc = seg->s_lowpc + (fromindex * HASHFRACTION * sizeof(*seg->froms)); ! for (toindex=seg->froms[fromindex]; toindex!=0; toindex=seg->tos[toindex].link) { if(profWrite8(fd, GMON_TAG_CG_ARC) || profWrite32(fd, (u32)frompc) || ! profWrite32(fd, (u32)seg->tos[toindex].selfpc) || ! profWrite32(fd, seg->tos[toindex].count)) { systemMessage(0, "mcount: arc"); fclose(fd); *************** *** 275,278 **** --- 280,285 ---- } } + seg = seg->next; + } fclose(fd); } *************** *** 285,288 **** --- 292,296 ---- register struct tostruct *prevtop; register long toindex; + profile_segment *seg = first_segment; /* *************** *** 310,319 **** * not from text space. too bad. */ ! frompcindex = (unsigned short *) ((long) frompcindex - (long) s_lowpc); ! if ((unsigned long) frompcindex > s_textsize) { goto done; } frompcindex = ! &froms[((long) frompcindex) / (HASHFRACTION * sizeof(*froms))]; toindex = *frompcindex; if (toindex == 0) { --- 318,334 ---- * not from text space. too bad. */ ! while(seg) { ! u32 index = (long)frompcindex - (long)seg->s_lowpc; ! if (index <= seg->s_textsize) { ! frompcindex = (unsigned short *) index; ! break; ! } ! seg = seg->next; ! } ! if ((unsigned long) frompcindex > seg->s_textsize) { goto done; } frompcindex = ! &(seg->froms[((long) frompcindex) / (HASHFRACTION * sizeof(*seg->froms))]); toindex = *frompcindex; if (toindex == 0) { *************** *** 321,330 **** * first time traversing this arc */ ! toindex = ++tos[0].link; ! if (toindex >= tolimit) { goto overflow; } *frompcindex = (unsigned short)toindex; ! top = &tos[toindex]; top->selfpc = selfpc; top->count = 1; --- 336,345 ---- * first time traversing this arc */ ! toindex = ++seg->tos[0].link; ! if (toindex >= seg->tolimit) { goto overflow; } *frompcindex = (unsigned short)toindex; ! top = &seg->tos[toindex]; top->selfpc = selfpc; top->count = 1; *************** *** 332,336 **** goto done; } ! top = &tos[toindex]; if (top->selfpc == selfpc) { /* --- 347,351 ---- goto done; } ! top = &seg->tos[toindex]; if (top->selfpc == selfpc) { /* *************** *** 354,362 **** * and link it to the head of the chain. */ ! toindex = ++tos[0].link; ! if (toindex >= tolimit) { goto overflow; } ! top = &tos[toindex]; top->selfpc = selfpc; top->count = 1; --- 369,377 ---- * and link it to the head of the chain. */ ! toindex = ++seg->tos[0].link; ! if (toindex >= seg->tolimit) { goto overflow; } ! top = &seg->tos[toindex]; top->selfpc = selfpc; top->count = 1; *************** *** 369,373 **** */ prevtop = top; ! top = &tos[top->link]; if (top->selfpc == selfpc) { /* --- 384,388 ---- */ prevtop = top; ! top = &seg->tos[top->link]; if (top->selfpc == selfpc) { /* Index: prof.h =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/prof/prof.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** prof.h 13 May 2004 15:06:47 -0000 1.2 --- prof.h 25 Aug 2006 14:13:38 -0000 1.3 *************** *** 25,28 **** --- 25,46 ---- all the data structures are ready. */ + + typedef struct profile_segment { + unsigned short *froms; + struct tostruct *tos; + long tolimit; + + u32 s_lowpc; + u32 s_highpc; + unsigned long s_textsize; + + int ssiz; + char *sbuf; + int s_scale; + + struct profile_segment *next; + + } profile_segment; + extern void profControl(int mode); extern void profStartup(u32 lowpc, u32 highpc); |