Annotation of researchv10no/cmd/sml/src/runtime/prof.c, revision 1.1.1.1

1.1       root        1: /* Copyright 1989 by AT&T Bell Laboratories */
                      2: extern chatting();
                      3: #define printf chatting
                      4: #define plural(a,b,c) (((a)==1)?(b):(c))
                      5: 
                      6: #ifdef PROFILE
                      7: 
                      8: #include <stdio.h>
                      9: #include "prof.h"
                     10: 
                     11: int profvec[PROFSIZE];
                     12: #define getprof(x) (profvec[x]/2)
                     13: 
                     14: int num_closures = 0;
                     15: int space_closures = 0;
                     16: int num_closure_accesses = 0;
                     17: int num_links_traced = 0;
                     18: int num_records = 0;
                     19: int space_records = 0;
                     20: int num_spills = 0;
                     21: int space_spills = 0;
                     22: int total = 0;
                     23: int descriptors = 0;
                     24: int num_calls = 0;
                     25: int num_arith_ops = 0;
                     26: int num_arith_ovh = 0;
                     27: extern int arenasize;
                     28: 
                     29: /*
                     30: #define links(i) (getprof(LINKS+i))
                     31: */
                     32: #define closures(i) (getprof(CLOSURES+i))
                     33: #define records(i) (getprof(RECORDS+i))
                     34: #define spills(i) (getprof(SPILLS+i))
                     35: #define arith(i) (getprof(ARITHOVH+i))
                     36: 
                     37: find_profile_info()
                     38: {
                     39:        int i;
                     40: 
                     41:        num_calls = getprof(KNOWNCALLS) + getprof(STDKCALLS) + getprof(STDCALLS);
                     42: 
                     43:        for (i = 0; i < CLOSURESLOTS; i++)
                     44:                num_closures += closures(i);
                     45:        for (i = 1; i < CLOSURESLOTS; i++)
                     46:                space_closures += closures(i) * (i+1);
                     47:        space_closures += getprof(CLOSUREOVFL) + closures(0);
                     48: 
                     49: /*
                     50:        for (i = 0; i < LINKSLOTS; i++)
                     51:                num_closure_accesses += links(i);
                     52:        for (i = 1; i < LINKSLOTS; i++)
                     53:                num_links_traced += links(i) * i;
                     54:        num_links_traced += getprof(BIGLINKS);
                     55: */
                     56: 
                     57:        for (i = 0; i < RECORDSLOTS; i++)
                     58:                num_records += records(i);
                     59:        for (i = 1; i < RECORDSLOTS; i++)
                     60:                space_records += records(i) * (i+1);
                     61:        space_records += getprof(RECORDOVFL) + records(0);
                     62: 
                     63:        for (i = 0; i < SPILLSLOTS; i++)
                     64:                num_spills += spills(i);
                     65:        for (i = 1; i < SPILLSLOTS; i++)
                     66:                space_spills += spills(i) * (i+1);
                     67:        space_spills += getprof(SPILLOVFL) + spills(0);
                     68:        total = space_closures + space_records + space_spills
                     69:                + getprof(ARRAYSIZE) + getprof(ARRAYS)
                     70:                + getprof(STRINGSIZE) + getprof(STRINGS)
                     71:                + getprof(REFCELLS) * 2
                     72:                + getprof(REFLISTS) * 2;
                     73: 
                     74:        descriptors = num_closures + num_records + num_spills
                     75:                 + getprof(ARRAYS) + getprof(STRINGS)+ getprof(REFCELLS);
                     76: 
                     77: 
                     78:        for (i = 0; i < ARITHSLOTS; i++)
                     79:                num_arith_ops += arith(i);
                     80:        for (i = 1; i < ARITHSLOTS; i++)
                     81:                num_arith_ovh += arith(i) * i;
                     82: 
                     83: }
                     84: 
                     85: print_alloc_info()
                     86: {
                     87:        int k; float f;
                     88:        char *s,*s1;
                     89: 
                     90:        printf("\nProfiling information:\n\n");
                     91: 
                     92:        printf("%d function calls:\n",num_calls);
                     93:        printf("%d known (%.1f%%),\n%d stdk (%.1f%%),\n",
                     94:                getprof(KNOWNCALLS),100.0*getprof(KNOWNCALLS)/num_calls,
                     95:                getprof(STDKCALLS),100.0*getprof(STDKCALLS)/num_calls);
                     96:        printf("%d continuation (%.1f%%),\n%d std (%.1f%%).\n\n",
                     97:                getprof(CNTCALLS),100.0*getprof(CNTCALLS)/num_calls,
                     98:                getprof(STDCALLS),100.0*getprof(STDCALLS)/num_calls);
                     99: 
                    100:        printf("Maximum heap size %dk\n",arenasize/1024);
                    101:        printf("Heap allocations: (only total sizes include descriptors)\n");
                    102:        printf("Total size %d; %d descriptors accounted for %.1f%%.\n\n",
                    103:                total, descriptors, 100.0*descriptors/total);
                    104: 
                    105:        printf("  Size   Number   %% total   Total size    %% total\n\n");
                    106: 
                    107:        if (num_closures > 0) {
                    108:        printf("Closures:\n");
                    109:        for (k = 1; k < CLOSURESLOTS; k++)
                    110:                if (closures(k) > 0)
                    111:                printf("%6d%9d%9.1f%%%13d%10.1f%%\n",
                    112:                        k,
                    113:                        closures(k),
                    114:                        100.0*closures(k)/num_closures,
                    115:                        closures(k) * (k+1),
                    116:                        100.0*(closures(k)*(k+1))/total);
                    117:        if (closures(0) > 0)
                    118:                printf(">%5d%9d%9.1f%%%13d%10.1f%%\n",
                    119:                        CLOSURESLOTS - 1,
                    120:                        closures(0),
                    121:                        100.0*closures(0)/num_closures,
                    122:                        getprof(CLOSUREOVFL)+closures(0),
                    123:                        100.0*(getprof(CLOSUREOVFL)+closures(0))/total);
                    124:        printf("Total:%9d%23d%10.1f%%  Average size %.2f\n\n",
                    125:            num_closures, space_closures, 100.0*space_closures/total,
                    126:            (float)(space_closures-num_closures)/num_closures);
                    127:        }
                    128: 
                    129:        if (num_records > 0) {
                    130:        printf("Records:\n");
                    131:        for (k = 1; k < RECORDSLOTS; k++)
                    132:                if (records(k) > 0)
                    133:                printf("%6d%9d%9.1f%%%13d%10.1f%%\n",
                    134:                        k,
                    135:                        records(k),
                    136:                        100.0*records(k)/num_records,
                    137:                        records(k) * (k+1),
                    138:                        100.0*(records(k) * (k+1)) / total);
                    139:        if (records(0) > 0)
                    140:                printf(">%5d%9d%9.1f%%%13d%10.1f%%\n",
                    141:                        RECORDSLOTS - 1,
                    142:                        records(0),
                    143:                        100.0*records(0)/num_records,
                    144:                        getprof(RECORDOVFL) + records(0),
                    145:                        100.0*(getprof(RECORDOVFL) + records(0)) / total);
                    146:        printf("Total:%9d%23d%10.1f%%  Average size %.2f\n\n",
                    147:            num_records,space_records,100.0*space_records/total,
                    148:            (float)(space_records-num_records)/num_records);
                    149:        }
                    150: 
                    151:        if (num_spills > 0) {
                    152:        printf("Spills:\n");
                    153:        for (k = 1; k < SPILLSLOTS; k++)
                    154:                if (spills(k) > 0)
                    155:                printf("%6d%9d%9.1f%%%13d%10.1f%%\n",
                    156:                        k,
                    157:                        spills(k),
                    158:                        100.0*spills(k)/num_spills,
                    159:                        spills(k) * (k+1),
                    160:                        100.0*(spills(k) * (k+1)) / total);
                    161:        if (spills(0) > 0)
                    162:                printf(">%5d%9d%9.1f%%%13d%10.1f%%\n",
                    163:                        SPILLSLOTS - 1,
                    164:                        spills(0),
                    165:                        100.0*spills(0)/num_spills,
                    166:                        getprof(SPILLOVFL) + spills(0),
                    167:                        100.0*(getprof(SPILLOVFL) + spills(0)) / total);
                    168:        printf("Total:%9d%23d%10.1f%%  Average size %.2f\n\n",
                    169:            num_spills,space_spills,100.0*space_spills/total,
                    170:            (float)(space_spills-num_spills)/num_spills);
                    171:        }
                    172: 
                    173:        if (getprof(ARRAYS))
                    174:        printf("Arrays:%8d%23d%10.1f%%  Average size %.2f\n",
                    175:                getprof(ARRAYS),
                    176:                getprof(ARRAYSIZE) + getprof(ARRAYS),
                    177:                100.0*(getprof(ARRAYSIZE) + getprof(ARRAYS)) / total,
                    178:                (float)getprof(ARRAYSIZE)/getprof(ARRAYS));
                    179: 
                    180:        if (getprof(STRINGS))
                    181:        printf("Strings:%7d%23d%10.1f%%  Average size %.2f\n",
                    182:                getprof(STRINGS),
                    183:                getprof(STRINGSIZE) + getprof(STRINGS),
                    184:                100.0*(getprof(STRINGSIZE) + getprof(STRINGS)) / total,
                    185:                (float)getprof(STRINGSIZE)/getprof(STRINGS));
                    186: 
                    187:        if (getprof(REFCELLS))
                    188:        printf("Refs:%10d%23d%10.1f%%\n",
                    189:                getprof(REFCELLS),
                    190:                getprof(REFCELLS)*2,
                    191:                100.0*(getprof(REFCELLS)*2) / total);
                    192: 
                    193:        if (getprof(REFLISTS))
                    194:        printf("Reflist\ncells:%9d%23d%10.1f%%\n",
                    195:                getprof(REFLISTS),
                    196:                getprof(REFLISTS)*2,
                    197:                100.0*(getprof(REFLISTS)*2) / total);
                    198: 
                    199: }
                    200: 
                    201: 
                    202: print_arith_info()
                    203: {int i;
                    204:  printf("\n");
                    205:  printf("Arithmetic Overhead Information:\n");
                    206:  for(i=0;i<ARITHSLOTS;i++)
                    207:    printf("Overhead %d:    %9d\n",i,arith(i));
                    208:  printf(  "Total Overhead: %9d\n",num_arith_ovh);
                    209:  printf(  "Total Operations:%8d\n",num_arith_ops);
                    210:  printf("\n");
                    211: }
                    212: 
                    213: print_profile_info()
                    214: {
                    215:        find_profile_info();
                    216:        if (num_closures > 0 || num_records > 0 || num_spills > 0 || num_calls > 0)
                    217:                print_alloc_info();
                    218:         if (num_arith_ops > 0)
                    219:                print_arith_info();
                    220: }
                    221: 
                    222: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.