| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/bash/src/lib/malloc/stats.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||||||||
| 2 | - | |||||||||||||||||||||||||
| 3 | - | |||||||||||||||||||||||||
| 4 | - | |||||||||||||||||||||||||
| 5 | - | |||||||||||||||||||||||||
| 6 | - | |||||||||||||||||||||||||
| 7 | - | |||||||||||||||||||||||||
| 8 | - | |||||||||||||||||||||||||
| 9 | - | |||||||||||||||||||||||||
| 10 | extern int malloc_free_blocks (int); | - | ||||||||||||||||||||||||
| 11 | - | |||||||||||||||||||||||||
| 12 | extern struct _malstats _mstats; | - | ||||||||||||||||||||||||
| 13 | - | |||||||||||||||||||||||||
| 14 | extern FILE *_imalloc_fopen (char *, char *, char *, char *, size_t); | - | ||||||||||||||||||||||||
| 15 | - | |||||||||||||||||||||||||
| 16 | struct bucket_stats | - | ||||||||||||||||||||||||
| 17 | malloc_bucket_stats (size) | - | ||||||||||||||||||||||||
| 18 | int size; | - | ||||||||||||||||||||||||
| 19 | { | - | ||||||||||||||||||||||||
| 20 | struct bucket_stats v; | - | ||||||||||||||||||||||||
| 21 | - | |||||||||||||||||||||||||
| 22 | v.nfree = 0; | - | ||||||||||||||||||||||||
| 23 | - | |||||||||||||||||||||||||
| 24 | if (size < 0
| 0 | ||||||||||||||||||||||||
| 25 | { | - | ||||||||||||||||||||||||
| 26 | v.blocksize = 0; | - | ||||||||||||||||||||||||
| 27 | v.nused = v.nmal = v.nmorecore = v.nlesscore = v.nsplit = 0; | - | ||||||||||||||||||||||||
| 28 | return never executed: v;return v;never executed: return v; | 0 | ||||||||||||||||||||||||
| 29 | } | - | ||||||||||||||||||||||||
| 30 | - | |||||||||||||||||||||||||
| 31 | v.blocksize = 1 << (size + 3); | - | ||||||||||||||||||||||||
| 32 | v.nused = _mstats.nmalloc[size]; | - | ||||||||||||||||||||||||
| 33 | v.nmal = _mstats.tmalloc[size]; | - | ||||||||||||||||||||||||
| 34 | v.nmorecore = _mstats.nmorecore[size]; | - | ||||||||||||||||||||||||
| 35 | v.nlesscore = _mstats.nlesscore[size]; | - | ||||||||||||||||||||||||
| 36 | v.nsplit = _mstats.nsplit[size]; | - | ||||||||||||||||||||||||
| 37 | v.ncoalesce = _mstats.ncoalesce[size]; | - | ||||||||||||||||||||||||
| 38 | - | |||||||||||||||||||||||||
| 39 | v.nfree = malloc_free_blocks (size); | - | ||||||||||||||||||||||||
| 40 | - | |||||||||||||||||||||||||
| 41 | return never executed: v;return v;never executed: return v; | 0 | ||||||||||||||||||||||||
| 42 | } | - | ||||||||||||||||||||||||
| 43 | - | |||||||||||||||||||||||||
| 44 | - | |||||||||||||||||||||||||
| 45 | - | |||||||||||||||||||||||||
| 46 | - | |||||||||||||||||||||||||
| 47 | - | |||||||||||||||||||||||||
| 48 | struct _malstats | - | ||||||||||||||||||||||||
| 49 | malloc_stats () | - | ||||||||||||||||||||||||
| 50 | { | - | ||||||||||||||||||||||||
| 51 | struct _malstats result; | - | ||||||||||||||||||||||||
| 52 | struct bucket_stats v; | - | ||||||||||||||||||||||||
| 53 | register int i; | - | ||||||||||||||||||||||||
| 54 | - | |||||||||||||||||||||||||
| 55 | result = _mstats; | - | ||||||||||||||||||||||||
| 56 | result.bytesused = result.bytesfree = 0; | - | ||||||||||||||||||||||||
| 57 | for (i = 0; i < 30
| 0 | ||||||||||||||||||||||||
| 58 | { | - | ||||||||||||||||||||||||
| 59 | v = malloc_bucket_stats (i); | - | ||||||||||||||||||||||||
| 60 | result.bytesfree += v.nfree * v.blocksize; | - | ||||||||||||||||||||||||
| 61 | result.bytesused += v.nused * v.blocksize; | - | ||||||||||||||||||||||||
| 62 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 63 | return never executed: (result);return (result);never executed: return (result); | 0 | ||||||||||||||||||||||||
| 64 | } | - | ||||||||||||||||||||||||
| 65 | - | |||||||||||||||||||||||||
| 66 | static void | - | ||||||||||||||||||||||||
| 67 | _print_malloc_stats (s, fp) | - | ||||||||||||||||||||||||
| 68 | char *s; | - | ||||||||||||||||||||||||
| 69 | FILE *fp; | - | ||||||||||||||||||||||||
| 70 | { | - | ||||||||||||||||||||||||
| 71 | register int i; | - | ||||||||||||||||||||||||
| 72 | unsigned long totused, totfree; | - | ||||||||||||||||||||||||
| 73 | struct bucket_stats v; | - | ||||||||||||||||||||||||
| 74 | - | |||||||||||||||||||||||||
| 75 | fprintf (fp, "Memory allocation statistics: %s\n size\tfree\tin use\ttotal\tmorecore lesscore split\tcoalesce\n", s ? s : ""); | - | ||||||||||||||||||||||||
| 76 | for (i = totused = totfree = 0; i < 30
| 0 | ||||||||||||||||||||||||
| 77 | { | - | ||||||||||||||||||||||||
| 78 | v = malloc_bucket_stats (i); | - | ||||||||||||||||||||||||
| 79 | if (v.nmal > 0
| 0 | ||||||||||||||||||||||||
| 80 | fprintf (fp, "%8lu\t%4d\t%6d\t%5d\t%8d\t%d %5d %8d\n", (unsigned long)v.blocksize, v.nfree, v.nused, v.nmal, v.nmorecore, v.nlesscore, v.nsplit, v.ncoalesce); never executed: fprintf (fp, "%8lu\t%4d\t%6d\t%5d\t%8d\t%d %5d %8d\n", (unsigned long)v.blocksize, v.nfree, v.nused, v.nmal, v.nmorecore, v.nlesscore, v.nsplit, v.ncoalesce); | 0 | ||||||||||||||||||||||||
| 81 | totfree += v.nfree * v.blocksize; | - | ||||||||||||||||||||||||
| 82 | totused += v.nused * v.blocksize; | - | ||||||||||||||||||||||||
| 83 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 84 | fprintf (fp, "\nTotal bytes in use: %lu, total bytes free: %lu\n", | - | ||||||||||||||||||||||||
| 85 | totused, totfree); | - | ||||||||||||||||||||||||
| 86 | fprintf (fp, "\nTotal bytes requested by application: %lu\n", (unsigned long)_mstats.bytesreq); | - | ||||||||||||||||||||||||
| 87 | fprintf (fp, "Total mallocs: %d, total frees: %d, total reallocs: %d (%d copies)\n", | - | ||||||||||||||||||||||||
| 88 | _mstats.nmal, _mstats.nfre, _mstats.nrealloc, _mstats.nrcopy); | - | ||||||||||||||||||||||||
| 89 | fprintf (fp, "Total sbrks: %d, total bytes via sbrk: %d\n", | - | ||||||||||||||||||||||||
| 90 | _mstats.nsbrk, _mstats.tsbrk); | - | ||||||||||||||||||||||||
| 91 | fprintf (fp, "Total blocks split: %d, total block coalesces: %d\n", | - | ||||||||||||||||||||||||
| 92 | _mstats.tbsplit, _mstats.tbcoalesce); | - | ||||||||||||||||||||||||
| 93 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 94 | - | |||||||||||||||||||||||||
| 95 | void | - | ||||||||||||||||||||||||
| 96 | print_malloc_stats (s) | - | ||||||||||||||||||||||||
| 97 | char *s; | - | ||||||||||||||||||||||||
| 98 | { | - | ||||||||||||||||||||||||
| 99 | _print_malloc_stats (s, | - | ||||||||||||||||||||||||
| 100 | stderr | - | ||||||||||||||||||||||||
| 101 | ); | - | ||||||||||||||||||||||||
| 102 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 103 | - | |||||||||||||||||||||||||
| 104 | void | - | ||||||||||||||||||||||||
| 105 | fprint_malloc_stats (s, fp) | - | ||||||||||||||||||||||||
| 106 | char *s; | - | ||||||||||||||||||||||||
| 107 | FILE *fp; | - | ||||||||||||||||||||||||
| 108 | { | - | ||||||||||||||||||||||||
| 109 | _print_malloc_stats (s, fp); | - | ||||||||||||||||||||||||
| 110 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 111 | - | |||||||||||||||||||||||||
| 112 | - | |||||||||||||||||||||||||
| 113 | - | |||||||||||||||||||||||||
| 114 | void | - | ||||||||||||||||||||||||
| 115 | trace_malloc_stats (s, fn) | - | ||||||||||||||||||||||||
| 116 | char *s, *fn; | - | ||||||||||||||||||||||||
| 117 | { | - | ||||||||||||||||||||||||
| 118 | FILE *fp; | - | ||||||||||||||||||||||||
| 119 | char defname[sizeof ("/var/tmp/maltrace/stats.") + 64]; | - | ||||||||||||||||||||||||
| 120 | static char mallbuf[1024]; | - | ||||||||||||||||||||||||
| 121 | - | |||||||||||||||||||||||||
| 122 | fp = _imalloc_fopen (s, fn, "/var/tmp/maltrace/stats.", defname, sizeof (defname)); | - | ||||||||||||||||||||||||
| 123 | if (fp
| 0 | ||||||||||||||||||||||||
| 124 | { | - | ||||||||||||||||||||||||
| 125 | setvbuf (fp, mallbuf, | - | ||||||||||||||||||||||||
| 126 | 0 | - | ||||||||||||||||||||||||
| 127 | , sizeof (mallbuf)); | - | ||||||||||||||||||||||||
| 128 | _print_malloc_stats (s, fp); | - | ||||||||||||||||||||||||
| 129 | fflush(fp); | - | ||||||||||||||||||||||||
| 130 | fclose(fp); | - | ||||||||||||||||||||||||
| 131 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 132 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 133 | - | |||||||||||||||||||||||||
| 134 | - | |||||||||||||||||||||||||
| 135 | - | |||||||||||||||||||||||||
| 136 | - | |||||||||||||||||||||||||
| 137 | FILE * | - | ||||||||||||||||||||||||
| 138 | _imalloc_fopen (s, fn, def, defbuf, defsiz) | - | ||||||||||||||||||||||||
| 139 | char *s; | - | ||||||||||||||||||||||||
| 140 | char *fn; | - | ||||||||||||||||||||||||
| 141 | char *def; | - | ||||||||||||||||||||||||
| 142 | char *defbuf; | - | ||||||||||||||||||||||||
| 143 | size_t defsiz; | - | ||||||||||||||||||||||||
| 144 | { | - | ||||||||||||||||||||||||
| 145 | char fname[1024]; | - | ||||||||||||||||||||||||
| 146 | long l; | - | ||||||||||||||||||||||||
| 147 | FILE *fp; | - | ||||||||||||||||||||||||
| 148 | - | |||||||||||||||||||||||||
| 149 | l = (long)getpid (); | - | ||||||||||||||||||||||||
| 150 | if (fn == 0
| 0 | ||||||||||||||||||||||||
| 151 | { | - | ||||||||||||||||||||||||
| 152 | sprintf (defbuf, "%s%ld", def, l); | - | ||||||||||||||||||||||||
| 153 | fp = fopen(defbuf, "w"); | - | ||||||||||||||||||||||||
| 154 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 155 | else | - | ||||||||||||||||||||||||
| 156 | { | - | ||||||||||||||||||||||||
| 157 | char *p, *q, *r; | - | ||||||||||||||||||||||||
| 158 | char pidbuf[32]; | - | ||||||||||||||||||||||||
| 159 | int sp; | - | ||||||||||||||||||||||||
| 160 | - | |||||||||||||||||||||||||
| 161 | sprintf (pidbuf, "%ld", l); | - | ||||||||||||||||||||||||
| 162 | if ((
| 0 | ||||||||||||||||||||||||
| 163 | return never executed: ((FILE *)0);return ((FILE *)0);never executed: return ((FILE *)0); | 0 | ||||||||||||||||||||||||
| 164 | for (sp = 0, p = fname, q = fn; *
| 0 | ||||||||||||||||||||||||
| 165 | { | - | ||||||||||||||||||||||||
| 166 | if (sp == 0
| 0 | ||||||||||||||||||||||||
| 167 | { | - | ||||||||||||||||||||||||
| 168 | sp = 1; | - | ||||||||||||||||||||||||
| 169 | for (r = pidbuf; *
| 0 | ||||||||||||||||||||||||
| 170 | * never executed: p++ = *r++;*p++ = *r++;never executed: *p++ = *r++; | 0 | ||||||||||||||||||||||||
| 171 | q += 2; | - | ||||||||||||||||||||||||
| 172 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 173 | else | - | ||||||||||||||||||||||||
| 174 | * never executed: p++ = *q++;*p++ = *q++;never executed: *p++ = *q++; | 0 | ||||||||||||||||||||||||
| 175 | } | - | ||||||||||||||||||||||||
| 176 | *p = '\0'; | - | ||||||||||||||||||||||||
| 177 | fp = fopen (fname, "w"); | - | ||||||||||||||||||||||||
| 178 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 179 | - | |||||||||||||||||||||||||
| 180 | return never executed: fp;return fp;never executed: return fp; | 0 | ||||||||||||||||||||||||
| 181 | } | - | ||||||||||||||||||||||||
| Switch to Source code | Preprocessed file |