]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add a malloc size histogram to the debugging malloc implementation
authordrh <drh@noemail.net>
Mon, 15 Oct 2007 19:34:32 +0000 (19:34 +0000)
committerdrh <drh@noemail.net>
Mon, 15 Oct 2007 19:34:32 +0000 (19:34 +0000)
in mem2.c. (CVS 4490)

FossilOrigin-Name: 3e51696cb878063e4ebfdcc2a61ba94c9bebdfe3

manifest
manifest.uuid
src/mem2.c
test/tester.tcl

index 800e5276512aa97dfd1147b994f55655ff781d27..c0107c31d299d724b22b8066ed76d7b9965bede5 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sfor\sOMIT_AUTHORIZATION\sbuilds.\s(CVS\s4489)
-D 2007-10-15T07:08:44
+C Add\sa\smalloc\ssize\shistogram\sto\sthe\sdebugging\smalloc\simplementation\nin\smem2.c.\s(CVS\s4490)
+D 2007-10-15T19:34:32
 F Makefile.in 75b729d562e9525d57d9890ec598b38e1a8b02bc
 F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -103,7 +103,7 @@ F src/main.c 994a6b6914d91dc6dea5012667ec0a52e74d3bca
 F src/malloc.c de4e77fe70a9a0ac47a1c3a874422b107231bf31
 F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
 F src/mem1.c 232075b7da8c9b7f23159bbda25c7407168ab9db
-F src/mem2.c 9c59519e471f858961fbdccd9543317bba1c5e58
+F src/mem2.c 8651e5306c1d5c0a7ab91c027a653ced1ca3e6d6
 F src/mutex.c 3259f62c2429967aee6dc112117a6d2f499ef061
 F src/mutex.h 079fa6fe9da18ceb89e79012c010594c6672addb
 F src/mutex_os2.c 7fe4773e98ed74a63b2e54fc557929eb155f6269
@@ -427,7 +427,7 @@ F test/table.test 13b1c2e2fb4727b35ee1fb7641fc469214fd2455
 F test/tableapi.test 92651a95c23cf955e92407928e640536402fa3cc
 F test/tclsqlite.test c7feea1985c3e8a1ed134ba342347d47fa762e43
 F test/temptable.test 19b851b9e3e64d91e9867619b2a3f5fffee6e125
-F test/tester.tcl 913a808f05b0aed2fbb16481a423b1a5a118bdf0
+F test/tester.tcl 0fea2ceef69678ee8b15d3dd64d29f659449a081
 F test/thread001.test 8fbd9559da0bbdc273e00318c7fd66c162020af7
 F test/thread002.test 2c4ad2c386f60f6fe268cd91c769ee35b3c1fd0b
 F test/thread1.test 776c9e459b75ba905193b351926ac4019b049f35
@@ -581,7 +581,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
-P e756bc9b74ef357c088b3044527c41e6834ba1a2
-R 2a362f0638262e15107e468de4d77838
-U danielk1977
-Z 171613e0cdad61754450cbee9fe33dc0
+P 260711a14d5ab2d7c9888c7c46c33a28a3da0415
+R e7cd2dbd87cc55ed9709f416c29bb4b2
+U drh
+Z b3fd55271c42d6d384286f4a414e866e
index 01d288a62515e0a9de812b02134c1006b7f95ab7..d9c0d03936718da833e15d6b75dc8b1d4de24e56 100644 (file)
@@ -1 +1 @@
-260711a14d5ab2d7c9888c7c46c33a28a3da0415
\ No newline at end of file
+3e51696cb878063e4ebfdcc2a61ba94c9bebdfe3
\ No newline at end of file
index 7c509fff49dede3cc550d2e387735bb3ca0d5252..5d9608776169cf963be936a9b00bce7ffbbc5f2d 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains the C functions that implement a memory
 ** allocation subsystem for use by SQLite.  
 **
-** $Id: mem2.c,v 1.14 2007/10/03 08:46:45 danielk1977 Exp $
+** $Id: mem2.c,v 1.15 2007/10/15 19:34:32 drh Exp $
 */
 
 /*
@@ -84,6 +84,11 @@ struct MemBlockHdr {
 #define FOREGUARD 0x80F5E153
 #define REARGUARD 0xE4676B53
 
+/*
+** Number of malloc size increments to track.
+*/
+#define NCSIZE  500
+
 /*
 ** All of the static variables used by this module are collected
 ** into a single structure named "mem".  This is to keep the
@@ -148,8 +153,15 @@ static struct {
   ** sqlite3MallocAllow() decrements it.
   */
   int disallow; /* Do not allow memory allocation */
-  
-  
+
+  /*
+  ** Gather statistics on the sizes of memory allocations.
+  ** sizeCnt[i] is the number of allocation attempts of i*4
+  ** bytes.  i==NCSIZE is the number of allocation attempts for
+  ** sizes more than NCSIZE*4 bytes.
+  */
+  int sizeCnt[NCSIZE];
+
 } mem;
 
 
@@ -272,6 +284,11 @@ void *sqlite3_malloc(int nByte){
       sqlite3MemsysAlarm(nByte);
     }
     nByte = (nByte+3)&~3;
+    if( nByte/8>NCSIZE-1 ){
+      mem.sizeCnt[NCSIZE-1]++;
+    }else{
+      mem.sizeCnt[nByte/8]++;
+    }
     totalSize = nByte + sizeof(*pHdr) + sizeof(int) +
                  mem.nBacktrace*sizeof(void*) + mem.nTitle;
     if( mem.iFail>0 ){
@@ -440,6 +457,7 @@ void sqlite3_memdebug_dump(const char *zFilename){
   FILE *out;
   struct MemBlockHdr *pHdr;
   void **pBt;
+  int i;
   out = fopen(zFilename, "w");
   if( out==0 ){
     fprintf(stderr, "** Unable to output memory debug output log: %s **\n",
@@ -459,6 +477,15 @@ void sqlite3_memdebug_dump(const char *zFilename){
       fprintf(out, "\n");
     }
   }
+  fprintf(out, "COUNTS:\n");
+  for(i=0; i<NCSIZE-1; i++){
+    if( mem.sizeCnt[i] ){
+      fprintf(out, "   %3d: %d\n", i*8+8, mem.sizeCnt[i]);
+    }
+  }
+  if( mem.sizeCnt[NCSIZE-1] ){
+    fprintf(out, "  >%3d: %d\n", NCSIZE*8, mem.sizeCnt[NCSIZE-1]);
+  }
   fclose(out);
 }
 
index a1ca65c480def1d7a69910f877d94deb9155b5de..2b24f3b6e90abbfcfff5b9772f0040fa7b428672 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements some common TCL routines used for regression
 # testing the SQLite library
 #
-# $Id: tester.tcl,v 1.91 2007/09/01 09:02:54 danielk1977 Exp $
+# $Id: tester.tcl,v 1.92 2007/10/15 19:34:32 drh Exp $
 
 
 set tcl_precision 15
@@ -203,6 +203,9 @@ proc finalize_testing {} {
     }
   } else {
     puts "All memory allocations freed - no leaks"
+    ifcapable memdebug {
+      sqlite3_memdebug_dump ./memusage.txt
+    }
   }
   puts "Maximum memory usage: [sqlite3_memory_highwater] bytes"
   foreach f [glob -nocomplain test.db-*-journal] {