Changeset 31152 for trunk/psLib/src/sys/psMemory.c
- Timestamp:
- Apr 4, 2011, 12:57:08 PM (15 years ago)
- Location:
- trunk/psLib
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/sys/psMemory.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib
- Property svn:ignore
-
old new 34 34 *.bbg 35 35 *.da 36 a.out.dSYM
-
- Property svn:ignore
-
trunk/psLib/src/sys/psMemory.c
r30595 r31152 27 27 #include <string.h> 28 28 #include <assert.h> 29 #include <unistd.h> 29 30 30 31 #if defined(PS_MEM_BACKTRACE) && defined(HAVE_BACKTRACE) … … 1090 1091 return (memBlock1->freeFunc == memBlock2->freeFunc); 1091 1092 } 1093 1094 bool static dumpMemory = false; 1095 1096 void psMemDumpSetState (bool state) { 1097 dumpMemory = state; 1098 } 1099 1100 void psMemDump(const char *name) 1101 { 1102 if (!dumpMemory) return; 1103 1104 char filename[1024]; // don't make your sub-names too long! 1105 static int num = 0; // Counter, to make files unique and give an idea of sequence 1106 1107 snprintf (filename, 1024, "memdump_%s_%03d.txt", name, num); 1108 FILE *memFile = fopen(filename, "w"); 1109 1110 psMemBlock **leaks = NULL; 1111 int numLeaks = psMemCheckLeaks(0, &leaks, NULL, true); 1112 fprintf(memFile, "# MemBlock Size Source\n"); 1113 unsigned long total = 0; // Total memory used 1114 for (int i = 0; i < numLeaks; i++) { 1115 psMemBlock *mb = leaks[i]; 1116 fprintf(memFile, "%12lu\t%12zd\t%s:%d\n", mb->id, mb->userMemorySize, mb->file, mb->lineno); 1117 total += mb->userMemorySize; 1118 } 1119 fclose(memFile); 1120 psFree(leaks); 1121 1122 // fprintf(stderr, "Memdump %s %d: Memory use: %ld, sbrk: %p\n", name, num, total, (void *) sbrk(0)); 1123 fprintf(stderr, "Memdump %s %d: Memory use: %ld\n", name, num, total); 1124 num++; 1125 }
Note:
See TracChangeset
for help on using the changeset viewer.
