--------------------- PatchSet 5147 Date: 2007/08/04 11:14:42 Author: amosjeffries Branch: bug2000 Tag: (none) Log: Remove StoreEntryStream. Many changes required. Members: src/Makefile.am:1.122->1.122.10.1 src/Mem.h:1.5->1.5.28.1 src/StoreEntryStream.h:1.2->1.2.36.1 src/mem.cc:1.38->1.38.12.1 src/tests/testStoreEntryStream.cc:1.5->1.5.10.1 src/tests/testStoreEntryStream.h:1.2->1.2.12.1 test-suite/hash.h:1.1->1.1.64.1 Index: squid3/src/Makefile.am =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Makefile.am,v retrieving revision 1.122 retrieving revision 1.122.10.1 diff -u -r1.122 -r1.122.10.1 --- squid3/src/Makefile.am 19 Jun 2007 22:51:04 -0000 1.122 +++ squid3/src/Makefile.am 4 Aug 2007 11:14:42 -0000 1.122.10.1 @@ -1,7 +1,7 @@ # # Makefile for the Squid Object Cache server # -# $Id: Makefile.am,v 1.122 2007/06/19 22:51:04 squidadm Exp $ +# $Id: Makefile.am,v 1.122.10.1 2007/08/04 11:14:42 amosjeffries Exp $ # # Uncomment and customize the following to suit your needs: # @@ -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 =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Mem.h,v retrieving revision 1.5 retrieving revision 1.5.28.1 diff -u -r1.5 -r1.5.28.1 --- squid3/src/Mem.h 29 May 2006 00:50:18 -0000 1.5 +++ squid3/src/Mem.h 4 Aug 2007 11:14:42 -0000 1.5.28.1 @@ -1,6 +1,6 @@ /* - * $Id: Mem.h,v 1.5 2006/05/29 00:50:18 squidadm Exp $ + * $Id: Mem.h,v 1.5.28.1 2007/08/04 11:14:42 amosjeffries Exp $ * * DEBUG: section 13 High Level Memory Pool Management * AUTHOR: Harvest Derived @@ -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 =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/StoreEntryStream.h,v retrieving revision 1.2 retrieving revision 1.2.36.1 diff -u -r1.2 -r1.2.36.1 --- squid3/src/StoreEntryStream.h 6 May 2006 01:50:22 -0000 1.2 +++ squid3/src/StoreEntryStream.h 4 Aug 2007 11:14:42 -0000 1.2.36.1 @@ -1,6 +1,6 @@ /* - * $Id: StoreEntryStream.h,v 1.2 2006/05/06 01:50:22 squidadm Exp $ + * $Id: StoreEntryStream.h,v 1.2.36.1 2007/08/04 11:14:42 amosjeffries Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -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 /* AYJ : testign without StoreEntryStreams' */ + #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 /*AYJ experiment with not using StoreEntryStream */ #endif /* SQUID_STORE_ENTRY_STREAM_H */ Index: squid3/src/mem.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/mem.cc,v retrieving revision 1.38 retrieving revision 1.38.12.1 diff -u -r1.38 -r1.38.12.1 --- squid3/src/mem.cc 22 May 2007 16:52:04 -0000 1.38 +++ squid3/src/mem.cc 4 Aug 2007 11:14:42 -0000 1.38.12.1 @@ -1,6 +1,6 @@ /* - * $Id: mem.cc,v 1.38 2007/05/22 16:52:04 squidadm Exp $ + * $Id: mem.cc,v 1.38.12.1 2007/08/04 11:14:42 amosjeffries Exp $ * * DEBUG: section 13 High Level Memory Pool Management * AUTHOR: Harvest Derived @@ -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 =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/tests/testStoreEntryStream.cc,v retrieving revision 1.5 retrieving revision 1.5.10.1 diff -u -r1.5 -r1.5.10.1 --- squid3/src/tests/testStoreEntryStream.cc 29 May 2007 13:51:53 -0000 1.5 +++ squid3/src/tests/testStoreEntryStream.cc 4 Aug 2007 11:14:43 -0000 1.5.10.1 @@ -1,3 +1,6 @@ + +#if 0 /* AYJ : killing this class/experiment entirely. */ + #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 /*AYJ*/ Index: squid3/src/tests/testStoreEntryStream.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/tests/testStoreEntryStream.h,v retrieving revision 1.2 retrieving revision 1.2.12.1 diff -u -r1.2 -r1.2.12.1 --- squid3/src/tests/testStoreEntryStream.h 23 May 2007 21:51:22 -0000 1.2 +++ squid3/src/tests/testStoreEntryStream.h 4 Aug 2007 11:14:43 -0000 1.2.12.1 @@ -2,6 +2,8 @@ #ifndef SQUID_SRC_TEST_STORE_ENTRY_STREAM_H #define SQUID_SRC_TEST_STORE_ENTRY_STREAM_H +#if 0 /*AYJ : killing this class entirely */ + #include /* @@ -23,3 +25,4 @@ #endif +#endif /*AYJ*/ Index: squid3/test-suite/hash.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/test-suite/hash.h,v retrieving revision 1.1 retrieving revision 1.1.64.1 diff -u -r1.1 -r1.1.64.1 --- squid3/test-suite/hash.h 14 Oct 2002 00:18:25 -0000 1.1 +++ squid3/test-suite/hash.h 4 Aug 2007 11:14:43 -0000 1.1.64.1 @@ -21,8 +21,11 @@ typedef struct _hash_table hash_table; extern int hash_links_allocated; +#if 0 + /* AYJ: g++ 4.1.3+ says: previously declared n globals.h */ extern int store_hash_buckets; /* 0 */ extern hash_table *store_table; /* NULL */ +#endif extern hash_table *hash_create(HASHCMP *, int, HASHHASH *); extern void hash_insert(hash_table *, const char *, void *); extern int hash_delete(hash_table *, const char *);