Patch file generated Sun Aug 5 01:03:02 NZST 2007 from CVS branch bug2000 CVS base branch HEAD CVS repository: amosjeffries@cvs.devel.squid-cache.org:/cvsroot/squid CVS module: squid3 cvs -q rdiff -u -kk -r Z-bug2000_merge_HEAD -r bug2000 squid3 Index: squid3/src/Makefile.am diff -u squid3/src/Makefile.am:1.122 squid3/src/Makefile.am:1.122.10.1 --- squid3/src/Makefile.am:1.122 Tue Jun 19 15:51:04 2007 +++ squid3/src/Makefile.am Sat Aug 4 04:14:42 2007 @@ -2121,7 +2121,16 @@ # string needs mem.cc. tests_testString_SOURCES= \ + Mem.h \ mem.cc \ + mem_node.h \ + mem_node.cc \ + stmem.cc \ + MemObject.h \ + tests/stub_MemObject.cc \ + tests/stub_comm.cc \ + tests/stub_store.cc \ + cbdata.cc \ String.cc \ tests/testMain.cc \ tests/testString.cc \ Index: squid3/src/Mem.h diff -u squid3/src/Mem.h:1.5 squid3/src/Mem.h:1.5.28.1 --- squid3/src/Mem.h:1.5 Sun May 28 17:50:18 2006 +++ squid3/src/Mem.h Sat Aug 4 04:14:42 2007 @@ -40,7 +40,7 @@ class CacheManager; -#include +class StoreEntry; class Mem { @@ -50,8 +50,8 @@ static void RegisterWithCacheManager(CacheManager & manager); static void Stats(StoreEntry *); static void CleanIdlePools(void *unused); - static void Report(std::ostream &); - static void PoolReport(const MemPoolStats * mp_st, const MemPoolMeter * AllMeter, std::ostream &); + static void Report(StoreEntry *sentry); + static void PoolReport(const MemPoolStats * mp_st, const MemPoolMeter * AllMeter, StoreEntry *); }; #endif /* SQUID_MEM */ Index: squid3/src/StoreEntryStream.h diff -u squid3/src/StoreEntryStream.h:1.2 squid3/src/StoreEntryStream.h:1.2.36.2 --- squid3/src/StoreEntryStream.h:1.2 Fri May 5 18:50:22 2006 +++ squid3/src/StoreEntryStream.h Sat Aug 4 06:02:42 2007 @@ -30,15 +30,16 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. * */ - #ifndef SQUID_STORE_ENTRY_STREAM_H #define SQUID_STORE_ENTRY_STREAM_H +#if 0 /* obsoleting StoreEntryStream */ + #include "Store.h" #include -/* +/** * This class provides a streambuf interface for writing * to StoreEntries. Typical use is via a StoreEntryStream * rather than direct manipulation @@ -51,9 +52,7 @@ StoreEntryStreamBuf(StoreEntry *anEntry) : anEntry(anEntry) { - anEntry->lock() - - ; + anEntry->lock(); anEntry->buffer(); } @@ -63,7 +62,8 @@ } protected: - /* flush the current buffer and the character that is overflowing + /** + * flush the current buffer and the character that is overflowing * to the store entry. */ virtual char overflow(char aChar = traits_type::eof()) @@ -127,4 +127,5 @@ StoreEntryStreamBuf * rdbuf() const { return const_cast(&_buffer); } }; +#endif #endif /* SQUID_STORE_ENTRY_STREAM_H */ Index: squid3/src/mem.cc diff -u squid3/src/mem.cc:1.38 squid3/src/mem.cc:1.38.12.1 --- squid3/src/mem.cc:1.38 Tue May 22 09:52:04 2007 +++ squid3/src/mem.cc Sat Aug 4 04:14:42 2007 @@ -34,23 +34,17 @@ */ #include "squid.h" - -#include -#include - #include "event.h" #include "CacheManager.h" #include "Mem.h" #include "memMeter.h" #include "Store.h" -#include "StoreEntryStream.h" #include "MemBuf.h" #include "SquidTime.h" /* module globals */ /* local prototypes */ -static void memStringStats(std::ostream &); /* module locals */ static MemAllocator *MemPools[MEM_MAX]; @@ -94,66 +88,58 @@ /* local routines */ static void -memStringStats(std::ostream &stream) +memStringStats(StoreEntry *sentry) { int i; int pooled_count = 0; size_t pooled_volume = 0; /* heading */ - stream << "String Pool\t Impact\t\t\n \t (%strings)\t (%volume)\n"; + storeAppendPrintf(sentry,"String Pool\t Impact\t\t\n \t (%%strings)\t (%%volume)\n"); /* table body */ for (i = 0; i < mem_str_pool_count; i++) { const MemAllocator *pool = StrPools[i].pool; const int plevel = pool->getMeter().inuse.level; - stream << std::setw(20) << std::left << pool->objectType(); - stream << std::right << "\t " << xpercentInt(plevel, StrCountMeter.level); - stream << "\t " << xpercentInt(plevel * pool->objectSize(), StrVolumeMeter.level) << "\n"; + storeAppendPrintf(sentry," %20s\t %10.0d\t %10.0d\n", + pool->objectType() , + xpercentInt(plevel, StrCountMeter.level) , + xpercentInt(plevel * pool->objectSize(), StrVolumeMeter.level) ); pooled_count += plevel; pooled_volume += plevel * pool->objectSize(); } /* malloc strings */ - stream << std::setw(20) << std::left << "Other Strings"; - - stream << std::right << "\t "; - - stream << xpercentInt(StrCountMeter.level - pooled_count, StrCountMeter.level) << "\t "; - - stream << xpercentInt(StrVolumeMeter.level - pooled_volume, StrVolumeMeter.level) << "\n\n"; -} - -static void -memBufStats(std::ostream & stream) -{ - stream << "Large buffers: " << - HugeBufCountMeter.level << " (" << - HugeBufVolumeMeter.level / 1024 << " KB)\n"; + storeAppendPrintf(sentry," %20s\t %10.0d\t %10.0d\n\n", + "Other Strings", + xpercentInt(StrCountMeter.level - pooled_count, StrCountMeter.level) , + xpercentInt(StrVolumeMeter.level - pooled_volume, StrVolumeMeter.level) ); } void Mem::Stats(StoreEntry * sentry) { - StoreEntryStream stream(sentry); - Report(stream); - memStringStats(stream); - memBufStats(stream); + Report(sentry); + memStringStats(sentry); + + storeAppendPrintf(sentry,"Large buffers: %d (%d KB)\n", + HugeBufCountMeter.level, + HugeBufVolumeMeter.level / 1024); + #if WITH_VALGRIND if (RUNNING_ON_VALGRIND) { - long int leaked = 0, dubious = 0, reachable = 0, suppressed = 0; - stream << "Valgrind Report:\n"; - stream << "Type\tAmount\n"; - debugs(13, 1, "Asking valgrind for memleaks"); + long int leaked = 0, dubious = 0, reachable = 0, suppressed = 0; + storeAppendPrintf(sentry,"Valgrind Report:\nType\tAmount\n"; + debugs(13, 1, "Asking valgrind for memleaks"); VALGRIND_DO_LEAK_CHECK; - debugs(13, 1, "Getting valgrind statistics"); + debugs(13, 1, "Getting valgrind statistics"); + VALGRIND_COUNT_LEAKS(leaked, dubious, reachable, suppressed); - stream << "Leaked\t" << leaked << "\n"; - stream << "Dubious\t" << dubious << "\n"; - stream << "Reachable\t" << reachable << "\n"; - stream << "Suppressed\t" << suppressed << "\n"; + storeAppendPrintf(sentry,"Leaked\t%d\n", leaked); + storeAppendPrintf(sentry,"Dubious\t%d\n", dubious); + storeAppendPrintf(sentry,"Reachable\t%d\n", reachable); + storeAppendPrintf(sentry,"Suppressed\t%d\n", suppressed); } #endif - stream.flush(); } /* @@ -556,19 +542,19 @@ /* MemPoolMeter */ void -Mem::PoolReport(const MemPoolStats * mp_st, const MemPoolMeter * AllMeter, std::ostream &stream) +Mem::PoolReport(const MemPoolStats * mp_st, const MemPoolMeter * AllMeter, StoreEntry *sentry) { int excess = 0; int needed = 0; MemPoolMeter *pm = mp_st->meter; const char *delim = "\t "; - stream << std::setw(20) << std::left << mp_st->label << delim; - stream << std::setw(4) << std::right << mp_st->obj_size << delim; + storeAppendPrintf(sentry,"%20.20s%s", mp_st->label, delim); + storeAppendPrintf(sentry,"%4d%s", mp_st->obj_size, delim); /* Chunks */ - stream << std::setw(4) << toKB(mp_st->obj_size * mp_st->chunk_capacity) << delim; - stream << std::setw(4) << mp_st->chunk_capacity << delim; + storeAppendPrintf(sentry,"%4d%s", toKB(mp_st->obj_size * mp_st->chunk_capacity), delim); + storeAppendPrintf(sentry,"%4d%s", mp_st->chunk_capacity, delim); if (mp_st->chunk_capacity) { needed = mp_st->items_inuse / mp_st->chunk_capacity; @@ -579,11 +565,11 @@ excess = mp_st->chunks_inuse - needed; } - stream << std::setw(4) << mp_st->chunks_alloc << delim; - stream << std::setw(4) << mp_st->chunks_inuse << delim; - stream << std::setw(4) << mp_st->chunks_free << delim; - stream << std::setw(4) << mp_st->chunks_partial << delim; - stream << std::setprecision(3) << xpercent(excess, needed) << delim; + storeAppendPrintf(sentry,"%4d%s", mp_st->chunks_alloc, delim); + storeAppendPrintf(sentry,"%4d%s", mp_st->chunks_inuse, delim); + storeAppendPrintf(sentry,"%4d%s", mp_st->chunks_free, delim); + storeAppendPrintf(sentry,"%4d%s", mp_st->chunks_partial, delim); + storeAppendPrintf(sentry,"%0.3f%s", xpercent(excess, needed), delim); /* * Fragmentation calculation: * needed = inuse.level / chunk_capacity @@ -593,26 +579,26 @@ * Fragm = (alloced - (inuse / obj_ch) ) / alloced */ /* allocated */ - stream << mp_st->items_alloc << delim; - stream << toKB(mp_st->obj_size * pm->alloc.level) << delim; - stream << toKB(mp_st->obj_size * pm->alloc.hwater_level) << delim; - stream << std::setprecision(2) << ((squid_curtime - pm->alloc.hwater_stamp) / 3600.) << delim; - stream << std::setprecision(3) << xpercent(mp_st->obj_size * pm->alloc.level, AllMeter->alloc.level) << delim; + storeAppendPrintf(sentry,"%d%s", mp_st->items_alloc, delim); + storeAppendPrintf(sentry,"%d%s", toKB(mp_st->obj_size * pm->alloc.level), delim); + storeAppendPrintf(sentry,"%d%s", toKB(mp_st->obj_size * pm->alloc.hwater_level), delim); + storeAppendPrintf(sentry,"%3f%s", ((squid_curtime - pm->alloc.hwater_stamp) / 3600.), delim); + storeAppendPrintf(sentry,"%3f%s", xpercent(mp_st->obj_size * pm->alloc.level, AllMeter->alloc.level), delim); /* in use */ - stream << mp_st->items_inuse << delim; - stream << toKB(mp_st->obj_size * pm->inuse.level) << delim; - stream << toKB(mp_st->obj_size * pm->inuse.hwater_level) << delim; - stream << std::setprecision(2) << ((squid_curtime - pm->inuse.hwater_stamp) / 3600.) << delim; - stream << std::setprecision(3) << xpercent(pm->inuse.level, pm->alloc.level) << delim; + storeAppendPrintf(sentry,"%d%s", mp_st->items_inuse, delim); + storeAppendPrintf(sentry,"%d%s", toKB(mp_st->obj_size * pm->inuse.level), delim); + storeAppendPrintf(sentry,"%d%s", toKB(mp_st->obj_size * pm->inuse.hwater_level), delim); + storeAppendPrintf(sentry,"%2f%s", ((squid_curtime - pm->inuse.hwater_stamp) / 3600.), delim); + storeAppendPrintf(sentry,"%3f%s", xpercent(pm->inuse.level, pm->alloc.level), delim); /* idle */ - stream << mp_st->items_idle << delim; - stream << toKB(mp_st->obj_size * pm->idle.level) << delim; - stream << toKB(mp_st->obj_size * pm->idle.hwater_level) << delim; + storeAppendPrintf(sentry,"%d%s", mp_st->items_idle, delim); + storeAppendPrintf(sentry,"%d%s", toKB(mp_st->obj_size * pm->idle.level), delim); + storeAppendPrintf(sentry,"%d%s", toKB(mp_st->obj_size * pm->idle.hwater_level), delim); /* saved */ - stream << (int)pm->gb_saved.count << delim; - stream << std::setprecision(3) << xpercent(pm->gb_saved.count, AllMeter->gb_saved.count) << delim; - stream << std::setprecision(3) << xpercent(pm->gb_saved.bytes, AllMeter->gb_saved.bytes) << delim; - stream << std::setprecision(3) << xdiv(pm->gb_saved.count - pm->gb_osaved.count, xm_deltat) << "\n"; + storeAppendPrintf(sentry,"%d%s", (int)pm->gb_saved.count, delim); + storeAppendPrintf(sentry,"%3f%s", xpercent(pm->gb_saved.count, AllMeter->gb_saved.count), delim); + storeAppendPrintf(sentry,"%3f%s", xpercent(pm->gb_saved.bytes, AllMeter->gb_saved.bytes), delim); + storeAppendPrintf(sentry,"%3f\n", xdiv(pm->gb_saved.count - pm->gb_osaved.count, xm_deltat) ); pm->gb_osaved.count = pm->gb_saved.count; } @@ -648,7 +634,7 @@ } void -Mem::Report(std::ostream &stream) +Mem::Report(StoreEntry *sentry) { static char buf[64]; static MemPoolStats mp_stats; @@ -658,25 +644,26 @@ MemAllocator *pool; /* caption */ - stream << "Current memory usage:\n"; + storeAppendPrintf(sentry,"Current memory usage:\n"); /* heading */ - stream << "Pool\t Obj Size\t" - "Chunks\t\t\t\t\t\t\t" - "Allocated\t\t\t\t\t" - "In Use\t\t\t\t\t" - "Idle\t\t\t" - "Allocations Saved\t\t\t" - "Hit Rate\t" - "\n" - " \t (bytes)\t" - "KB/ch\t obj/ch\t" - "(#)\t used\t free\t part\t %Frag\t " - "(#)\t (KB)\t high (KB)\t high (hrs)\t %Tot\t" - "(#)\t (KB)\t high (KB)\t high (hrs)\t %alloc\t" - "(#)\t (KB)\t high (KB)\t" - "(#)\t %cnt\t %vol\t" - "(#) / sec\t" - "\n"; + storeAppendPrintf(sentry, + "Pool\t Obj Size\t" + "Chunks\t\t\t\t\t\t\t" + "Allocated\t\t\t\t\t" + "In Use\t\t\t\t\t" + "Idle\t\t\t" + "Allocations Saved\t\t\t" + "Hit Rate\t" + "\n" + " \t (bytes)\t" + "KB/ch\t obj/ch\t" + "(#)\t used\t free\t part\t %%Frag\t " + "(#)\t (KB)\t high (KB)\t high (hrs)\t %%Tot\t" + "(#)\t (KB)\t high (KB)\t high (hrs)\t %%alloc\t" + "(#)\t (KB)\t high (KB)\t" + "(#)\t %%cnt\t %%vol\t" + "(#) / sec\t" + "\n"); xm_deltat = current_dtime - xm_time; xm_time = current_dtime; @@ -706,7 +693,7 @@ qsort(sortme, npools, sizeof(*sortme), MemPoolReportSorter); for (int i = 0; i< npools; i++) { - PoolReport(&sortme[i], mp_total.TheMeter, stream); + PoolReport(&sortme[i], mp_total.TheMeter, sentry); } xfree(sortme); @@ -726,17 +713,19 @@ mp_stats.items_idle = mp_total.tot_items_idle; mp_stats.overhead = mp_total.tot_overhead; - PoolReport(&mp_stats, mp_total.TheMeter, stream); + PoolReport(&mp_stats, mp_total.TheMeter, sentry); /* Cumulative */ - stream << "Cumulative allocated volume: "<< double_to_str(buf, 64, mp_total.TheMeter->gb_saved.bytes) << "\n"; + storeAppendPrintf(sentry,"Cumulative allocated volume: %s\n", + double_to_str(buf, 64, mp_total.TheMeter->gb_saved.bytes) ); /* overhead */ - stream << "Current overhead: " << mp_total.tot_overhead << " bytes (" << - std::setprecision(3) << xpercent(mp_total.tot_overhead, mp_total.TheMeter->inuse.level) << "%)\n"; + storeAppendPrintf(sentry,"Current overhead: %d bytes (%0.3f%%)\n", + mp_total.tot_overhead, + xpercent(mp_total.tot_overhead, mp_total.TheMeter->inuse.level) ); /* limits */ - stream << "Idle pool limit: " << std::setprecision(2) << toMB(mp_total.mem_idle_limit) << " MB\n"; + storeAppendPrintf(sentry,"Idle pool limit: %0.2f MB\n", toMB(mp_total.mem_idle_limit) ); /* limits */ - stream << "Total Pools created: " << mp_total.tot_pools_alloc << "\n"; - stream << "Pools ever used: " << mp_total.tot_pools_alloc - not_used << " (shown above)\n"; - stream << "Currently in use: " << mp_total.tot_pools_inuse << "\n"; + storeAppendPrintf(sentry,"Total Pools created: %d", mp_total.tot_pools_alloc ); + storeAppendPrintf(sentry,"Pools ever used: %d (shown above)\n", mp_total.tot_pools_alloc - not_used ); + storeAppendPrintf(sentry,"Currently in use: %d", mp_total.tot_pools_inuse ); } Index: squid3/src/tests/testStoreEntryStream.cc diff -u squid3/src/tests/testStoreEntryStream.cc:1.5 squid3/src/tests/testStoreEntryStream.cc:1.5.10.2 --- squid3/src/tests/testStoreEntryStream.cc:1.5 Tue May 29 06:51:53 2007 +++ squid3/src/tests/testStoreEntryStream.cc Sat Aug 4 06:02:43 2007 @@ -1,3 +1,6 @@ + +#if 0 /* obsolete StoreEntryStream */ + #include "squid.h" #include "Mem.h" #include "testStore.h" @@ -31,16 +34,18 @@ StoreEntryStream stream(anEntry); CPPUNIT_ASSERT_EQUAL(1, anEntry->_buffer_calls); CPPUNIT_ASSERT_EQUAL(0, anEntry->_flush_calls); - stream << "some text" << std::setw(4) << "!"; + stream << "some text" << std::setw(4) << 2 << std::setw(2) << "!"; CPPUNIT_ASSERT_EQUAL(1, anEntry->_buffer_calls); CPPUNIT_ASSERT_EQUAL(0, anEntry->_flush_calls); stream.flush(); CPPUNIT_ASSERT_EQUAL(1, anEntry->_buffer_calls); CPPUNIT_ASSERT_EQUAL(1, anEntry->_flush_calls); - CPPUNIT_ASSERT_EQUAL(String("some text !"), anEntry->_appended_text); + CPPUNIT_ASSERT_EQUAL(String("some text 2 !"), anEntry->_appended_text); } delete anEntry; Store::Root(NULL); } + +#endif Index: squid3/src/tests/testStoreEntryStream.h diff -u squid3/src/tests/testStoreEntryStream.h:1.2 squid3/src/tests/testStoreEntryStream.h:1.2.12.2 --- squid3/src/tests/testStoreEntryStream.h:1.2 Wed May 23 14:51:22 2007 +++ squid3/src/tests/testStoreEntryStream.h Sat Aug 4 06:02:43 2007 @@ -2,6 +2,8 @@ #ifndef SQUID_SRC_TEST_STORE_ENTRY_STREAM_H #define SQUID_SRC_TEST_STORE_ENTRY_STREAM_H +#if 0 /* obsolete StoreEntryStream */ + #include /* @@ -23,3 +25,4 @@ #endif +#endif