------------------------------------------------------------ revno: 13239 revision-id: squid3@treenet.co.nz-20140120005004-cog02zcumrg0cf3y parent: squid3@treenet.co.nz-20140119224322-68dk59jdoi0esk5v committer: Amos Jeffries branch nick: trunk timestamp: Mon 2014-01-20 13:50:04 +1300 message: Cleanup refreshCountsStats() cache manager code * Replace a #define macro with local static function. * Replace pointer parameter with reference * suppress display of histograms where there are no records and so no meaningful content to be displayed. ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20140120005004-cog02zcumrg0cf3y # target_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # testament_sha1: a0ea1b128033331e92fab0acb30f8be8a8dbdf0e # timestamp: 2014-01-20 00:53:54 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # base_revision_id: squid3@treenet.co.nz-20140119224322-\ # 68dk59jdoi0esk5v # # Begin patch === modified file 'src/refresh.cc' --- src/refresh.cc 2014-01-19 22:43:22 +0000 +++ src/refresh.cc 2014-01-20 00:50:04 +0000 @@ -559,57 +559,40 @@ return REFRESH_DEFAULT_MAX; } +static int +refreshCountsStatsEntry(StoreEntry * sentry, struct RefreshCounts &rc, int code, const char *desc) +{ + storeAppendPrintf(sentry, "%6d\t%6.2f\t%s\n", rc.status[code], xpercent(rc.status[code], rc.total), desc); + return rc.status[code]; +} + static void - -refreshCountsStats(StoreEntry * sentry, struct RefreshCounts *rc) +refreshCountsStats(StoreEntry * sentry, struct RefreshCounts &rc) { + if (!rc.total) + return; + + storeAppendPrintf(sentry, "\n\n%s histogram:\n", rc.proto); + storeAppendPrintf(sentry, "Count\t%%Total\tCategory\n"); + int sum = 0; - int tot = rc->total; - - storeAppendPrintf(sentry, "\n\n%s histogram:\n", rc->proto); - storeAppendPrintf(sentry, "Count\t%%Total\tCategory\n"); - -#define refreshCountsStatsEntry(code,desc) { \ - storeAppendPrintf(sentry, "%6d\t%6.2f\t%s\n", \ - rc->status[code], xpercent(rc->status[code], tot), desc); \ - sum += rc->status[code]; \ -} - - refreshCountsStatsEntry(FRESH_REQUEST_MAX_STALE_ALL, - "Fresh: request max-stale wildcard"); - refreshCountsStatsEntry(FRESH_REQUEST_MAX_STALE_VALUE, - "Fresh: request max-stale value"); - refreshCountsStatsEntry(FRESH_EXPIRES, - "Fresh: expires time not reached"); - refreshCountsStatsEntry(FRESH_LMFACTOR_RULE, - "Fresh: refresh_pattern last-mod factor percentage"); - refreshCountsStatsEntry(FRESH_MIN_RULE, - "Fresh: refresh_pattern min value"); - refreshCountsStatsEntry(FRESH_OVERRIDE_EXPIRES, - "Fresh: refresh_pattern override expires"); - refreshCountsStatsEntry(FRESH_OVERRIDE_LASTMOD, - "Fresh: refresh_pattern override lastmod"); - refreshCountsStatsEntry(STALE_MUST_REVALIDATE, - "Stale: response has must-revalidate"); - refreshCountsStatsEntry(STALE_RELOAD_INTO_IMS, - "Stale: changed reload into IMS"); - refreshCountsStatsEntry(STALE_FORCED_RELOAD, - "Stale: request has no-cache directive"); - refreshCountsStatsEntry(STALE_EXCEEDS_REQUEST_MAX_AGE_VALUE, - "Stale: age exceeds request max-age value"); - refreshCountsStatsEntry(STALE_EXPIRES, - "Stale: expires time reached"); - refreshCountsStatsEntry(STALE_MAX_RULE, - "Stale: refresh_pattern max age rule"); - refreshCountsStatsEntry(STALE_LMFACTOR_RULE, - "Stale: refresh_pattern last-mod factor percentage"); - refreshCountsStatsEntry(STALE_DEFAULT, - "Stale: by default"); - - tot = sum; /* paranoid: "total" line shows 100% if we forgot nothing */ - storeAppendPrintf(sentry, "%6d\t%6.2f\tTOTAL\n", - rc->total, xpercent(rc->total, tot)); - \ + sum += refreshCountsStatsEntry(sentry, rc, FRESH_REQUEST_MAX_STALE_ALL, "Fresh: request max-stale wildcard"); + sum += refreshCountsStatsEntry(sentry, rc, FRESH_REQUEST_MAX_STALE_VALUE, "Fresh: request max-stale value"); + sum += refreshCountsStatsEntry(sentry, rc, FRESH_EXPIRES, "Fresh: expires time not reached"); + sum += refreshCountsStatsEntry(sentry, rc, FRESH_LMFACTOR_RULE, "Fresh: refresh_pattern last-mod factor percentage"); + sum += refreshCountsStatsEntry(sentry, rc, FRESH_MIN_RULE, "Fresh: refresh_pattern min value"); + sum += refreshCountsStatsEntry(sentry, rc, FRESH_OVERRIDE_EXPIRES, "Fresh: refresh_pattern override expires"); + sum += refreshCountsStatsEntry(sentry, rc, FRESH_OVERRIDE_LASTMOD, "Fresh: refresh_pattern override lastmod"); + sum += refreshCountsStatsEntry(sentry, rc, STALE_MUST_REVALIDATE, "Stale: response has must-revalidate"); + sum += refreshCountsStatsEntry(sentry, rc, STALE_RELOAD_INTO_IMS, "Stale: changed reload into IMS"); + sum += refreshCountsStatsEntry(sentry, rc, STALE_FORCED_RELOAD, "Stale: request has no-cache directive"); + sum += refreshCountsStatsEntry(sentry, rc, STALE_EXCEEDS_REQUEST_MAX_AGE_VALUE, "Stale: age exceeds request max-age value"); + sum += refreshCountsStatsEntry(sentry, rc, STALE_EXPIRES, "Stale: expires time reached"); + sum += refreshCountsStatsEntry(sentry, rc, STALE_MAX_RULE, "Stale: refresh_pattern max age rule"); + sum += refreshCountsStatsEntry(sentry, rc, STALE_LMFACTOR_RULE, "Stale: refresh_pattern last-mod factor percentage"); + sum += refreshCountsStatsEntry(sentry, rc, STALE_DEFAULT, "Stale: by default"); + + storeAppendPrintf(sentry, "%6d\t%6.2f\tTOTAL\n", rc.total, xpercent(rc.total, sum)); storeAppendPrintf(sentry, "\n"); } @@ -639,7 +622,7 @@ storeAppendPrintf(sentry, "\n\nRefreshCheck histograms for various protocols\n"); for (i = 0; i < rcCount; ++i) - refreshCountsStats(sentry, &refreshCounts[i]); + refreshCountsStats(sentry, refreshCounts[i]); } static void